Skip to content

Commit

Permalink
Fix StackOverflowError in MavenPomDownloader (#3801)
Browse files Browse the repository at this point in the history
When building gridgain/gridgain@main there is a `StackOverflowError` because the root project references `parent/pom.xml` as its parent and the latter contains `<relativePath/>`. But that actually means that Maven should *not* look for the parent in the current project.
  • Loading branch information
knutwannheden authored Dec 9, 2023
1 parent d0d73e6 commit ecfe291
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ private Pom getParentWithinProject(Pom projectPom, Map<Path, Pom> projectPoms) {
.resolve("..")
.resolve(Paths.get(relativePath))
.normalize();
return projectPoms.get(parentPath);
Pom parentPom = projectPoms.get(parentPath);
return parentPom != null && parentPom.getGav().getGroupId().equals(parent.getGav().getGroupId()) &&
parentPom.getGav().getArtifactId().equals(parent.getGav().getArtifactId()) ? parentPom : null;
}

public MavenMetadata downloadMetadata(GroupArtifact groupArtifact, @Nullable ResolvedPom containingPom, List<MavenRepository> repositories) throws MavenDownloadingException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,44 @@ void recursivePropertyFromParentPoms() {
);
}

@Test
void nestedParentWithDownloadedParent() {
rewriteRun(
mavenProject("root",
pomXml(
"""
<project>
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
<version>16</version>
<relativePath/>
</parent>
<groupId>org.openrewrite.maven</groupId>
<artifactId>parent</artifactId>
<version>0.1.0-SNAPSHOT</version>
</project>
""",
spec -> spec.path("parent/pom.xml")
),
pomXml(
"""
<project>
<parent>
<groupId>org.openrewrite.maven</groupId>
<artifactId>parent</artifactId>
<version>0.1.0-SNAPSHOT</version>
<relativePath>parent/pom.xml</relativePath>
</parent>
<artifactId>root</artifactId>
</project>
""",
spec -> spec.path("pom.xml")
)
)
);
}

// a depends on d without specifying version number. a's parent is b
// b imports c into its dependencyManagement section
// c's dependencyManagement specifies the version of d to use
Expand Down

0 comments on commit ecfe291

Please sign in to comment.