Skip to content

Supported Annotations

Manu Sridharan edited this page Mar 15, 2018 · 23 revisions

This page documents the different code annotations that are supported by NullAway by default.

Nullability

NullAway treats any annotation whose simple (un-qualified) name is @Nullable as marking a parameter / return / field as nullable. Checker Framework's @NullableDecl is also supported.

Initialization

Any annotation whose simple (un-qualified) name is @Initializer is treated as marking a method as an initializer (see here for more information on initialization checking). We also support JUnit's @Before and @BeforeClass for marking initializers.

Contracts

NullAway has partial support for JetBrains @Contract annotations. Some examples:

public class NullnessChecker {
  @Contract("_, null -> true")
  static boolean isNull(boolean flag, @Nullable Object o) { return o == null; }
  @Contract("null -> false")
  static boolean isNonNull(@Nullable Object o) { return o != null; }
  @Contract("null -> fail")
  static void assertNonNull(@Nullable Object o) { if (o != null) throw new Error(); }
}
Clone this wiki locally