Skip to content

Commit 83bd388

Browse files
authored
Fix URISyntaxException in MavenPomDownloader for unresolved version placeholders (#7313)
* Fix URISyntaxException in MavenPomDownloader for unresolved property placeholders When a parent POM version contains unresolved placeholders like ${revision} and the parent isn't found locally, the download method would construct a URI with illegal { } characters, causing URISyntaxException. Added an early check to throw MavenDownloadingException instead, which callers already handle gracefully by falling through to property resolution. * Apply suggestion from @timtebeek
1 parent b0f88bc commit 83bd388

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

rewrite-maven/src/main/java/org/openrewrite/maven/internal/MavenPomDownloader.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,12 @@ public Pom download(GroupArtifactVersion gav,
558558
gav = resolveNamedVersion(gav, containingPom, repositories, ctx);
559559
String versionMaybeDatedSnapshot = datedSnapshotVersion(gav, containingPom, repositories, ctx);
560560
gav = handleSnapshotTimestampVersion(gav);
561+
562+
if (gav.getVersion().contains("${")) {
563+
throw new MavenDownloadingException("Unable to download POM " + gav +
564+
". Version contains unresolved property placeholder.", null, originalGav);
565+
}
566+
561567
Iterable<MavenRepository> normalizedRepos = distinctNormalizedRepositories(repositories, containingPom, gav.getVersion());
562568

563569
Timer.Sample sample = Timer.start();

rewrite-maven/src/test/java/org/openrewrite/maven/internal/MavenPomDownloaderTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ void shouldThrowExceptionForModulesInModulesWithNoRightProperty() {
11081108

11091109
var downloader = new MavenPomDownloader(pomsByPath, ctx);
11101110

1111-
assertThrows(IllegalArgumentException.class, () -> downloader.download(gav, Objects.requireNonNull(pom.getParent()).getRelativePath(), resolvedPom, singletonList(nonexistentRepo)));
1111+
assertThrows(MavenDownloadingException.class, () -> downloader.download(gav, Objects.requireNonNull(pom.getParent()).getRelativePath(), resolvedPom, singletonList(nonexistentRepo)));
11121112
}
11131113

11141114
@Test
@@ -1197,9 +1197,10 @@ void emptyRelativePathSkipsLocalParentLookup() {
11971197
assertDoesNotThrow(() -> downloader.download(requestedGav, null, resolvedPom, singletonList(nonexistentRepo)));
11981198

11991199
// With empty relativePath (<relativePath/>), step 3 is skipped entirely.
1200-
// Since the parent can't be found by GAV match either, and the remote
1201-
// repo doesn't exist, download fails — proving local lookup was skipped.
1202-
assertThrows(Exception.class,
1200+
// Since the parent can't be found by GAV match either, the version still
1201+
// contains an unresolved placeholder, so download throws MavenDownloadingException
1202+
// instead of URISyntaxException from URI.create().
1203+
assertThrows(MavenDownloadingException.class,
12031204
() -> downloader.download(requestedGav, "", resolvedPom, singletonList(nonexistentRepo)));
12041205
}
12051206

0 commit comments

Comments
 (0)