-
Notifications
You must be signed in to change notification settings - Fork 628
Closed
Description
if i have code like below:
public class Container {
@Nullable
private String name;
public Container() throws Exception {
Callable<String[]> shortTask = new Callable<String[]>() {
@Override
public String[] call() throws Exception {
if (!name.isEmpty()) {
System.out.println("name = " + name);
}
return getShortName().split(",");
}
};
shortTask.call();
}
@Nullable
private String getShortName() {
return name.length() < 5 ? null : name.split(",")[0];
}
}
now spotbugs will report NP for name
because field access which decorated by @Nullable
annotation :
<BugInstance type="NP_NULL_ON_SOME_PATH" priority="2" rank="8" abbrev="NP" category="CORRECTNESS">
<Class classname="com.example.libdemo.Container$1">
<SourceLine classname="com.example.libdemo.Container$1" start="12" end="20" sourcefile="Container.java" sourcepath="com/example/libdemo/Container.java"/>
</Class>
<Method classname="com.example.libdemo.Container$1" name="call" signature="()[Ljava/lang/String;" isStatic="false">
<SourceLine classname="com.example.libdemo.Container$1" start="16" end="20" startBytecode="0" endBytecode="110" sourcefile="Container.java" sourcepath="com/example/libdemo/Container.java"/>
</Method>
<Field classname="com.example.libdemo.Container" name="name" signature="Ljava/lang/String;" isStatic="false" role="FIELD_CONTAINS_VALUE">
<SourceLine classname="com.example.libdemo.Container" sourcefile="Container.java" sourcepath="com/example/libdemo/Container.java"/>
</Field>
<SourceLine classname="com.example.libdemo.Container$1" start="16" end="16" startBytecode="7" endBytecode="7" sourcefile="Container.java" sourcepath="com/example/libdemo/Container.java" role="SOURCE_LINE_DEREF"/>
<SourceLine classname="com.example.libdemo.Container$1" start="16" end="16" startBytecode="4" endBytecode="4" sourcefile="Container.java" sourcepath="com/example/libdemo/Container.java" role="SOURCE_LINE_KNOWN_NULL"/>
</BugInstance>
but not the getShortName()
method access with same annotation.
Metadata
Metadata
Assignees
Labels
No labels