1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
import org.checkerframework.checker.nullness.qual.Nullable;
class Upper {
@Nullable String fs = "NonNull init";
final @Nullable String ffs = "NonNull init";
void access() {
// Error, because non-final field type is not refined
// :: error: (dereference.of.nullable)
fs.hashCode();
// Final field in the same class is refined
ffs.hashCode();
}
}
class FinalFields {
public void foo(Upper u) {
// Error, because final field in different class is not refined
// :: error: (dereference.of.nullable)
u.fs.hashCode();
}
public void bar(Lower l) {
// Error, because final field in different class is not refined
// :: error: (dereference.of.nullable)
l.fs.hashCode();
}
public void local() {
@Nullable String ls = "Locals";
// Local variable is refined
ls.hashCode();
}
}
class Lower {
@Nullable String fs = "NonNull init, too";
final @Nullable String ffs = "NonNull init, too";
void access() {
// Error, because non-final field type is not refined
// :: error: (dereference.of.nullable)
fs.hashCode();
// Final field in the same class is refined
ffs.hashCode();
}
}
|