Skip to content

Commit 5b7b4a4

Browse files
committed
Fix potential NPE in UseVarForObject
1 parent 8317853 commit 5b7b4a4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/main/java/org/openrewrite/java/migrate/lang/var/UseVarForObject.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.openrewrite.java.search.UsesJavaVersion;
2828
import org.openrewrite.java.tree.Expression;
2929
import org.openrewrite.java.tree.J;
30+
import org.openrewrite.java.tree.TypeTree;
3031

3132
@Value
3233
@EqualsAndHashCode(callSuper = false)
@@ -87,8 +88,9 @@ private J.VariableDeclarations transformToVar(J.VariableDeclarations vd) {
8788
J.VariableDeclarations result = template.<J.VariableDeclarations>apply(getCursor(), vd.getCoordinates().replace(), simpleName, initializer)
8889
.withModifiers(vd.getModifiers())
8990
.withPrefix(vd.getPrefix());
91+
TypeTree typeExpression = result.getTypeExpression();
9092
//noinspection DataFlowIssue
91-
return result.withTypeExpression(result.getTypeExpression().withPrefix(vd.getTypeExpression().getPrefix()));
93+
return typeExpression != null ? result.withTypeExpression(typeExpression.withPrefix(vd.getTypeExpression().getPrefix())) : vd;
9294
}
9395
}
9496
}

0 commit comments

Comments
 (0)