NullAway icon indicating copy to clipboard operation
NullAway copied to clipboard

Extend `@Contract` support to handle fields

Open msridhar opened this issue 7 years ago • 2 comments

In #129 we added (some) support for JetBrains @Contract annotations. We should somehow extend this support to fields, e.g., to handle the example in this comment. This will require going beyond what is expressible with standard @Contract annotations though and will likely require introducing our own annotation.

msridhar avatar Mar 15 '18 00:03 msridhar

We could add partial support for Checker Framework nullness method annotations; see here.

msridhar avatar Oct 17 '18 19:10 msridhar

Note: In addition to supporting fields, this should be extended to getters and setters. There is a case internally where writing @Contract("this.getFoo() == null -> false") bar() would help avoid redundant checks or casts, since testing for nullability is done by the bar() validation function.

Alternatively, this could be: @Contract("foo == null -> false") bar() and @Contract("foo != null -> !null") getFoo()

lazaroclapp avatar Feb 26 '19 22:02 lazaroclapp