Skip to content

Fix NPE in UpgradeDependencyVersion ext property upgrade#7299

Merged
timtebeek merged 1 commit intomainfrom
Jenson3210/fix-pr7231-regression
Apr 7, 2026
Merged

Fix NPE in UpgradeDependencyVersion ext property upgrade#7299
timtebeek merged 1 commit intomainfrom
Jenson3210/fix-pr7231-regression

Conversation

@Jenson3210
Copy link
Copy Markdown
Contributor

@Jenson3210 Jenson3210 commented Apr 7, 2026

Summary

  • Add null guard for selectedVersion in the ext property upgrade path of UpgradeDependencyVersion, fixing NPE when DependencyVersionSelector.select() returns null

Problem

Stack trace from downstream CI:

java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.length()" because "this.text" is null
    at java.util.regex.Pattern.matcher(Pattern.java:1180)
    at org.openrewrite.semver.VersionComparator.checkVersion(VersionComparator.java:60)
    at org.openrewrite.semver.LatestRelease.isValid(LatestRelease.java:36)
    at org.openrewrite.semver.XRange.isValid(XRange.java:51)
    at org.openrewrite.semver.VersionComparator.upgrade(VersionComparator.java:46)
    at org.openrewrite.gradle.UpgradeDependencyVersion$UpdateGradle.lambda$postVisit$2(UpgradeDependencyVersion.java:588)

Fix

Add a null check for selectedVersion before the upgrade check, consistent with the same pattern used elsewhere in the file (e.g., line 480).

Test plan

  • Existing UpgradeDependencyVersionTest.doesNotDowngradeExtPropertyVersion passes
  • All UpgradeDependencyVersionTest tests pass
  • All semver tests pass

… is unresolvable

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.
Copy link
Copy Markdown
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Thanks for the quick fix!

@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Apr 7, 2026
@timtebeek timtebeek merged commit a636e5c into main Apr 7, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Apr 7, 2026
@timtebeek timtebeek deleted the Jenson3210/fix-pr7231-regression branch April 7, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants