Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,16 @@ public Pom download(GroupArtifactVersion gav,
gav = resolveNamedVersion(gav, containingPom, repositories, ctx);
String versionMaybeDatedSnapshot = datedSnapshotVersion(gav, containingPom, repositories, ctx);
gav = handleSnapshotTimestampVersion(gav);

// If the version still contains unresolved property placeholders (e.g. ${revision}),
// downloading from any repository will never succeed and would cause URISyntaxException
// due to illegal '{' / '}' characters in the constructed URI.
//noinspection DataFlowIssue
Comment thread
timtebeek marked this conversation as resolved.
Outdated
if (gav.getVersion().contains("${")) {
throw new MavenDownloadingException("Unable to download POM " + gav +
". Version contains unresolved property placeholder.", null, originalGav);
Comment on lines +563 to +564
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is called from different paths; now checking how each treats the exception signature change from IllegalArgumentException to MavenDownloadingException:

Image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying a few interesting patterns here:

} catch (MavenDownloadingException | MavenDownloadingExceptions | IllegalArgumentException e) {
return Markup.warn(buildScript, e);

} catch (MavenDownloadingException ignored) {
// If we can't download the POM, we can still just upgrade the dependency version
}
return dependency.withDeclaredVersion(selectedVersion).getTree();

} catch (MavenDownloadingException e) {
throw new RuntimeException(e);


} catch (MavenDownloadingException e) {
document = e.warn(document);

try {
// This is a best effort attempt to see if the pom is there anyway, in spite of the
// fact that it's not in the metadata. Usually it won't be, only in situations like the
// MapR repository mentioned in the comment above will it be.
Pom pom = new MavenPomDownloader(emptyMap(), ctx,
mrr.getMavenSettings(), mrr.getActiveProfiles()).download(new GroupArtifactVersion(groupId, artifactId, ((ExactVersion) versionComparator).getVersion()),
null, null, mrr.getPom().getRepositories());
if (pom.getGav().getVersion().equals(exactVersion) &&
!exactVersion.equals(finalVersion) &&
versionComparator.compare(finalVersion, finalVersion, exactVersion) <= 0) {
return exactVersion;
}
} catch (MavenDownloadingException e) {
return null;

The MavenDownloadingException was nearly always caught & handled (it's a checked exception after all), but the IllegalArgumentException from not being able to construct the URL would have propagated except in rare cases. This change then ensures we're more predictable at runtime for such poms that use ${revision}.

}

Iterable<MavenRepository> normalizedRepos = distinctNormalizedRepositories(repositories, containingPom, gav.getVersion());

Timer.Sample sample = Timer.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ void shouldThrowExceptionForModulesInModulesWithNoRightProperty() {

var downloader = new MavenPomDownloader(pomsByPath, ctx);

assertThrows(IllegalArgumentException.class, () -> downloader.download(gav, Objects.requireNonNull(pom.getParent()).getRelativePath(), resolvedPom, singletonList(nonexistentRepo)));
assertThrows(MavenDownloadingException.class, () -> downloader.download(gav, Objects.requireNonNull(pom.getParent()).getRelativePath(), resolvedPom, singletonList(nonexistentRepo)));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test & assertion on an IllegalArgumentException was explicitly added in

}

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

// With empty relativePath (<relativePath/>), step 3 is skipped entirely.
// Since the parent can't be found by GAV match either, and the remote
// repo doesn't exist, download fails — proving local lookup was skipped.
assertThrows(Exception.class,
// Since the parent can't be found by GAV match either, the version still
// contains an unresolved placeholder, so download throws MavenDownloadingException
// instead of URISyntaxException from URI.create().
assertThrows(MavenDownloadingException.class,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

() -> downloader.download(requestedGav, "", resolvedPom, singletonList(nonexistentRepo)));
}

Expand Down
Loading