Skip to content

Handle null plugin maps in BuildHelper - #409

Merged
gnodet merged 1 commit into
apache:masterfrom
efegokdemir:codex/368-null-plugin-map
Oct 9, 2026
Merged

gnodet merged 1 commit into
apache:masterfrom
efegokdemir:codex/368-null-plugin-map

Conversation

@efegokdemir

Copy link
Copy Markdown

Summary

  • Handle a null plugin map returned by a Maven model without throwing a NullPointerException.
  • Add regression coverage for models whose getPluginsAsMap() returns null.

Fixes #368

Testing

  • mvn -Dspotless.skip=true -Dtest=BuildHelperTest test — passed.
  • git diff --check — passed.

Spotless was skipped for the focused local run because the installed formatter is incompatible with the current JDK environment.

AI assistance was used during implementation; the submitted changes were reviewed and validated against the issue and repository tests.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minimal and correct defensive null check. The real PluginContainer.getPluginsAsMap() implementation (lazy init from @Nonnull plugins field) can never return null, but the method lacks a @Nonnull annotation — so coding defensively against the API contract is the right call. The test correctly exercises the fix path through the public getPlugin(Model, String) entry point.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one-line null check in getPlugin is correct and harmless. However, the test has issues that should be addressed before merge.

Note: in the current Maven 4 model, PluginContainer.getPluginsAsMap() never returns null — it lazily builds an immutable map from the plugins list, which itself defaults to emptyList() via ImmutableCollections.copy(null). So this fix is purely defensive against non-standard PluginContainer implementations. That's fine, but the test should reflect this reality.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review after commit 3e89015 — all three previous findings are addressed:

  1. Mocking rationale comment — ✅ Class-level comment added explaining why mocking is necessary (standard model can't produce null maps).
  2. Full test suite verification — ✅ Confirmed mvn verify passes (99 tests, 0 failures). Mock intercepts correctly despite getPluginsAsMap() being inherited from PluginContainer.
  3. Missing getPluginManagement() null-map test — ✅ getPluginHandlesNullPluginMapInPluginManagement() added, covering the second lookup path exactly as suggested.

Production code is minimal and correct. Tests are well-structured with proper assertions. Ready to merge.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet gnodet added this to the 4.0.0-beta-5 milestone Sep 28, 2026
@gnodet gnodet added bug Something isn't working java Pull requests that update Java code labels Oct 9, 2026
- Guard getPluginsAsMap() calls with null checks to prevent NPE when plugin management or build plugins map is absent
- Add explanatory comment clarifying when null maps can occur (e.g. minimal POMs with no plugins section)
- Add test coverage for null pluginManagement and null build plugins map cases
@gnodet
gnodet force-pushed the codex/368-null-plugin-map branch from 3e89015 to e98958c Compare October 9, 2026 09:17
@gnodet
gnodet merged commit 16018a5 into apache:master Oct 9, 2026
@ascheman ascheman modified the milestones: 4.0.0-beta-5, 4.0.0-beta-6 Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working java Pull requests that update Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential NPE in BuildHelper.getPlugin() when getPluginsAsMap() returns null

4 participants