Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83f3cde

Browse files
Jenson3210Jente Sondervorst
andauthored
Ignore method invocation arguments that are not string J.Literals (openrewrite#4276)
Fixes: openrewrite#4275 Co-authored-by: Jente Sondervorst <[email protected]>
1 parent 22ac272 commit 83f3cde

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ private J.MethodInvocation updateDependency(J.MethodInvocation method, Execution
435435
}
436436
} else if (arg instanceof J.Literal) {
437437
J.Literal literal = (J.Literal) arg;
438+
if (literal.getType() != JavaType.Primitive.String) {
439+
return arg;
440+
}
438441
String gav = (String) literal.getValue();
439442
if (gav == null) {
440443
getCursor().putMessage(UPDATE_VERSION_ERROR_KEY, new IllegalStateException("Unable to update version"));

rewrite-gradle/src/test/java/org/openrewrite/gradle/UpgradeDependencyVersionTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,4 +882,29 @@ void unknownConfiguration() {
882882
)
883883
);
884884
}
885+
886+
@Test
887+
@Issue("https://github.com/openrewrite/rewrite/issues/4275")
888+
void noActionForNonStringLiterals() {
889+
rewriteRun(
890+
buildGradle(
891+
"""
892+
plugins {
893+
id 'java'
894+
}
895+
896+
repositories {
897+
mavenCentral()
898+
}
899+
900+
dependencies {
901+
implementation(gradleApi())
902+
jar {
903+
enabled(true)
904+
}
905+
}
906+
"""
907+
)
908+
);
909+
}
885910
}

0 commit comments

Comments
 (0)