fix(java): don't inherit a relativePath POM that only matches the parent ArtifactID - #11059
Open
sueun-dev wants to merge 1 commit into
Open
fix(java): don't inherit a relativePath POM that only matches the parent ArtifactID#11059sueun-dev wants to merge 1 commit into
sueun-dev wants to merge 1 commit into
Conversation
…nt's ArtifactID tryRelativePath first matches the parent's ArtifactID before resolveParent runs (GroupID/Version aren't available yet), then re-checks the full identity afterwards. That second check used artifact.Equal, which compared the GAV fields with OR, so it returned true whenever any single field matched. Since the ArtifactID always matches at that point, the check could never reject a POM, and a ../pom.xml (or relativePath) that merely shares the ArtifactID but has a different GroupID was treated as the parent, inheriting its dependencies and dependencyManagement into the SBOM graph. Compare the GroupID (now resolved) instead. The declared parent Version can still be an unevaluated property at this point, so it is left out of the comparison. Removed the now-unused, misleading artifact.Equal helper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
tryRelativePathresolves a<parent>declared with arelativePath(or the default../pom.xml). It first matches the local POM's ArtifactID against the declared parent, becauseresolveParenthasn't run yet and the GroupID/Version aren't available. AfterresolveParentfills those in, it re-checks the identity withartifact.Equal:The fields are combined with
||, soEqualreturns true whenever any single field matches. The ArtifactID is already guaranteed equal by the first check, so the second check can never reject anything. A../pom.xml(or relativePath target) that shares the ArtifactID but has a different GroupID is then treated as the parent, and itsdependencies/dependencyManagementare inherited — dependencies that aren't really there end up in the SBOM graph.Example: a module declares parent
com.example:parent:1.0.0, but the sibling./parent/pom.xmlis an unrelatedcom.unrelated:parent:9.9.9that depends onorg.phantom:phantom-lib:6.6.6. Before this changephantom-libis reported as a dependency of the module; after it isn't.This compares the resolved GroupID at that call site instead. The declared parent Version can still be an unevaluated property (e.g.
${revision}) there, so comparing it would reject valid parents — theparent version in propertyandinherit parent dependenciestests exercise exactly that — and it is left out. The now-unusedartifact.Equalhelper is removed.Checklist