Hi there,
I have setup Sonarqube (6.7.1) for a larger multi-project Gradle project. All projects use Eclipse annotation-based null analysis and things work mostly fine in Eclipse.
When I run the Sonar analysis I get lots of false positives. Let me explain in more detail.
We are using a default of NonNull like this:
@NonNullByDefault
package sonar.nullanalysis.tests;
import org.eclipse.jdt.annotation.NonNullByDefault;
Now, when a method is allowed to return null that method is annotated with @Nullable. Sonar does not seem to pick up that the method should "overrule" the package default.
This leads to at least two false positives:
1) The method which returns null and is allowed to do so is marked with:
"@NonNull" values should not be set to null (squid:S2637) / This method's return value is marked "org.eclipse.jdt.annotation.NonNullByDefault" but null is returned.
This make me believe that the overruling does not work at all.
2) If the method is allowed to return null (as it is) the calling code should do a null check. Now, the sonar analyzer will mark that null check with this:
Conditionally executed blocks should be reachable (squid:S2583) / Change this condition so that it does not always evaluate to "false"
You will need to add the sonar connection information into a gradle.properties file to connect the project with some sonar server.
I'm looking forward to your assessment of these issues.
Regards, Thomas