Honor empty <relativePath/> in MavenPomDownloader#6875
Merged
Jenson3210 merged 4 commits intoopenrewrite:mainfrom Mar 5, 2026
Merged
Honor empty <relativePath/> in MavenPomDownloader#6875Jenson3210 merged 4 commits intoopenrewrite:mainfrom
Jenson3210 merged 4 commits intoopenrewrite:mainfrom
Conversation
When a POM declares `<relativePath/>` (empty self-closing tag), Maven skips local parent lookup entirely and goes straight to remote repositories. OpenRewrite's MavenPomDownloader was treating this the same as an omitted `<relativePath>` (which defaults to `../pom.xml`) because both `null` and `""` pass through `StringUtils.isBlank()`. This fix distinguishes between: - `null` (element absent) → default to `../pom.xml` - `""` (explicit empty element) → skip local parent lookup - non-blank string → use that path Affects both `getParentWithinProject()` and the relative-path block in `download()`. Fixes moderneinc/customer-requests#1950
Contributor
Author
|
@MBoegers I could use your recent investigations to get bit more insights on this one. |
…eholder versions
The existing emptyRelativePathSkipsLocalParentLookup test has a gap: the
parent is found via GAV iteration (stage 2) before the path-based lookup
(stage 3) is ever reached, so it passes with or without the fix.
This new test uses a placeholder version ${my.version} that can't be
resolved in stage 2 (the property isn't defined). Without the fix,
stage 3 would default the empty relativePath to ".." and find the parent
locally (the "${" in the version relaxes the version check). With the
fix, stage 3 is correctly skipped and the download falls through to the
remote repo.
Contributor
|
Added another test: The test exercises these steps through
The |
MBoegers
approved these changes
Mar 5, 2026
Contributor
MBoegers
left a comment
There was a problem hiding this comment.
LGTM with the additional test we should have both tracks covered
The previous test passed because the parent was found by GAV match
(step 1 in download()), making the relativePath irrelevant. The new
test uses a placeholder version ${revision} that can only be resolved
via relativePath-based local lookup (step 3), proving that
<relativePath/> correctly skips that step.
…dy covers it The emptyRelativePathSkipsPathBasedLookupWithPlaceholderVersion test uses the same placeholder-version approach and is a subset of the emptyRelativePathSkipsLocalParentLookup test, which additionally verifies that null relativePath DOES find the parent locally.
timtebeek
approved these changes
Mar 5, 2026
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.
Summary
<relativePath>(defaults to../pom.xml) and explicit empty<relativePath/>(skip local parent lookup) inMavenPomDownloadergetParentWithinProject()and the relative-path resolution block indownload()Problem
When a POM declares
<relativePath/>(empty self-closing tag), Maven skips local parent lookup entirely and goes straight to remote repositories (DefaultModelBuilder.java#L1048). OpenRewrite'sMavenPomDownloaderwas treating emptyrelativePaththe same as omitted because bothnulland""pass throughStringUtils.isBlank(), causing it to default to../pom.xmlin both cases.Solution
Check for empty string explicitly before the
isBlankfallback:null(element absent) → default to../pom.xml""(explicit empty<relativePath/>) → skip local parent lookupTest plan
Existing tests pass (
MavenPomDownloaderTest,MavenParserTest,ChangeParentPomTest,ResolvedPomTest)New test
emptyRelativePathSkipsLocalParentLookupverifies the fixFixes moderneinc/customer-requests#1950