Class NullAwayOptions

java.lang.Object
net.ltgt.gradle.nullaway.NullAwayOptions

public abstract class NullAwayOptions extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Disable NullAway.
    void
    Enable NullAway.
    void
    Enable NullAway as an error.
    abstract org.gradle.api.provider.Property<Boolean>
    If set to true, treats @RecentlyNullable as {code @Nullable}, and @RecentlyNonNull as @NonNull; maps to -XepOpt:NullAway:AcknowledgeAndroidRecent.
    abstract org.gradle.api.provider.Property<Boolean>
    If set to true, NullAway will acknowledge nullability annotations whenever they are available in unannotated code and also more restrictive than it's optimistic defaults; maps to -XepOpt:NullAway:AcknowledgeRestrictiveAnnotations.
    abstract org.gradle.api.provider.ListProperty<String>
    The list of packages that should be considered properly annotated according to the NullAway convention; maps to -XepOpt:NullAway:AnnotatedPackages.
    abstract org.gradle.api.provider.Property<Boolean>
    If set to true, NullAway will handle assertions, and use that to reason about the possibility of null dereferences in the code that follows these assertions; maps to -XepOpt:NullAway:AssertsEnabled.
    abstract org.gradle.api.provider.Property<String>
    A comment that will be added alongside the @SuppressWarnings("NullAway") annotation when suggestSuppressions is set to true; maps to -XepOpt:NullAway:AutoFixSuppressionComment.
    abstract org.gradle.api.provider.Property<String>
    The fully qualified name of a method to be used for downcasting to a non-null value rather than standard suppressions in some instances; maps to -XepOpt:NullAway:CastToNonNullMethod.
    abstract org.gradle.api.provider.Property<Boolean>
    If set to true, NullAway will check @Contract annotations; maps to -XepOpt:NullAway:CheckContracts.
    abstract org.gradle.api.provider.Property<Boolean>
    If set to true, NullAway will check for .get() accesses to potentially empty Optional values, analogously to how it handles dereferences to @Nullable values; maps to -XepOpt:NullAway:CheckOptionalEmptiness.
    abstract org.gradle.api.provider.ListProperty<String>
    A list of classes to be treated as Optional implementations (e.g.
    abstract org.gradle.api.provider.ListProperty<String>
    A list of annotations that should be considered equivalent to @Contract annotations; maps to -XepOpt:NullAway:CustomContractAnnotations.
    abstract org.gradle.api.provider.ListProperty<String>
    A list of annotations that should be considered equivalent to @Generated annotations, for the cases where NullAway cares about such annotations (see e.g.
    abstract org.gradle.api.provider.ListProperty<String>
    A list of annotations that should be considered equivalent to @Initializer annotations, and thus mark methods as initializers; maps to -XepOpt:NullAway:CustomInitializerAnnotations.
    abstract org.gradle.api.provider.ListProperty<String>
    A list of annotations that should be considered equivalent to @NonNull annotations, for the cases where NullAway cares about such annotations (see e.g.
    abstract org.gradle.api.provider.ListProperty<String>
    A list of annotations that should be considered equivalent to @Nullable annotations; maps to -XepOpt:NullAway:CustomNullableAnnotations.
    abstract org.gradle.api.provider.ListProperty<String>
    A list of annotations that cause classes to be excluded from nullability analysis; maps tp -XepOpt:NullAway:ExcludedClassAnnotations.
    abstract org.gradle.api.provider.ListProperty<String>
    A list of classes to be excluded from the nullability analysis; maps to -XepOpt:NullAway:ExcludedClasses.
    abstract org.gradle.api.provider.ListProperty<String>
    A list of annotations that cause fields to be excluded from being checked for proper initialization; maps to -XepOpt:NullAway:ExcludedFieldAnnotations.
    abstract org.gradle.api.provider.Property<Boolean>
    If set to true, NullAway will check every method to see whether or not it overrides a method of a super-type, rather than relying only on the @Override annotation; maps to -XepOpt:NullAway:ExhaustiveOverride.
    abstract org.gradle.api.provider.ListProperty<String>
    A list of annotations for classes that are "externally initialized;" maps to -XepOpt:NullAway:ExternalInitAnnotations.
    abstract org.gradle.api.provider.ListProperty<String>
    A list of classes to be treated equivalently to Guava Futures` and `FluentFuture; maps to -XepOpt:NullAway:ExtraFuturesClasses.
    abstract org.gradle.api.provider.Property<Boolean>
    If set to true, NullAway will handle assertions from test libraries, like assertThat(...).isNotNull(), and use that to reason about the possibility of null dereferences in the code that follows these assertions; maps to -XepOpt:NullAway:HandleTestAssertionLibraries.
    abstract org.gradle.api.provider.Property<Boolean>
    Should wildcard-aware generic nullability checks be enabled?
    abstract org.gradle.api.provider.Property<Boolean>
    Convenience option that enables the experimental HandleWildcardGenerics, JSpecifyJDKModels, and WarnOnGenericInferenceFailure features; maps to -XepOpt:NullAwway:JSpecifyExperimental.
    abstract org.gradle.api.provider.Property<Boolean>
    Enables NullAway's built-in JSpecify nullness models for JDK APIs; maps to -XepOpt:NullAway:JSpecifyJDKModels.
    abstract org.gradle.api.provider.Property<Boolean>
    If set to true, enables new checks based on JSpecify (like checks for generic types); maps to -XepOpt:NullAway:JSpecifyMode.
    abstract org.gradle.api.provider.ListProperty<String>
    The fully qualified name of those methods from third-party libraries that NullAway should treat as initializers; maps to -XepOpt:NullAway:KnownInitializers.
    abstract org.gradle.api.provider.Property<Boolean>
    Indicates that the annotatedPackages flag has been deliberately omitted, and that NullAway can proceed with only treating @NullMarked code as annotated, in accordance with the JSpecify specification; maps to -XepOpt:NullAway:OnlyNullMarked.
    abstract org.gradle.api.provider.Property<net.ltgt.gradle.errorprone.CheckSeverity>
    The severity of the NullAway check.
    abstract org.gradle.api.provider.Property<Boolean>
    If set to true, NullAway will use Error Prone's suggested fix functionality to suggest suppressing any warning that it finds; maps to -XepOpt:NullAway:SuggestSuppressions.
    abstract org.gradle.api.provider.ListProperty<String>
    A list of names to suppress NullAway using a @SuppressWarnings annotation, similar to @SuppressWarnings("NullAway"); maps to -XepOpt:NullAway:SuppressionNameAliases.
    abstract org.gradle.api.provider.Property<Boolean>
    If set to true, NullAway treats any class annotated with @Generated as if its APIs are unannotated when analyzing uses from other classes; maps to -XepOpt:NullAway:TreatGeneratedAsUnannotated.
    abstract org.gradle.api.provider.ListProperty<String>
    A list of classes within annotated packages that should be treated as unannotated; maps to -XepOpt:NullAway:UnannotatedClasses.
    abstract org.gradle.api.provider.ListProperty<String>
    A list of subpackages to be excluded from the annotatedPackages list; maps to -XepOpt:NullAway:UnannotatedSubPackages.
    abstract org.gradle.api.provider.Property<Boolean>
    If set to true, NullAway will issue a warning when generic type inference fails to infer a type argument's nullability; maps to -XepOpt:NullAway:WarnOnGenericInferenceFailure.
    void
    Enable NullAway as a warning.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NullAwayOptions

      @Inject public NullAwayOptions(NullAwayExtension nullawayExtension)
  • Method Details

    • getSeverity

      @Input public abstract org.gradle.api.provider.Property<net.ltgt.gradle.errorprone.CheckSeverity> getSeverity()
      The severity of the NullAway check.

      Almost equivalent to options.errorprone.check("NullAway", severity) (NullAway won't actually appear in options.errorprone.checks). Can be set to CheckSeverity.OFF to disable NullAway.

      See Also:
      • ErrorProneOptions.check(String, CheckSeverity)
      • ErrorProneOptions.check(String, Provider)
      • ErrorProneOptions.getChecks()
      • enable()
      • disable()
      • warn()
      • error()
    • getOnlyNullMarked

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getOnlyNullMarked()
      Indicates that the annotatedPackages flag has been deliberately omitted, and that NullAway can proceed with only treating @NullMarked code as annotated, in accordance with the JSpecify specification; maps to -XepOpt:NullAway:OnlyNullMarked.

      If this option is passed, then annotatedPackages must be empty. Note that even if this flag is omitted (and annotatedPackages is non-empty), any @NullMarked code will still be treated as annotated.

      Defaults to the value configured at the project-level.

    • getAnnotatedPackages

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getAnnotatedPackages()
      The list of packages that should be considered properly annotated according to the NullAway convention; maps to -XepOpt:NullAway:AnnotatedPackages.

      This can be used to add to or override the annotatedPackages at the project level.

      Defaults to the list configured at the project-level.

    • getUnannotatedSubPackages

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getUnannotatedSubPackages()
      A list of subpackages to be excluded from the annotatedPackages list; maps to -XepOpt:NullAway:UnannotatedSubPackages.
    • getUnannotatedClasses

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getUnannotatedClasses()
      A list of classes within annotated packages that should be treated as unannotated; maps to -XepOpt:NullAway:UnannotatedClasses.
    • getKnownInitializers

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getKnownInitializers()
      The fully qualified name of those methods from third-party libraries that NullAway should treat as initializers; maps to -XepOpt:NullAway:KnownInitializers.
    • getExcludedClassAnnotations

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getExcludedClassAnnotations()
      A list of annotations that cause classes to be excluded from nullability analysis; maps tp -XepOpt:NullAway:ExcludedClassAnnotations.
    • getExcludedClasses

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getExcludedClasses()
      A list of classes to be excluded from the nullability analysis; maps to -XepOpt:NullAway:ExcludedClasses.
    • getExcludedFieldAnnotations

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getExcludedFieldAnnotations()
      A list of annotations that cause fields to be excluded from being checked for proper initialization; maps to -XepOpt:NullAway:ExcludedFieldAnnotations.
    • getCustomInitializerAnnotations

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getCustomInitializerAnnotations()
      A list of annotations that should be considered equivalent to @Initializer annotations, and thus mark methods as initializers; maps to -XepOpt:NullAway:CustomInitializerAnnotations.
    • getExternalInitAnnotations

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getExternalInitAnnotations()
      A list of annotations for classes that are "externally initialized;" maps to -XepOpt:NullAway:ExternalInitAnnotations.
    • getTreatGeneratedAsUnannotated

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getTreatGeneratedAsUnannotated()
      If set to true, NullAway treats any class annotated with @Generated as if its APIs are unannotated when analyzing uses from other classes; maps to -XepOpt:NullAway:TreatGeneratedAsUnannotated.
    • getAcknowledgeRestrictiveAnnotations

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getAcknowledgeRestrictiveAnnotations()
      If set to true, NullAway will acknowledge nullability annotations whenever they are available in unannotated code and also more restrictive than it's optimistic defaults; maps to -XepOpt:NullAway:AcknowledgeRestrictiveAnnotations.
      See Also:
    • getCheckOptionalEmptiness

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getCheckOptionalEmptiness()
      If set to true, NullAway will check for .get() accesses to potentially empty Optional values, analogously to how it handles dereferences to @Nullable values; maps to -XepOpt:NullAway:CheckOptionalEmptiness.
      See Also:
    • getSuggestSuppressions

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getSuggestSuppressions()
      If set to true, NullAway will use Error Prone's suggested fix functionality to suggest suppressing any warning that it finds; maps to -XepOpt:NullAway:SuggestSuppressions.
      See Also:
    • getAssertsEnabled

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getAssertsEnabled()
      If set to true, NullAway will handle assertions, and use that to reason about the possibility of null dereferences in the code that follows these assertions; maps to -XepOpt:NullAway:AssertsEnabled.

      This assumes that assertions will always be enabled at runtime (java run with -ea JVM argument).

    • getExhaustiveOverride

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getExhaustiveOverride()
      If set to true, NullAway will check every method to see whether or not it overrides a method of a super-type, rather than relying only on the @Override annotation; maps to -XepOpt:NullAway:ExhaustiveOverride.
    • getCastToNonNullMethod

      @Input @Optional public abstract org.gradle.api.provider.Property<String> getCastToNonNullMethod()
      The fully qualified name of a method to be used for downcasting to a non-null value rather than standard suppressions in some instances; maps to -XepOpt:NullAway:CastToNonNullMethod.
    • getCheckOptionalEmptinessCustomClasses

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getCheckOptionalEmptinessCustomClasses()
      A list of classes to be treated as Optional implementations (e.g. Guava's com.google.common.base.Optional); maps to -XepOpt:NullAway:CheckOptionalEmptinessCustomClasses.
      See Also:
    • getAutoFixSuppressionComment

      @Input @Optional public abstract org.gradle.api.provider.Property<String> getAutoFixSuppressionComment()
      A comment that will be added alongside the @SuppressWarnings("NullAway") annotation when suggestSuppressions is set to true; maps to -XepOpt:NullAway:AutoFixSuppressionComment.
      See Also:
    • getHandleTestAssertionLibraries

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getHandleTestAssertionLibraries()
      If set to true, NullAway will handle assertions from test libraries, like assertThat(...).isNotNull(), and use that to reason about the possibility of null dereferences in the code that follows these assertions; maps to -XepOpt:NullAway:HandleTestAssertionLibraries.
    • getAcknowledgeAndroidRecent

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getAcknowledgeAndroidRecent()
      If set to true, treats @RecentlyNullable as {code @Nullable}, and @RecentlyNonNull as @NonNull; maps to -XepOpt:NullAway:AcknowledgeAndroidRecent.

      Requires that acknowledgeRestrictiveAnnotations is also set to true.

      See Also:
    • getCheckContracts

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getCheckContracts()
      If set to true, NullAway will check @Contract annotations; maps to -XepOpt:NullAway:CheckContracts.
    • getCustomContractAnnotations

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getCustomContractAnnotations()
      A list of annotations that should be considered equivalent to @Contract annotations; maps to -XepOpt:NullAway:CustomContractAnnotations.
    • getCustomNullableAnnotations

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getCustomNullableAnnotations()
      A list of annotations that should be considered equivalent to @Nullable annotations; maps to -XepOpt:NullAway:CustomNullableAnnotations.
    • getCustomNonnullAnnotations

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getCustomNonnullAnnotations()
      A list of annotations that should be considered equivalent to @NonNull annotations, for the cases where NullAway cares about such annotations (see e.g. acknowledgeRestrictiveAnnotations); maps to -XepOpt:NullAway:CustomNonnullAnnotations.
    • getCustomGeneratedCodeAnnotations

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getCustomGeneratedCodeAnnotations()
      A list of annotations that should be considered equivalent to @Generated annotations, for the cases where NullAway cares about such annotations (see e.g. treatGeneratedAsUnannotated); maps to -XepOpt:NullAway:CustomGeneratedCodeAnnotations.
    • getJspecifyMode

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getJspecifyMode()
      If set to true, enables new checks based on JSpecify (like checks for generic types); maps to -XepOpt:NullAway:JSpecifyMode.
    • getExtraFuturesClasses

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getExtraFuturesClasses()
      A list of classes to be treated equivalently to Guava Futures` and `FluentFuture; maps to -XepOpt:NullAway:ExtraFuturesClasses.

      This special support will likely be removed once NullAway's JSpecify support is more complete.

    • getSuppressionNameAliases

      @Input @Optional public abstract org.gradle.api.provider.ListProperty<String> getSuppressionNameAliases()
      A list of names to suppress NullAway using a @SuppressWarnings annotation, similar to @SuppressWarnings("NullAway"); maps to -XepOpt:NullAway:SuppressionNameAliases.

      This is useful when other warnings are already suppressed in the codebase and NullAway should be suppressed as well, such as with JetBrains' [ DataFlowIssue](https://www.jetbrains.com/help/inspectopedia/DataFlowIssue.html) inspection.

    • getWarnOnGenericInferenceFailure

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getWarnOnGenericInferenceFailure()
      If set to true, NullAway will issue a warning when generic type inference fails to infer a type argument's nullability; maps to -XepOpt:NullAway:WarnOnGenericInferenceFailure.
    • getHandleWildcardGenerics

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getHandleWildcardGenerics()
      Should wildcard-aware generic nullability checks be enabled? maps to -XepOpt:NullAway:HandleWildcardGenerics.
    • getJspecifyExperimental

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getJspecifyExperimental()
      Convenience option that enables the experimental HandleWildcardGenerics, JSpecifyJDKModels, and WarnOnGenericInferenceFailure features; maps to -XepOpt:NullAwway:JSpecifyExperimental.

      This option must be used with jspecifyMode = true. An explicit value for any of the individual feature flags overrides the value supplied by this option.

    • getJspecifyJdkModels

      @Input @Optional public abstract org.gradle.api.provider.Property<Boolean> getJspecifyJdkModels()
      Enables NullAway's built-in JSpecify nullness models for JDK APIs; maps to -XepOpt:NullAway:JSpecifyJDKModels.

      This option may only be enabled in JSpecify mode.

    • enable

      public void enable()
      Enable NullAway.

      Equivalent to setting severity to CheckSeverity.DEFAULT.

    • disable

      public void disable()
      Disable NullAway.

      Equivalent to setting severity to CheckSeverity.OFF.

    • warn

      public void warn()
      Enable NullAway as a warning.

      Equivalent to setting severity to CheckSeverity.WARN

    • error

      public void error()
      Enable NullAway as an error.

      Equivalent to setting severity to CheckSeverity.ERROR