uber / NullAway

A tool to help eliminate NullPointerExceptions (NPEs) in your Java code with low build-time overhead
MIT License
3.63k stars 293 forks source link

False negative for method call on interface from function parameter #896

Closed cobratbq closed 9 months ago

cobratbq commented 9 months ago

A violation of @Nonnull is not detected when a method is called on an instance received as argument. The function parameter test of type InterfaceType contains a method Bla that does NOT guarantee @Nonnull on the return-type. This is not detected as an issue.

@Nonnull
private static String testOuter(final InterfaceType test) {
    // test.Bla does not guarantee @Nonnull
    return test.Bla("a");
}
msridhar commented 9 months ago

@cobratbq NullAway assumes that any type without an annotation is @Nonnull by default. So writing @Nonnull explicitly has no effect. I would expect to see an error inside the Bla() method for a case like this. Do you see anything like that?

cobratbq commented 9 months ago

@cobratbq NullAway assumes that any type without an annotation is @Nonnull by default. So writing @Nonnull explicitly has no effect. I would expect to see an error inside the Bla() method for a case like this. Do you see anything like that?

The interface is defined for interoperability, so an implementation is not provided. It is expected to be implemented by the user of the library. NullAway, for this code-base, has only the interface and the method calls to work with. (Apart from some tests.)

I am taken by surprise, because this seems to deviate from the practices of other analysis tools that by-default assume plain Java behavior, unless explicitly annotated on invidual cases or per-package.

Regardless, that's my mistake. Explicitly annotating the interface works. Sorry about my false false negative :-P