Skip to content

Commit e859e0c

Browse files
NPE: Cannot invoke org.eclipse.jdt.internal.compiler.lookup.TypeBinding.isAnonymousType() because binding.type is null" on hyperlink request (#4221)
* Fixes #4216
1 parent e4fcda2 commit e859e0c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests10.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,30 @@ public void testBug562382() throws CoreException {
152152
assertEquals(1, selected.length);
153153
assertEquals("Number", selected[0].getElementName());
154154
}
155+
156+
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4216
157+
// NPE: Cannot invoke org.eclipse.jdt.internal.compiler.lookup.TypeBinding.isAnonymousType() because binding.type is null" on hyperlink request
158+
public void testIssue4216() throws CoreException {
159+
this.wc = getWorkingCopy("/Resolve/src/X.java",
160+
"""
161+
public class Hover {
162+
163+
private void mat() {
164+
var entity/*here*/ = entity.get() == null ? entity : entity.get();
165+
}
166+
}
167+
""");
168+
String str = this.wc.getSource();
169+
String selection = "entity/*here*/";
170+
int start = str.lastIndexOf(selection);
171+
int length = selection.length();
172+
173+
IJavaElement[] selected = this.wc.codeSelect(start, length);
174+
assertEquals(1, selected.length);
175+
assertElementsEqual(
176+
"Unexpected elements",
177+
"entity [in mat() [in Hover [in [Working copy] X.java [in <default> [in src [in Resolve]]]]]]",
178+
selected
179+
);
180+
}
155181
}

org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SelectionRequestor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ public void acceptLocalVariable(LocalVariableBinding binding, org.eclipse.jdt.in
415415
LocalVariable localVar = null;
416416
if(parent != null) {
417417
String typeSig = null;
418-
if (local.type == null || (local.type.isTypeNameVar(binding.declaringScope) && !binding.type.isAnonymousType())) {
418+
if (local.type == null || (local.type.isTypeNameVar(binding.declaringScope) && binding.type != null && !binding.type.isAnonymousType())) {
419419
if (local.initialization instanceof CastExpression) {
420420
typeSig = Util.typeSignature(((CastExpression) local.initialization).type);
421421
} else {

0 commit comments

Comments
 (0)