Java Analyzer performance and reliability improvements

We’ve been a bit quiet about what’s going on with the Java analyzer so far. Don’t worry though, we’ve got some good news for all you Java developers!

Speed and reliability improvements

We have applied a number of memory and speed optimizations to reduce the chances of analysis timing out on Java repositories. There are more optimizations to come, so keep an eye out for more updates on this!

Arbitrary Java project support

Earlier, the Java analyzer only supported repositories that used Gradle and/or Maven as a build system. It was not able to analyze Eclipse or Idea projects, for example.

The Java analyzer now supports analysis of any repository that contains java files, regardless of the presence of a supported build system. While Gradle and Maven projects will still have first-class support, the Java analyzer is now able to analyze repositories that make use of other build systems (or even no build system; e.g. sample or scratch files can also be analyzed for issues).

This does come with some caveats:

  • Dependency metrics may not be available for unsupported repositories.
  • We may not be able to take advantage of the modular structure of such repositories, resulting in possibly slower analysis.

False-positive fixes

A number of false positives have been fixed, here’s a sample:

Unused private method - JAVA-W0324

This issue will no longer be reported wrongly for methods that are used by JUnit5 parameterized tests:

    private Stream<String> abc() { 
        return Stream.of(null, "", "  ");
    }

    @ParameterizedTest
    @MethodSource("abc")
    void def(String s) {
        // ...
    }

Here, the method abc used to be reported as unused, even when it was specified as a parameter source for the test method def . This is now fixed.

Thread with empty run method - JAVA-W0084

This issue will no longer be reported when a new anonymous thread object is created:

    new Thread() {
        @Override
        public void run() {
            // ...
        }
    }

Repeated expression - JAVA-E0034

This issue will no longer report string concatenations that may have repeated values.

String combined = oneString + oneString + " together";

Bad oddness check - JAVA-E0405

This issue will no longer be reported for patterns such as (a >> b) % 2 == 1, which are a legitimate way to check if a particular bit in a is set to 1.

String return value is ignored - JAVA-W0243

This issue will no longer be reported for methods of the String class which may be called within a conditional expression (a ? b : c):

int size = someString != null ? someString.length() : 0

Before, the call to String.length() was incorrectly flagged.

If you have any questions about the Java analyzer, you can add a comment here, reach us through our discord server or send us an email on our support mail id. Have a great day!