Problem: java:S2638 occurs without any known reason
package sampleS2638;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@NonNullByDefault
interface Foo {
interface Bar<T> {
@Nullable
T bar1();
T bar2();
}
<T> T doBar(Bar<T> bar);
}
package sampleS2638;
import org.eclipse.jdt.annotation.NonNull;
import java.util.Collection;
import java.util.Collections;
final class Sample {
Collection<String> sample(@NonNull final Foo foo) {
return foo.doBar(new Foo.Bar<Collection<String>>() {
@NonNull
@Override
public Collection<String> bar1() {
// ^^^^^^ java:S2638 "Fix the incompatibility of the annotation @Nullable to honor @NonNullByDefault at class level of the overridden method."
return Collections.singleton(null);
}
@NonNull
@Override
public Collection<String> bar2() {
return Collections.singleton(null);
}
});
}
}
Hey @RichardWith, welcome to the Community! This is known issue that has already been fixed in newer SonarQube Community Build versions. I recommend that you update to a more modern version (the latest one is 26.10) and try again. If the issue persists, do let us know!