openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.3k stars 341 forks source link

Issue discovered with `src/main/java/org/jenkinsci/remoting/overthere/OverthereProcessStub.java` #2148

Closed pway99 closed 2 years ago

pway99 commented 2 years ago

Problem

RenamePrivateFieldsToCamelCase throws NPE

Expected behavior

Describe what you expected to see.

Example diff

class OverthereProcessStub extends DelegatingOverthereProcess implements Serializable {

    * @author Kohsuke Kawaguchi
  */
 class OverthereProcessStub extends DelegatingOverthereProcess implements Serializable {
-    OverthereProcessStub(OverthereProcess base) {
+    OverthereProcessStub(OverthereProcess /*~~(java.lang.NullPointerException: Cannot invoke "org.openrewrite.java.tree.JavaType$Variable.hasFlags(org.openrewrite.java.tree.Flag[])" because the return value of "org.openrewrite.java.tree.J$VariableDeclarations$NamedVariable.getVariableType()" is null
+  org.openrewrite.java.cleanup.RenamePrivateFieldsToCamelCase$RenameNonCompliantNames.visitVariable(RenamePrivateFieldsToCamelCase.java:101)
+  org.openrewrite.java.cleanup.RenamePrivateFieldsToCamelCase$RenameNonCompliantNames.visitVariable(RenamePrivateFieldsToCamelCase.java:76)
+  org.openrewrite.java.tree.J$VariableDeclarations$NamedVariable.acceptJava(J.java:5184)
+  org.openrewrite.java.tree.J.accept(J.java:55)
+  org.openrewrite.TreeVisitor.visit(TreeVisitor.java:206)
+  org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:285)
+  org.openrewrite.java.JavaVisitor.visitRightPadded(JavaVisitor.java:1220)
+  org.openrewrite.java.JavaVisitor.lambda$visitVariableDeclarations$27(JavaVisitor.java:882)
+  ...)~~>*/base) {
         super(base);
     }

Recipes in example diff:

pway99 commented 2 years ago

fixed by: eaf8b030ea6706bfdef2104210a14ec54160754e