I am trying to add NullAway to my project and I have ran into what I think is a false positive.
I tried to make it as small as possible and this shows the problem:
import java.util.HashMap;
import java.util.Map;
public class Test {
public static void main(String[] args) {
String httpStatusValue = "200";
Map<String, String> map = new HashMap<>();
if (map.get(someOperation()) != null) {
staticMethod(map.get(someOperation()));
} else if (map.get(someOtherOperation(httpStatusValue)) != null) {
staticMethod(map.get(someOtherOperation(httpStatusValue)));
}
}
private static String someOperation() {
return "test";
}
private static String someOtherOperation(String httpStatusValue) {
return "test2";
}
private static void staticMethod(String t) {
String trimmed = t.trim();
System.out.println("trimmed = " + trimmed);
}
}
Running NullAway on this code gives:
error: [NullAway] passing @Nullable parameter 'map.get(someOtherOperation(httpStatusValue))' where @NonNull is required
Note that is only reports the problem for the someOtherOperation that has a parameter. The other method that has no parameter is ok.
I am using @NullMarked on the package that this class is in, and run with these settings -Xplugin:ErrorProne -Xep:NullAway:ERROR -XepOpt:NullAway:OnlyNullMarked.