import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* Sample class to produce a false positive SonarQube issue when a class is annotated with {@code @NonNullByDefault}
* and a method of that class then marked as {@code @Nullable} and actually returns {@code null}.
*/
@NonNullByDefault
class SonarQubeNullableMethodFalsePositiveRepro {
/**
* This method produces a false positive SonarQube issue for <em>squid:S2637</em>
* (<q>"@NonNull" values should not be set to null (squid:S2637)</q>).
*
* @param value Some value
* @return Some result
*/
@Nullable
String thisMethodProducesAFalsePositive(String value) {
if (value != null && !value.trim().isEmpty()) {
return value;
}
return null; // False positive: This method's return value is marked "org.eclipse.jdt.annotation.NonNullByDefault" but null is returned
}
}
Thank you for the detailed reproducer. I tried to reproduce with the latest SonarJava (SonarJava 5.9.1) and could not.
Could you please update to the latest sonar-java plugin (5.9.1) and tell us if the issue persists? You can do that from the SonarQube Marketplace - you need to have admin rights.