-
Notifications
You must be signed in to change notification settings - Fork 97
Description
What version of OpenRewrite are you using?
I am using
- rewrite-maven-plugin 6.2.0-SNAPSHOT
- rewrite-migrate-java 3.3.0-SNAPSHOT
- Maven 3.9.9
- Java 21
- Intellij 2024.3.2.2
- Win 11
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a single module project.
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>6.2.0-SNAPSHOT</version>
<configuration>
<exportDatatables>true</exportDatatables>
<configLocation>upstep.yaml</configLocation>
<activeRecipes>
<recipe>org.openrewrite.java.migrate.joda.JodaTimeRecipe</recipe>
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-migrate-java</artifactId>
<version>3.3.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
What is the smallest, simplest way to reproduce the problem?
All started from throwing NullPointerException.
[ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:6.0.4:run (default-cli) on project ***: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:6.0.4:run failed: Error while visiting ***\***.java: java.lang.NullPointerException: Cannot invoke "org.openrewrite.java.tree.JavaType$Method.getDeclaringType()" because the return value of "org.openrewrite.java.tree.J$MethodInvocation.getMethodType()" is null
[ERROR] org.openrewrite.java.migrate.joda.JodaTimeVisitor.visitMethodInvocation(JodaTimeVisitor.java:168)
[ERROR] org.openrewrite.java.migrate.joda.JodaTimeVisitor.visitMethodInvocation(JodaTimeVisitor.java:36)
[ERROR] org.openrewrite.java.tree.J$MethodInvocation.acceptJava(J.java:3982)
[ERROR] org.openrewrite.java.tree.J.accept(J.java:59)
[ERROR] org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250)
[ERROR] org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:320)
[ERROR] org.openrewrite.java.JavaVisitor.visitLeftPadded(JavaVisitor.java:1396)
[ERROR] org.openrewrite.java.JavaVisitor.visitVariable(JavaVisitor.java:1302)
[ERROR] org.openrewrite.java.migrate.joda.JodaTimeVisitor.visitVariable(JodaTimeVisitor.java:121)
[ERROR] org.openrewrite.java.migrate.joda.JodaTimeVisitor.visitVariable(JodaTimeVisitor.java:36)
[ERROR] org.openrewrite.java.tree.J$VariableDeclarations$NamedVariable.acceptJava(J.java:5978)
[ERROR] org.openrewrite.java.tree.J.accept(J.java:59)
[ERROR] org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250)
[ERROR] org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:320)
[ERROR] org.openrewrite.java.JavaVisitor.visitRightPadded(JavaVisitor.java:1368)
[ERROR] org.openrewrite.java.JavaVisitor.lambda$visitVariableDeclarations$27(JavaVisitor.java:962)
This was fixed by 2 commits from Tim te Beek
fix 1
fix 2
And one similar by me in another method I made locally.
After those changes, I was able to run the plugin without error. But it is also doing nothing.
The reason is that for all J.VariableDeclarations.NamedVariable
getType
is null
But J.VariableDeclarations
contain type. In typeExpression field.
And it is like this from the beginning of my stack trace
I made a quick test (sorry for the dirty code) and tried to add type manually in org.openrewrite.java.migrate.joda.JodaTimeScanner#visitCompilationUnit
@Override
public J visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) {
cu.getClasses().forEach(c -> {
c.getBody().getStatements().forEach(s -> {
if (!(s instanceof J.VariableDeclarations)) return;
J.VariableDeclarations variable = (J.VariableDeclarations)s;
if(variable.getType() == null) return;
variable.getVariables().set(0, variable.getVariables().get(0).withType(variable.getType()));
});
}
);
...rest of the method code
With no luck.
I was not able to use method org.openrewrite.java.tree.J.VariableDeclarations.NamedVariable#withType
The result of variable.getVariables().get(0).withType(variable.getType())
is still contain type null
Please help me to make it work. We have 2000 files to migrate. :)
I will attach some screens from my debugging.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status