Skip to content

Commit 233a70f

Browse files
authored
Merge pull request #9042 from lahodaj/stabilize-ConvertInvalidVarToExplicitArrayType
Hint/test stabilization: cannot keep TypeMirrors across javac context invocations.
2 parents 71f18a1 + f90a8ce commit 233a70f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

java/java.hints/src/org/netbeans/modules/java/hints/errors/ConvertInvalidVarToExplicitArrayType.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import com.sun.source.tree.ExpressionTree;
2222
import com.sun.source.tree.NewArrayTree;
23-
import com.sun.source.tree.NewClassTree;
2423
import com.sun.source.tree.Tree;
2524
import com.sun.source.util.TreePath;
2625
import java.util.Collections;
@@ -35,6 +34,7 @@
3534
import org.netbeans.api.java.source.CompilationInfo;
3635
import org.netbeans.api.java.source.JavaSource;
3736
import org.netbeans.api.java.source.TreeMaker;
37+
import org.netbeans.api.java.source.TypeMirrorHandle;
3838
import org.netbeans.api.java.source.WorkingCopy;
3939
import org.netbeans.modules.java.hints.spi.ErrorRule;
4040
import org.netbeans.spi.editor.hints.Fix;
@@ -134,11 +134,11 @@ public void cancel() {
134134

135135
private static final class FixImpl extends JavaFix {
136136

137-
private TypeMirror arrayTypeMirror;
137+
private final TypeMirrorHandle arrayTypeMirror;
138138

139139
public FixImpl(CompilationInfo info, TreePath tp, TypeMirror arrayType) {
140140
super(info, tp);
141-
this.arrayTypeMirror = arrayType;
141+
this.arrayTypeMirror = TypeMirrorHandle.create(arrayType);
142142
}
143143

144144
@Override
@@ -157,12 +157,18 @@ protected void performRewrite(TransformationContext tc) throws Exception {
157157
if (statementPath.getLeaf().getKind() == Tree.Kind.VARIABLE) {
158158
oldVariableTree = (VariableTree) statementPath.getLeaf();
159159

160-
arrayTypeMirror = Utilities.resolveCapturedType(wc, arrayTypeMirror);
160+
TypeMirror arrayType = arrayTypeMirror.resolve(wc);
161+
162+
if (arrayType == null) {
163+
return ; //cannot resolve
164+
}
165+
166+
arrayType = Utilities.resolveCapturedType(wc, arrayType);
161167

162168
VariableTree newVariableTree = make.Variable(
163169
oldVariableTree.getModifiers(),
164170
oldVariableTree.getName(),
165-
make.ArrayType(make.Type(arrayTypeMirror)),
171+
make.ArrayType(make.Type(arrayType)),
166172
oldVariableTree.getInitializer()
167173
);
168174
tc.getWorkingCopy().rewrite(oldVariableTree, newVariableTree);

0 commit comments

Comments
 (0)