Skip to content

Commit d1a8435

Browse files
committed
NPE: Cannot invoke org.eclipse.jdt.internal.compiler.lookup.BlockScope.getBinding() because scope is null" on hyperlink request (#4217)
* Fixes #4217
1 parent 150ab84 commit d1a8435

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,49 @@ private void mat() {
178178
selected
179179
);
180180
}
181+
182+
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4217
183+
// NPE: Cannot invoke org.eclipse.jdt.internal.compiler.lookup.BlockScope.getBinding(char[], int, org.eclipse.jdt.internal.compiler.lookup.InvocationSite, boolean) because scope is null" on hyperlink request
184+
public void testIssue4217() throws CoreException {
185+
this.wc = getWorkingCopy("/Resolve/src/X.java",
186+
"""
187+
import java.util.concurrent.Callable;
188+
189+
public class Test {
190+
191+
public static <T> void createObjectBinding(final Callable<T> func) {
192+
return;
193+
}
194+
195+
sealed interface Index {
196+
enum SS implements Index {}
197+
enum TS implements Index {}
198+
}
199+
200+
public abstract sealed class Entity<S extends Index> permits Struct, Time {}
201+
202+
final class Struct extends Entity<Index.SS> {}
203+
204+
final class Time extends Entity<Index.TS> {
205+
Struct getStruct() {
206+
return null;
207+
}
208+
}
209+
210+
private void setMaterials(Time entity) {
211+
ObjectBinding<Entity<?>> selfIllumImage = Bindings.<Entity<?>>createObjectBinding(() -> {
212+
var entity2/*here*/ = entity.getStruct() == null ? entity : entity.getStruct();
213+
return createSlefIlluminationMap(entity.getSpells());
214+
});
215+
}
216+
}
217+
""");
218+
String str = this.wc.getSource();
219+
String selection = "entity2/*here*/";
220+
int start = str.lastIndexOf(selection);
221+
int length = selection.length();
222+
223+
IJavaElement[] selected = this.wc.codeSelect(start, length);
224+
assertEquals(0, selected.length);
225+
}
181226
}

org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/SelectionEngine.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,9 @@ public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope s
14101410
public boolean visit(
14111411
LocalDeclaration localDeclaration, BlockScope scope) {
14121412
if(localDeclaration instanceof SelectionOnLocalName) {
1413+
if (scope == null) {
1414+
throw new SelectionNodeFound();
1415+
}
14131416
localDeclaration.resolve(scope);
14141417
}
14151418
if (localDeclaration.type instanceof SingleTypeReference && ((SingleTypeReference)localDeclaration.type).token == assistIdentifier) {

0 commit comments

Comments
 (0)