Annotation Interface Nullable


This annotation marks a field, parameter, local variable, or method (return value) as potentially having the value null. The specific semantics implied by this annotation depend on the kind of element the annotation is applied to.
  • Field or Local Variable: Code reading the field or local variable may not assume that the value is never null.
  • Parameter: Code calling the method might pass null for this parameter. The documentation for the method should describe the behavior of the method in the event this parameter is null.
  • Method (Return Value): Code calling the method may not assume that the result of the method is never null. The documentation for the method should describe the meaning of a null reference being returned. Overriding methods may optionally use the NotNull annotation instead of this annotation for the method, indicating that the overriding method (and any method which overrides it) will never return a null reference.

The NullUsageProcessor annotation processor validates certain usage scenarios for this annotation, with compile-time errors or warnings reported for misuse. For detailed information about the supported analysis, see the documentation for NullUsageProcessor.