[MNG-8736] Fix concurrency issue in model building with profile activation by gnodet · Pull Request #2378 · apache/maven (original) (raw)

@gnodet

This commit addresses multiple critical issues in the profile activation context recording and caching mechanism during model inheritance:

Issues Fixed:

  1. Profile Activation Context Recording Bug: When there was a cache hit in readAsParentModel(), the keys accessed during cache matching re-evaluation were lost because the recording context was discarded without merging the recorded keys into the parent context.

  2. Recording Context Isolation: Parent model processing was polluting the child's recording context with intermediate keys that weren't essential to the final result, leading to noisy cache keys and reduced cache effectiveness.

  3. Profile Injection Precedence: Profile properties from distant ancestors were incorrectly overriding direct properties from closer ancestors due to improper profile injection timing during inheritance assembly.

Solutions Implemented:

  1. Cache Hit Recording Fix:

    • Create a separate recording context for cache matching re-evaluation
    • Replay cached record keys into the parent recording context on cache hits
    • Ensure all essential keys are captured regardless of cache hit/miss
  2. Recording Context Isolation:

    • Use separate recording contexts for parent model processing
    • Only replay essential keys from the final result into parent context
    • Maintain clean, precise cache keys for better performance
  3. Profile Injection Timing:

    • Inject profiles into child models using parent's profile list
    • Ensure proper precedence where child elements override parent elements
    • Maintain correct inheritance hierarchy during profile activation

Technical Details:

Benefits:

This fix ensures that profile activation behaves consistently and correctly in both single-threaded and multi-threaded environments, while maintaining optimal performance through improved caching mechanisms.