Skip to content

Commit a636e5c

Browse files
authored
Fix NPE in UpgradeDependencyVersion ext property upgrade when version is unresolvable (#7299)
DependencyVersionSelector.select() can return null when no matching version is found. The downgrade prevention code added in #7290 passes this null into versionComparator.upgrade() via singletonList(selectedVersion), which then calls RELEASE_PATTERN.matcher(null) and throws NullPointerException. Add a null guard consistent with the pattern used elsewhere in the same file (e.g., line 480). Fixes downstream failure in moderneinc/rewrite-spring.
1 parent 18df73f commit a636e5c

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

rewrite-gradle/src/main/java/org/openrewrite/gradle/UpgradeDependencyVersion.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,9 @@ public J postVisit(J tree, ExecutionContext ctx) {
583583
}
584584
selectedVersion = dependencyVersionSelector.select(ga, "classpath", newVersion, versionPattern, execCtx);
585585
}
586+
if (selectedVersion == null) {
587+
return prop.getTree();
588+
}
586589
VersionComparator versionComparator = getVersionComparator();
587590
if (versionComparator != null) {
588591
Optional<String> finalVersion = versionComparator.upgrade(prop.getValue(), singletonList(selectedVersion));

0 commit comments

Comments
 (0)