Skip to content

Fix NPE in ChangeDependencyGroupIdAndArtifactId for POMs without dependencyManagement#7374

Merged
MBoegers merged 1 commit intomainfrom
MBoegers/fix-depmgmt-npe
Apr 14, 2026
Merged

Fix NPE in ChangeDependencyGroupIdAndArtifactId for POMs without dependencyManagement#7374
MBoegers merged 1 commit intomainfrom
MBoegers/fix-depmgmt-npe

Conversation

@MBoegers
Copy link
Copy Markdown
Contributor

Summary

  • Pom fields use @Builder.Default to initialize list fields to emptyList(), but deserialization can bypass the builder and leave them null
  • ChangeDependencyGroupIdAndArtifactId crashes with NPE when run against a POM that has no <dependencyManagement> section
  • Added null guards with early returns in three locations:
    • MavenDependencyPropertyUsageOverlap.filterPropertiesWithOverlapInDependencies() — guards both getDependencyManagement() and getDependencies()
    • Both getSafeVersionPlaceholdersToChange() methods in ChangeDependencyGroupIdAndArtifactId — guards getDependencies()

Test plan

  • Added noDependencyManagementSection() test that runs ChangeDependencyGroupIdAndArtifactId on a POM with no <dependencyManagement> section
  • Existing tests pass: ./gradlew :rewrite-maven:test --tests "*ChangeDependencyGroupIdAndArtifactId*"

…dencyManagement

Pom fields use @Builder.Default to initialize to emptyList(), but
deserialization can bypass the builder and leave them null. Guard
against null getDependencyManagement() and getDependencies() in
MavenDependencyPropertyUsageOverlap and both getSafeVersionPlaceholdersToChange
methods in ChangeDependencyGroupIdAndArtifactId.
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Apr 14, 2026
@MBoegers MBoegers self-assigned this Apr 14, 2026
@MBoegers MBoegers merged commit 56b250b into main Apr 14, 2026
1 check passed
@MBoegers MBoegers deleted the MBoegers/fix-depmgmt-npe branch April 14, 2026 18:00
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Apr 14, 2026
@MBoegers
Copy link
Copy Markdown
Contributor Author

merging this after in person discussion with tim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant