Extend re-entrancy detection for broken trace chains#2009
Conversation
…naged dependency validation The trace-based re-entrancy detection added in PR #1957 does not cover all code paths. Maven 4's RequestTraceHelper converts between Maven API traces and resolver RequestTrace objects, creating a fresh trace chain that loses the REPOSITORY_SYSTEM_CALL marker. This causes MavenValidator to reject re-entrant calls that carry uninterpolated property expressions. This commit addresses the gap with two complementary fixes: 1. Session-scoped re-entrancy detection: Each public RepositorySystem method now maintains a depth counter in SessionData via enterSessionScope()/ exitSessionScope(). When the counter is > 0 on entry, the call is detected as re-entrant regardless of whether the RequestTrace chain carries the marker. This catches cases where consumers rebuild the trace chain from a different tracing system. 2. Skip managed dependency validation in validateCollectRequest(): Managed dependencies are declarative constraints that only take effect when a matching dependency is encountered during collection. Validating them eagerly rejects valid builds where a BOM imports managed dependencies with uninterpolated property expressions (e.g. ${osgi.version}) that are never actually used. If a managed dependency IS matched and its coordinates are invalid, the error surfaces during version/artifact resolution. Together, these changes allow Maven PR #12481 to remove the consumer-side workarounds for uninterpolated expressions in DefaultArtifactDescriptorReader, ArtifactDescriptorReaderDelegate, DefaultProjectDependenciesResolver, and DefaultDependencyResolver. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
See #2008 MavenValidator should just not implement new method. But in some other, non-Maven use cases, uninterpolated depMgt may be seen as error. |
Revert the managed dependency validation removal from DefaultRepositorySystemValidator. As cstamas noted, managed deps should remain validatable for non-Maven use cases — the proper separation between direct and managed dependency validation belongs in PR #2008 (validateManagedDependency method). This PR now focuses solely on session-scoped re-entrancy detection via an AtomicInteger depth counter in session data, which covers the broken trace chain scenario independently. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks for the feedback @cstamas! You're right — removing managed dependency validation entirely is too broad. I've reverted the managed dependency validation changes in 7400592. This PR now focuses solely on session-scoped re-entrancy detection (the The managed dependency separation (direct vs managed validation) is better handled by #2008's |
Summary
The trace-based re-entrancy detection added in PR #1957 does not fully cover all code paths. Specifically, Maven 4's
RequestTraceHelperconverts between Maven API traces and resolverRequestTraceobjects viatoResolver(), creating a fresh trace chain that loses theREPOSITORY_SYSTEM_CALLmarker. This causesMavenValidatorto reject the collect request in theMavenITgh12305integration test (PR apache/maven#12481) withInvalid Collect Request: null -> [].This PR addresses the gap with two complementary fixes:
Session-scoped re-entrancy detection (
DefaultRepositorySystem): Each public method now maintains a depth counter inSessionDataviaenterSessionScope()/try-finally decrement. When the counter is > 0 on entry, the call is detected as re-entrant regardless of whether theRequestTracechain carries the marker. This catches cases where consumers rebuild the trace chain from a different tracing system.Skip managed dependency validation (
DefaultRepositorySystemValidator): Managed dependencies are declarative constraints that only take effect when a matching dependency is encountered during collection. Validating them eagerly rejects valid builds where a BOM imports managed deps with uninterpolated expressions (e.g.${osgi.version}) that are never actually used. If a managed dependency IS matched and its coordinates are invalid, the error surfaces naturally during version/artifact resolution.Together these changes allow apache/maven#12481 to remove the consumer-side workarounds for uninterpolated expressions.
Context
Test plan
sessionScopedDetectionSkipsValidationWhenTraceChainIsBroken— verifies inner calls with broken trace + uninterpolated expressions succeed via session-scoped detectioncollectDependenciesAcceptsManagedDepsWithUninterpolatedExpressions— reproduces the MavenITgh12305 scenariocollectDependenciesStillRejectsInvalidDirectDependencies— ensures direct deps are still validatedsessionScopedDepthIsProperlyDecrementedOnExit— verifies counter cleanup for independent calls🤖 Generated with Claude Code