This detector checks that overriding methods do not relax @NonNull (made @CheckForNull) on return values or @CheckForNull (made @NonNull) on parameters.
I'll explain it with two examples.
Return value relaxation: given the following calsses:
public class TestOverride {
static interface I {
@NonNull
Object get();
}
static interface SI extends I {
@CheckForNull
Object get();
}
void a(I i) {
i.get().toString();
}
void b() {
a(new SI() {
public Object get() {
return null;
}
});
}
In the example SI relaxes the nullness of the return value for the get() method (overrides the annotation from @NonNull to @CheckForNull), that means that the "return null" in the anonymous class in b() would not be warned, causing i.get().toString() to throw a NullPointerException in a(i).
Parameter relaxation: given the following calsses:
public class TestOverride {
static interface I {
void set(@CheckForNull Object o);
}
static interface SI extends I {
public void set(@NonNull Object o);
}
void a(I i) {
i.set(null);
}
void b() {
a(new SI() {
public void set(Object o) {
o.toString();
}
});
}
In the example SI relaxes the nullness of the paramter for the set() method (overrides the annotation from @CheckForNull to @NonNull), that means that the "i.set(null)" in the anonymous class in a() would not be warned, causing to throw a NullPointerException when SI.set() tries to run o.toString().
Nullness relaxation detector
Hi,
thanks for the patch, I think this one is very valuable.
I've applied the (updated/refactored) patch, please check
http://code.google.com/p/findbugs/source/detail?r=14656
Please review it.
If no one have no objections, we could close this issue.
Regards,
Andrey