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

Extend `@Contract` support to handle fields #134

Open msridhar opened 6 years ago

msridhar commented 6 years ago

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 commented 6 years ago

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

lazaroclapp commented 5 years ago

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()