SonarQube v10.8 (100206)
SonarQube Gradle 6.0.1.5171
The strangeness begins with "static" base class members should not be accessed via derived types java:S3252
being reported for code that looks like this:
@Data
@SuperBuilder
public class MySuperClass {
@Builder.Default
private Optional<String> foo = Optional.empty();
}
@Data
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
public class MySubClassOne extends MySuperClass {
@Builder.Default
private Optional<String> bar = Optional.empty();
}
@Data
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
public class MySubClassTwo extends MySuperClass {
@Builder.Default
private Optional<String> baz = Optional.empty();
}
MySubClassOne.builder().build(); <- issue here
MySubClassTwo.builder().baz("baz").build(); <- but not here
So far this seems like an ordinary false positive. But then I made a small change to one of the classes, so that it looks like this:
@Data
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
public class MySubClassOne extends MySuperClass {
@Builder.Default
@Nullable
private String bar = null;
public Optional<String> getBar() {
return Optional.ofNullable(bar);
}
}
This did not resolve the initial (false positive) issue, but it did cause 3 completely unrelated issues to be falsely marked as resolved (false negative).
In a file which uses a renamed getter in MySubClassOne (and no other changes), 3 issues marked as resolved:
// Annotate the parameter with @javax.annotation.Nullable in method 'itemCategory' declaration, or make sure that null can not be passed as argument.
// contextData.itemCategory is still annotated as @Nullable, and the field in the builder is still annotated @NonNull
.itemCategory(contextData.getItemCategory())
...
/// A "NullPointerException" could be thrown; "getLogo()" can return null.
// contextData.logo is still annotated as @Nullable
builder.logoUrl(contextData.getLogo().toString());
...
// Remove this expression which always evaluates to "true"
// The issue was not fixed, contextData.backgroundImage is still annotated @NonNull
if (contextData.getBackgroundImage() != null) {