Skip to content

Commit 293946e

Browse files
committed
Avoid traversal when newVersion or compartor is null
1 parent 23af75d commit 293946e

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

rewrite-maven/src/main/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactId.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,25 @@ public Accumulator getInitialValue(ExecutionContext ctx) {
151151

152152
@Override
153153
public TreeVisitor<?, ExecutionContext> getScanner(Accumulator acc) {
154+
if (newVersion == null) {
155+
return TreeVisitor.noop();
156+
}
157+
final VersionComparator versionComparator = Semver.validate(newVersion, versionPattern).getValue();
158+
if (versionComparator == null) {
159+
return TreeVisitor.noop();
160+
}
154161
return new MavenIsoVisitor<ExecutionContext>() {
155-
final @Nullable VersionComparator versionComparator = newVersion != null ? Semver.validate(newVersion, versionPattern).getValue() : null;
156162
final boolean configuredToChangeManagedDependency = changeManagedDependency == null || changeManagedDependency;
157163

158164
@Override
159165
public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) {
160-
if (!isDependencyTag(oldGroupId, oldArtifactId) && !isPluginDependencyTag(oldGroupId, oldArtifactId) && !isAnnotationProcessorPathTag(oldGroupId, oldArtifactId)) {
161-
return super.visitTag(tag, ctx);
162-
}
163-
if (newVersion == null || versionComparator == null) {
166+
if (!isDependencyTag(oldGroupId, oldArtifactId) &&
167+
!isPluginDependencyTag(oldGroupId, oldArtifactId) &&
168+
!isAnnotationProcessorPathTag(oldGroupId, oldArtifactId)) {
164169
return super.visitTag(tag, ctx);
165170
}
166171
String currentVersion = tag.getChildValue("version").orElse(null);
167-
if (currentVersion == null || !isProperty(currentVersion)) {
172+
if (!isProperty(currentVersion)) {
168173
return super.visitTag(tag, ctx);
169174
}
170175
String propertyName = currentVersion.substring(2, currentVersion.length() - 1);

rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactIdTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,7 +2356,7 @@ void changeVersionPropertyInParentPomSimple() {
23562356
<artifactId>parent-project</artifactId>
23572357
<version>1</version>
23582358
<properties>
2359-
<version.swagger>2.2.42</version.swagger>
2359+
<version.swagger>2.2.43</version.swagger>
23602360
</properties>
23612361
<modules>
23622362
<module>sub-project</module>
@@ -2493,7 +2493,7 @@ void sharedPropertyInParentPomLeavesPropertyUnchangedAndInlinesVersion() {
24932493
<dependency>
24942494
<groupId>io.swagger.core.v3</groupId>
24952495
<artifactId>swagger-annotations</artifactId>
2496-
<version>2.2.42</version>
2496+
<version>2.2.43</version>
24972497
</dependency>
24982498
<dependency>
24992499
<groupId>io.swagger</groupId>
@@ -2583,7 +2583,7 @@ void sharedPropertyInParentPomUsedByDifferentChildrenLeavesPropertyUnchanged() {
25832583
<dependency>
25842584
<groupId>io.swagger.core.v3</groupId>
25852585
<artifactId>swagger-annotations</artifactId>
2586-
<version>2.2.42</version>
2586+
<version>2.2.43</version>
25872587
</dependency>
25882588
</dependencies>
25892589
</project>
@@ -2678,7 +2678,7 @@ void childRedefinesPropertyUsedNonConflictinglyInlinesVersionInParent() {
26782678
<dependency>
26792679
<groupId>io.swagger.core.v3</groupId>
26802680
<artifactId>swagger-annotations</artifactId>
2681-
<version>2.2.42</version>
2681+
<version>2.2.43</version>
26822682
</dependency>
26832683
</dependencies>
26842684
</project>
@@ -2913,7 +2913,7 @@ void handlesGlobCorrectly() {
29132913
"swagger-*",
29142914
"io.swagger.core.v3",
29152915
null,
2916-
"2.2.42",
2916+
"2.2.43",
29172917
null
29182918
)),
29192919
//language=xml
@@ -2951,7 +2951,7 @@ void handlesGlobCorrectly() {
29512951
<artifactId>demo-child</artifactId>
29522952
<version>0.0.1-SNAPSHOT</version>
29532953
<properties>
2954-
<version.swagger>2.2.42</version.swagger>
2954+
<version.swagger>2.2.43</version.swagger>
29552955
</properties>
29562956
<dependencies>
29572957
<dependency>

0 commit comments

Comments
 (0)