-
Notifications
You must be signed in to change notification settings - Fork 629
Closed
Description
Hello, I have found an issue that appears to be a bug.
Description
After updating to SpotBugs 4.8.4, the method annotated with edu.umd.cs.findbugs.annotations.Nullable is incorrectly flagged with NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE as a false positive.
https://spotbugs.readthedocs.io/en/stable/annotations.html#edu-umd-cs-findbugs-annotations-nullable
The annotated element could be null under some circumstances. This is treated the same way as not being annotated.
Java version
- OpenJDK Runtime Environment Corretto-21.0.1.12.1 (build 21.0.1+12-LTS)
Change Version
- SpotBugs: 4.8.3 to 4.8.4
minimum example
package com.sample.realworld;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
public class Main {
public static void main(String[] args) {
var hoge = new Hoge();
System.out.println(hoge.sample);
}
public static class Hoge {
@NonNull
public String sample = getNullable();
@Nullable String getNullable() {
return "someValue";
}
}
}
Build script
plugins {
id 'java'
id("com.github.spotbugs") version "6.0.26"
}
group = 'com.sample.realworld'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
gradlePluginPortal()
}
dependencies {
spotbugs("com.github.spotbugs:spotbugs:4.8.4")
// spotbugs("com.github.spotbugs:spotbugs:4.8.3")
compileOnly "com.github.spotbugs:spotbugs-annotations:${spotbugs.toolVersion.get()}"
}
Result run SpotBugsMain
Run SpotBugs with version 4.8.3:
./gradlew -Duser.language=en -Duser.country=US clean spotbugsMain
BUILD SUCCESSFUL in 1s
3 actionable tasks: 3 executed
Run SpotBugs with version 4.8.4:
./gradlew -Duser.language=en -Duser.country=US clean spotbugsMain
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
> Task :spotbugsMain FAILED
M D NP: Possible null pointer dereference in com.sample.realworld.Main.main(String[]) due to return value of called method Method invoked at Main.java:[line 13]
FAILURE: Build failed with an exception. NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE * What went wrong:
Execution failed for task ':spotbugsMain'.
> A failure occurred while executing com.github.spotbugs.snom.internal.SpotBugsRunnerForHybrid$SpotBugsExecutor
> Verification failed: SpotBugs ended with exit code 1.
expected behavior
NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE is not detected
Additional Information
This Pull Request is probably the cause
#2694
Remove Nullable Annotation
spotbugs("com.github.spotbugs:spotbugs:4.8.4")
public class Main {
public static void main(String[] args) {
var hoge = new Hoge();
System.out.println(hoge.sample);
}
public static class Hoge {
@NonNull
public String sample = getNullable();
String getNullable() {
return null;
}
}
}
Run spotBugsMain
./gradlew -Duser.language=en -Duser.country=US clean spotbugsMain
BUILD SUCCESSFUL in 1s
3 actionable tasks: 3 executed
Thank you.