Skip to content

Add @Nullable annotations and NullAway profile for Maven 4 API#11818

Open
gnodet wants to merge 1 commit intoapache:masterfrom
gnodet:nullaway-annotations
Open

Add @Nullable annotations and NullAway profile for Maven 4 API#11818
gnodet wants to merge 1 commit intoapache:masterfrom
gnodet:nullaway-annotations

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Mar 20, 2026

Summary

  • Add opt-in NullAway profile (-Pnullaway) using Error Prone 2.36.0 + NullAway 0.12.6 for compile-time null safety checking on org.apache.maven.api packages
  • Add @Nullable annotations across the Maven 4 API where values can genuinely be null: fields, method parameters, return types, builder fields, generated model code (via Velocity template)
  • Add requireNonNull() validation in builder build() methods to preserve existing @Nonnull API contracts — no @Nonnull annotations were changed to @Nullable
  • Fix InputLocation.locations field: was incorrectly annotated @Nullable but is never null (always initialized via ImmutableCollections which returns empty map for null input)
  • Fix Sources.BuildPathSource.resolve() null safety for Path.getParent() which can return null

Details

The NullAway profile runs at WARN level with -XepDisableAllChecks so only NullAway warnings are reported. It is designed as an opt-in quality check, not a build gate. The profile configures NullAway to recognize Maven's custom @Nullable and @Nonnull annotations.

Files changed fall into these categories:

  • Hand-written API classes: Added @Nullable to genuinely nullable fields, params, and return types
  • Builder classes: Added @Nullable to builder fields (which start null) and requireNonNull() in build() methods for non-null params
  • Velocity template (model.vm): Added @Nullable to non-primitive, non-collection generated fields and their getters
  • Template source files (InputLocation.java, InputSource.java, etc.): Added @Nullable annotations
  • .mdo model files: Added @Nullable to code segments where needed

Test plan

  • All existing tests pass (mvn clean test -f api)
  • Clean compile without NullAway profile (mvn clean compile -f api)
  • Zero NullAway warnings with profile enabled (mvn clean compile -f api -Pnullaway)
  • Verify no downstream breakage in maven-core modules

🤖 Generated with Claude Code

@gnodet gnodet force-pushed the nullaway-annotations branch 2 times, most recently from ffcc698 to b603fc4 Compare March 20, 2026 10:58
…ile-time null checks

- Add opt-in NullAway profile (-Pnullaway) using Error Prone 2.36.0 + NullAway 0.12.6
  for compile-time null safety checking on org.apache.maven.api packages
- Add @nullable annotations to fields, method parameters, and return types across
  the Maven 4 API where values can genuinely be null
- Add @nullable to Velocity model template (model.vm) for generated model classes:
  non-primitive, non-collection fields and their getters
- Add @nullable to hand-written template files: InputLocation, InputSource,
  InputLocationTracker, ImmutableCollections
- Add @nullable to XmlNode builder, XmlService merge methods, XmlReaderRequest,
  XmlWriterRequest
- Add @nullable to builder fields in request classes (fields start null before
  builder methods are called)
- Add requireNonNull() validation in builder build() methods for parameters
  that must be non-null, preserving existing @nonnull API contracts
- Fix InputLocation.locations field: not nullable (always initialized via
  ImmutableCollections which returns empty map for null input)
- Fix Sources.BuildPathSource.resolve() null safety for Path.getParent()
- Add @nullable to Nullable annotation itself (meta-annotation for NullAway)
- Fix Phase.getEffectiveId() return annotation in lifecycle.mdo

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet force-pushed the nullaway-annotations branch from b603fc4 to 7a89764 Compare March 20, 2026 11:06
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.

1 participant