infer icon indicating copy to clipboard operation
infer copied to clipboard

[java] add tests documenting the dependencies analysis mode

Open jeremydubreil opened this issue 1 year ago • 7 comments

This pull request adds a test to document the --dependencies options triggering the analysis of the classes appearing in the Java classpath. This feature is especially useful when analysing JAR files packaging all the code of a Java application including the dependencies.

The examples added in the test are outlining how running the Pulse taint analysis with the dependencies mode enabled can eliminate cases of false negatives and cases of false positives.

All the tests are passing locally.

jeremydubreil avatar Sep 12 '22 07:09 jeremydubreil

@jvillard has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Sep 12 '22 16:09 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Sep 12 '22 17:09 facebook-github-bot

@jvillard has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Sep 13 '22 12:09 facebook-github-bot

The macos tests on GitHub are failing: https://github.com/facebook/infer/actions/runs/3039326327/jobs/4894127613

[*ERROR**][82386] ./lib/Framework.java:30: error: cannot find symbol
[*ERROR**][82386]             String content = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
[*ERROR**][82386]                                                    ^
[*ERROR**][82386]   symbol:   method readAllBytes()
[*ERROR**][82386]   location: variable inputStream of type FileInputStream

Maybe that method is not available in Java 8, can we just use another?

jvillard avatar Sep 13 '22 12:09 jvillard

Yes, the choice of the method is arbitrary so we can use another one that is available with Java 8. However, I wonder independently if we should make sure that we are using the same version of the Java SDK on Linux and on macOS. We can discuss this on https://github.com/facebook/infer/pull/1680.

jeremydubreil avatar Sep 13 '22 12:09 jeremydubreil

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Sep 16 '22 07:09 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Sep 21 '22 15:09 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Sep 23 '22 08:09 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Sep 29 '22 14:09 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Sep 29 '22 22:09 facebook-github-bot

@jvillard has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Oct 03 '22 10:10 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Oct 03 '22 15:10 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Oct 03 '22 15:10 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Oct 03 '22 15:10 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Oct 03 '22 16:10 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Oct 03 '22 22:10 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Oct 06 '22 13:10 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Oct 07 '22 19:10 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Oct 07 '22 19:10 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Oct 11 '22 07:10 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Oct 11 '22 13:10 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Oct 11 '22 14:10 facebook-github-bot

@jvillard has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Oct 12 '22 11:10 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Oct 12 '22 12:10 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Oct 12 '22 12:10 facebook-github-bot

@jeremydubreil has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Oct 12 '22 12:10 facebook-github-bot

@jvillard , this last version should be ready. I simplified the test code to avoid pulling in too many dependencies to run the analysis on. I was also trying to understand why the disable-issue-type was not working (it was because of the --debug-exceptions). Should be good now.

jeremydubreil avatar Oct 12 '22 12:10 jeremydubreil

@jvillard has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Oct 13 '22 09:10 facebook-github-bot

I get more errors in the test, and they are reported inside infer-out/ for some reason!

diff --git a/mnt/btrfs/trunk-git-infer-38-1665654773/infer/tests/codetoanalyze/java/dependencies/issues.exp b/mnt/btrfs/trunk-git-infer-38-1665654773/infer/tests/codetoanalyze/java/dependencies/issues.exp.test
index 65c0e8821f..485fb40455 100644
--- a/mnt/btrfs/trunk-git-infer-38-1665654773/infer/tests/codetoanalyze/java/dependencies/issues.exp
+++ b/mnt/btrfs/trunk-git-infer-38-1665654773/infer/tests/codetoanalyze/java/dependencies/issues.exp.test
@@ -1 +1,4 @@
{+codetoanalyze/java/dependencies/infer-out/classnames/java/util/stream/StreamOpFlag.class, java.util.stream.StreamOpFlag.isStreamFlag():boolean, 0, NULLPTR_DEREFERENCE, no_bucket, ERROR, [in call to `Map.get()` (modelled),is assigned to the null pointer,assigned,in call to `cast` (modelled),invalid access occurs here]+}
{+codetoanalyze/java/dependencies/infer-out/classnames/java/util/stream/StreamOpFlag.class, java.util.stream.StreamOpFlag.canSet(java.util.stream.StreamOpFlag$Type):boolean, 0, NULLPTR_DEREFERENCE, no_bucket, ERROR, [in call to `Map.get()` (modelled),is assigned to the null pointer,assigned,in call to `cast` (modelled),invalid access occurs here]+}
{+codetoanalyze/java/dependencies/infer-out/classnames/java/util/stream/StreamOpFlag.class, java.util.stream.StreamOpFlag.createMask(java.util.stream.StreamOpFlag$Type):int, 2, NULLPTR_DEREFERENCE, no_bucket, ERROR, [in call to `Map.get()` (modelled),is assigned to the null pointer,assigned,in call to `cast` (modelled),invalid access occurs here]+}
codetoanalyze/java/dependencies/my/Application.java, my.Application.indirectNPE():java.lang.String, 1, NULLPTR_DEREFERENCE, no_bucket, ERROR, [in call to `Object Framework.returnNull()`,is assigned to the null pointer,returned,return from call to `Object Framework.returnNull()`,assigned,invalid access occurs here]

Test output (codetoanalyze/java/dependencies/issues.exp.test) differs from expected test output codetoanalyze/java/dependencies/issues.exp
Run the following command to replace the expected test output with the new output:

  make -C infer/tests/codetoanalyze/java/dependencies replace

jvillard avatar Oct 13 '22 12:10 jvillard

@jvillard what version of Java is used to run the tests on the internal CI?

jeremydubreil avatar Oct 13 '22 13:10 jeremydubreil