I configured Intellij to use checkerframework @Nullable and @NonNull annotation but I can’t get the inspections to generate an error or a warning at the indicated line (without specifically annotating it with @NonNull.
public interface MyInterface {
/**
* @return whatever I expect this to be considered @NonNull
*/
String getWhatever();
}
// ...
import org.checkerframework.checker.nullness.qual.Nullable;
public class MyClass implements MyInterface {
/** I expect this to be considered @NonNull */
private final /*@NonNull*/ String whatever;
/**
* @param whatever I expect this to be considered @NonNull
*/
public MyClass(String whatever) {
// *************************************
// I expect an error (or warning) on the
// next line while assigning a nullable
// value to a non null field.
// *************************************
this.whatever = validateWhatever(whatever);
}
@Override
public String getWhatever() {
return whatever;
}
/**
* @param whatever
* @return whatever or null on error.
*/
private static @Nullable String validateWhatever(String whatever) {
try {
// do something
return whatever;
} catch (Exception e) {
return null;
}
}
}