Skip to content

Add nullAwayOptions to configure arbitrary NullAway options - #62

Merged
making merged 2 commits into
developfrom
feature/nullaway-options
Aug 25, 2026
Merged

Add nullAwayOptions to configure arbitrary NullAway options#62
making merged 2 commits into
developfrom
feature/nullaway-options

Conversation

@making

@making making commented Aug 25, 2026

Copy link
Copy Markdown
Owner

Closes gh-55

Why

NullAway has many options that this plugin does not expose as dedicated parameters, and adding them by hand does not work:

  • <arg>-XepOpt:NullAway:KnownInitializers=...</arg> in maven-compiler-pluginerror: invalid flag, because the option is only valid inside the -Xplugin:ErrorProne argument.
  • <compilerArg>-Xplugin:ErrorProne -XepOpt:NullAway:KnownInitializers=...</compilerArg>plug-in not found: ErrorProne (see the second commit).

Exposing every NullAway option as a parameter is not realistic, so an escape hatch is added.

What

1. Detect existing compiler arguments regardless of their element name

The items of compilerArgs are a plain list, so maven-compiler-plugin accepts any element name and <compilerArg> is commonly used instead of <arg>. The plugin only inspected children named arg, so an existing -Xplugin:ErrorProne argument declared with another element name was not found and a second -Xplugin:ErrorProne argument was added, which makes javac fail with plug-in not found: ErrorProne. This is the error reported in the issue, and it is reproduced by the new errorprone-arg-element-name IT.

2. nullAwayOptions

<configuration>
    <nullAwayOptions>
        <KnownInitializers>com.example.api.SomeClass.init</KnownInitializers>
        <TreatGeneratedAsUnannotated>true</TreatGeneratedAsUnannotated>
    </nullAwayOptions>
</configuration>

is passed to the compiler as -XepOpt:NullAway:KnownInitializers=com.example.api.SomeClass.init -XepOpt:NullAway:TreatGeneratedAsUnannotated=true, for both main and test compilation.

The map form is used instead of the <nullAwayOption>Key=Value</nullAwayOption> list proposed in the issue: the option name is the key, so no string parsing is needed, the values may contain commas (KnownInitializers takes a comma-separated list), and an entry can override the option of the same name that the plugin derives from the other parameters instead of emitting the option twice.

The options can also be set as nullability.nullAwayOptions.<name> Maven properties, keeping the parity with the other parameters. A <configuration> entry wins over the property of the same option name.

Option names and values must not contain whitespace, because all options are appended to a single -Xplugin:ErrorProne argument; the build fails with an explicit message otherwise.

Tests

  • NullabilityLifecycleParticipantTest (new): parsing from <configuration> and from properties, precedence, trimming, validation errors.
  • NullAwayArgsBuilderTest, NullabilityConfigurationTest, CompilerConfigurerTest: option emission, override of derived options, defensive copy, and the duplicated -Xplugin:ErrorProne regression.
  • New ITs nullaway-options (the build only succeeds because KnownInitializers reaches NullAway -- without it the compilation fails with @NonNull field 'greeting' not initialized) and errorprone-arg-element-name.
  • ./mvnw verify passes (15 ITs).

README is updated with a "Setting arbitrary NullAway options" section.

🤖 Generated with Claude Code

making and others added 2 commits August 25, 2026 13:36
The items of maven-compiler-plugin's compilerArgs are a plain list, so any
element name is accepted and <compilerArg> is commonly used instead of <arg>.
The plugin only inspected the children named "arg", so an ErrorProne argument
declared as <compilerArg> was not found and a second -Xplugin:ErrorProne
argument was added, which makes javac fail with "plug-in not found: ErrorProne".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
NullAway has many options that are not exposed as dedicated parameters, and
adding -XepOpt:NullAway:... to maven-compiler-plugin by hand does not work:
javac rejects it as an invalid flag unless it is part of the -Xplugin:ErrorProne
argument.

Options can now be set by name, without the -XepOpt:NullAway: prefix:

    <configuration>
        <nullAwayOptions>
            <KnownInitializers>com.example.SomeClass.init</KnownInitializers>
        </nullAwayOptions>
    </configuration>

or as nullability.nullAwayOptions.<name> Maven properties. An entry overrides
the option of the same name derived from the other parameters, so no duplicated
option is emitted. Option names and values must not contain whitespace because
they are appended to a single -Xplugin:ErrorProne argument.

Closes gh-55

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@making
making merged commit 365739b into develop Aug 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option to configure arbitrary NullAway configuration option

1 participant