Bug 438945 - [1.8] NullPointerException
InferenceContext18.checkExpression in java 8 with generics, primitives,
and overloading
Change-Id: If559b8c584a0e935f26c0627e724b315977e513e
Signed-off-by: Stephan Herrmann <stephan.herrmann@berlin.de>
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java
index c13c014..f677887 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java
@@ -9131,7 +9131,7 @@
"----------\n");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=438945, [1.8] NullPointerException InferenceContext18.checkExpression in java 8 with generics, primitives, and overloading
-public void _test438945() {
+public void test438945() {
this.runNegativeTest(
new String[] {
"X.java",
@@ -9494,4 +9494,4 @@
public static Class testClass() {
return NegativeLambdaExpressionsTest.class;
}
-}
\ No newline at end of file
+}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java
index 9396583..310c53d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReferenceExpression.java
@@ -31,6 +31,7 @@
* Bug 438383 - [1.8][null] Bogus warning: Null type safety at method return type
* Bug 434483 - [1.8][compiler][inference] Type inference not picked up with method reference
* Bug 441734 - [1.8][inference] Generic method with nested parameterized type argument fails on method reference
+ * Bug 438945 - [1.8] NullPointerException InferenceContext18.checkExpression in java 8 with generics, primitives, and overloading
* Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contribution for
* Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work)
*******************************************************************************/
@@ -719,6 +720,10 @@
return this.exactMethodBinding != null;
}
+ public MethodBinding getExactMethod() {
+ return this.exactMethodBinding;
+ }
+
public boolean isMethodReference() {
return !CharOperation.equals(this.selector, ConstantPool.Init);
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java
index ed52407..61fbcc0 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java
@@ -792,19 +792,19 @@
}
return reduceAndIncorporate(ConstraintTypeFormula.create(r1, r2, ReductionResult.SUBTYPE));
} else if (expri instanceof ReferenceExpression && ((ReferenceExpression)expri).isExactMethodReference()) {
+ ReferenceExpression reference = (ReferenceExpression) expri;
for (int i = 0; i < u.length; i++) {
- ReferenceExpression reference = (ReferenceExpression) expri;
if (!reduceAndIncorporate(ConstraintTypeFormula.create(u[i], v[i], ReductionResult.SAME)))
return false;
- if (r2.id == TypeIds.T_void)
- return true;
- MethodBinding method = reference.findCompileTimeMethodTargeting(null, this.scope); // TODO directly access exactMethodBinding!
- TypeBinding returnType = method.isConstructor() ? method.declaringClass : method.returnType;
- if (r1.isPrimitiveType() && !r2.isPrimitiveType() && returnType.isPrimitiveType())
- return true;
- if (r2.isPrimitiveType() && !r1.isPrimitiveType() && !returnType.isPrimitiveType())
- return true;
}
+ if (r2.id == TypeIds.T_void)
+ return true;
+ MethodBinding method = reference.getExactMethod();
+ TypeBinding returnType = method.isConstructor() ? method.declaringClass : method.returnType;
+ if (r1.isPrimitiveType() && !r2.isPrimitiveType() && returnType.isPrimitiveType())
+ return true;
+ if (r2.isPrimitiveType() && !r1.isPrimitiveType() && !returnType.isPrimitiveType())
+ return true;
return reduceAndIncorporate(ConstraintTypeFormula.create(r1, r2, ReductionResult.SUBTYPE));
} else if (expri instanceof ConditionalExpression) {
ConditionalExpression cond = (ConditionalExpression) expri;