Skip to content

fix: keep all profile activation keys in the cache, including inactive ones - #12728

Open
waterWang wants to merge 1 commit into
apache:masterfrom
waterWang:master
Open

fix: keep all profile activation keys in the cache, including inactive ones#12728
waterWang wants to merge 1 commit into
apache:masterfrom
waterWang:master

Conversation

@waterWang

Copy link
Copy Markdown

Problem

DefaultProfileActivationContext.stop() filters out false-valued entries from usedActiveProfiles and usedInactiveProfiles before freezing the Record. This means a parent POM assembled without -Prelease stores an empty map (usedActiveProfiles = {}), which matches ANY context — including one where -Prelease is active. The poisoned cache entry is then shared by every reactor module, causing profile-injected content (plugin executions, properties, dependencies) to silently vanish from a subset of modules.

Root cause: the cache key is too narrow — it only records profiles that were active, not profiles that were consulted but found inactive.

Fix

Remove the two removeIf filters so every consulted profile key is retained, regardless of whether it evaluated to true or false. The Record.matches() method already correctly verifies keys it holds, so a false-valued entry correctly prevents a mis-match.

Test

Added ParentProfileCacheTest with two assertions that fail on the unpatched code and pass with the fix:

  • A parent assembled without -Prelease must not be reused for a module built with -Prelease
  • A parent assembled without -!release must not be reused for a module built with -!release

References

Full root-cause analysis: #12724

…e ones

DefaultProfileActivationContext.stop() was filtering out
false-valued entries from usedActiveProfiles and
usedInactiveProfiles before freezing the Record. This meant a
parent assembled without -Prelease stored an empty map
(usedActiveProfiles = {}), which matches ANY context —
including one where -Prelease is active. The poisoned cache
entry was then shared by every reactor module, causing
profile-injected content (plugin executions, properties,
dependencies) to silently vanish from a subset of modules.

Fix: remove the two removeIf filters so every consulted
profile key is retained, regardless of whether it evaluated
to true or false. The Record.matches() method already
correctly verifies keys it holds, so a false-valued entry
correctly prevents a mis-match.

Fixes apache#12724

See apache#12724 for full
root-cause analysis and test case.

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Correct, minimal fix for a real cache-key bug in profile activation context. The removeIf calls in stop() were stripping false entries from the activation maps, causing empty maps that matched any context via allMatch — letting matchesProfiles incorrectly treat contexts where a profile was consulted but inactive as equivalent to contexts where the profile was never seen.

The fix (removing those two removeIf lines) is clean and well-targeted, and the new test directly validates the cache-key distinction.

Minor nit: Missing trailing newline at end of ParentProfileCacheTest.java.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of gnodet

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.

2 participants