diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/errors/ConvertInvalidVarToExplicitArrayType.java b/java/java.hints/src/org/netbeans/modules/java/hints/errors/ConvertInvalidVarToExplicitArrayType.java index 9568817dd75d..2037aab81e88 100644 --- a/java/java.hints/src/org/netbeans/modules/java/hints/errors/ConvertInvalidVarToExplicitArrayType.java +++ b/java/java.hints/src/org/netbeans/modules/java/hints/errors/ConvertInvalidVarToExplicitArrayType.java @@ -20,7 +20,6 @@ import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.NewArrayTree; -import com.sun.source.tree.NewClassTree; import com.sun.source.tree.Tree; import com.sun.source.util.TreePath; import java.util.Collections; @@ -35,6 +34,7 @@ import org.netbeans.api.java.source.CompilationInfo; import org.netbeans.api.java.source.JavaSource; import org.netbeans.api.java.source.TreeMaker; +import org.netbeans.api.java.source.TypeMirrorHandle; import org.netbeans.api.java.source.WorkingCopy; import org.netbeans.modules.java.hints.spi.ErrorRule; import org.netbeans.spi.editor.hints.Fix; @@ -134,11 +134,11 @@ public void cancel() { private static final class FixImpl extends JavaFix { - private TypeMirror arrayTypeMirror; + private final TypeMirrorHandle arrayTypeMirror; public FixImpl(CompilationInfo info, TreePath tp, TypeMirror arrayType) { super(info, tp); - this.arrayTypeMirror = arrayType; + this.arrayTypeMirror = TypeMirrorHandle.create(arrayType); } @Override @@ -157,12 +157,18 @@ protected void performRewrite(TransformationContext tc) throws Exception { if (statementPath.getLeaf().getKind() == Tree.Kind.VARIABLE) { oldVariableTree = (VariableTree) statementPath.getLeaf(); - arrayTypeMirror = Utilities.resolveCapturedType(wc, arrayTypeMirror); + TypeMirror arrayType = arrayTypeMirror.resolve(wc); + + if (arrayType == null) { + return ; //cannot resolve + } + + arrayType = Utilities.resolveCapturedType(wc, arrayType); VariableTree newVariableTree = make.Variable( oldVariableTree.getModifiers(), oldVariableTree.getName(), - make.ArrayType(make.Type(arrayTypeMirror)), + make.ArrayType(make.Type(arrayType)), oldVariableTree.getInitializer() ); tc.getWorkingCopy().rewrite(oldVariableTree, newVariableTree);