Skip to content

Commit e4fcda2

Browse files
java.lang.NullPointerException: Cannot invoke "org.eclipse.jdt.internal.compiler.lookup.TypeBinding.isLocalType()" because "originalType" is null(eclipse-jdt#4211)
Fixes eclipse-jdt#4202
1 parent 6a50cdd commit e4fcda2

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,7 @@ public LocalTypeSubstitutor(Map<Integer, LocalTypeBinding> localTypes, MethodBin
15241524

15251525
@Override
15261526
public TypeBinding substitute(Substitution substitution, TypeBinding originalType) {
1527-
if (originalType.isLocalType()) {
1527+
if (originalType != null && originalType.isLocalType()) {
15281528
LocalTypeBinding orgLocal = (LocalTypeBinding) originalType.original();
15291529
MethodScope lambdaScope2 = orgLocal.scope.enclosingLambdaScope();
15301530
if (lambdaScope2 != null) {

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10593,6 +10593,92 @@ void h(X c) {
1059310593
"----------\n");
1059410594
}
1059510595

10596+
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4202
10597+
// java.lang.NullPointerException: Cannot invoke "org.eclipse.jdt.internal.compiler.lookup.TypeBinding.isLocalType()" because "originalType" is null
10598+
public void testIssue4202() {
10599+
this.runNegativeTest(
10600+
new String[] {
10601+
"X.java",
10602+
"""
10603+
import java.util.function.Function;
10604+
10605+
public class X {
10606+
void foo(Function<String, String> f) {}
10607+
private void doChooseImports() {
10608+
foo(() -> {
10609+
10610+
MultiElementListSelectionDialog dialog= new Object() {
10611+
@Override
10612+
protected void handleSelectionChanged() {
10613+
super.handleSelectionChanged();
10614+
// show choices in editor
10615+
doListSelectionChanged(getCurrentPage(), ranges, editor);
10616+
}
10617+
};
10618+
fIsQueryShowing= false;
10619+
return result;
10620+
});
10621+
}
10622+
10623+
private void doListSelectionChanged() {
10624+
// blah
10625+
}
10626+
}
10627+
"""
10628+
},
10629+
"----------\n" +
10630+
"1. ERROR in X.java (at line 6)\n" +
10631+
" foo(() -> {\n" +
10632+
" ^^^\n" +
10633+
"The method foo(Function<String,String>) in the type X is not applicable for the arguments (() -> {})\n" +
10634+
"----------\n" +
10635+
"2. ERROR in X.java (at line 6)\n" +
10636+
" foo(() -> {\n" +
10637+
" ^^^^^\n" +
10638+
"Lambda expression's signature does not match the signature of the functional interface method apply(String)\n" +
10639+
"----------\n" +
10640+
"3. ERROR in X.java (at line 8)\n" +
10641+
" MultiElementListSelectionDialog dialog= new Object() {\n" +
10642+
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
10643+
"MultiElementListSelectionDialog cannot be resolved to a type\n" +
10644+
"----------\n" +
10645+
"4. ERROR in X.java (at line 10)\n" +
10646+
" protected void handleSelectionChanged() {\n" +
10647+
" ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
10648+
"The method handleSelectionChanged() of type new Object(){} must override or implement a supertype method\n" +
10649+
"----------\n" +
10650+
"5. ERROR in X.java (at line 11)\n" +
10651+
" super.handleSelectionChanged();\n" +
10652+
" ^^^^^^^^^^^^^^^^^^^^^^\n" +
10653+
"The method handleSelectionChanged() is undefined for the type Object\n" +
10654+
"----------\n" +
10655+
"6. ERROR in X.java (at line 13)\n" +
10656+
" doListSelectionChanged(getCurrentPage(), ranges, editor);\n" +
10657+
" ^^^^^^^^^^^^^^\n" +
10658+
"The method getCurrentPage() is undefined for the type new Object(){}\n" +
10659+
"----------\n" +
10660+
"7. ERROR in X.java (at line 13)\n" +
10661+
" doListSelectionChanged(getCurrentPage(), ranges, editor);\n" +
10662+
" ^^^^^^\n" +
10663+
"ranges cannot be resolved to a variable\n" +
10664+
"----------\n" +
10665+
"8. ERROR in X.java (at line 13)\n" +
10666+
" doListSelectionChanged(getCurrentPage(), ranges, editor);\n" +
10667+
" ^^^^^^\n" +
10668+
"editor cannot be resolved to a variable\n" +
10669+
"----------\n" +
10670+
"9. ERROR in X.java (at line 16)\n" +
10671+
" fIsQueryShowing= false;\n" +
10672+
" ^^^^^^^^^^^^^^^\n" +
10673+
"fIsQueryShowing cannot be resolved to a variable\n" +
10674+
"----------\n" +
10675+
"10. ERROR in X.java (at line 17)\n" +
10676+
" return result;\n" +
10677+
" ^^^^^^\n" +
10678+
"result cannot be resolved to a variable\n" +
10679+
"----------\n");
10680+
}
10681+
1059610682
public static Class testClass() {
1059710683
return NegativeLambdaExpressionsTest.class;
1059810684
}

0 commit comments

Comments
 (0)