This is a valid point of view, and the one that is used by people working
in the field of formal specifications.
Unfortunately, this is not a useful perspective from the point of view of
preventing null pointer errors -- which is why someone uses the nullness
checker of the Checker Framework.
Section 2.4.1 discusses this issue; see
As always, feel free to let me know if there are ways that section should
be improved.
> public boolean contains(@Result(exception=NullPointerException.class,valueIsNull=true) Object o);
>
> which could have an 'alias' annotation of:
> public boolean contains(@NullCheck Object o);
>
> which would in normal compiler setting issue a warning if null was passed
> as a parameter to contains on a class known to throw NullPointerException
> on null values. Tweaking of this to an error, or for values that could
> possibly be null, should be a setting when the annotation processor is
> run (the API should tell you what its code does, not how to write your
> own).
This has the feel of FindBugs.
FindBugs takes the approach of annotating a declaration, and thus
suppressing checking at all client uses, even the places that you want to
check. It is better to suppress warnings at only the specific client uses
where the value is known to be non-null; the Checker Framework supports
this, if you write @SuppressWarnings at the client uses. The Checker
Framework also supports suppressing checking at all client uses, by writing
a @SuppressWarnings annotation at the declaration site. So, you can choose
which approach you want.
-Mike