Minimum Working Example -
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
public class BugCheck {
public static void main(String[] args) {
@SuppressWarnings("assignment.type.incompatible")
@NonNull String s1 = nString1();
s1 = nString2();
}
private static @Nullable String nString2() {
return "World";
}
private static @Nullable String nString1() {
return "Hello";
}
}
Command -
javacheck -processor nullness BugCheck.java
Expected behavior -
Compile normally.
Actual behavior -
BugCheck.java:8: error: [assignment.type.incompatible] incompatible types in assignment.
s1 = nString2();
^
found: @Initialized @Nullable String
required: @UnknownInitialization @NonNull String
1 error
Comments -
This might be the expected behavior to prevent the misuse of variable s1 further in the code, but I read through section 29.1 (@SuppressWarnings annotation) in the manual and did not find any clarifications regarding this, so I decided to report it. This is a recurring pattern in my case study where I have to transfer the (Nullable) contents of a ResultSet to an ArrayList which holds NonNull elements, where I can guarantee that the contents are not null.
Thanks in advance.