Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2014-01-23 19:42:13 +0000
committerStephan Herrmann2014-01-23 19:44:51 +0000
commitc4203edb27100ace82d961d9cf1385c837279276 (patch)
tree69e1e99935e29e6f978af72ca52a65da09561225
parent5f8bc31fdd9227264ffdb0d653c171e78b54416c (diff)
downloadeclipse.jdt.core-c4203edb27100ace82d961d9cf1385c837279276.tar.gz
eclipse.jdt.core-c4203edb27100ace82d961d9cf1385c837279276.tar.xz
eclipse.jdt.core-c4203edb27100ace82d961d9cf1385c837279276.zip
Bug 425152 - [1.8] [compiler] Lambda Expression not resolved but flow
analyzed leading to NPE.
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java24
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExpressionFormula.java8
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java11
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding.java8
5 files changed, 45 insertions, 8 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
index f710896ec7..500c13a17d 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java
@@ -1237,4 +1237,28 @@ public void testBug426290() {
},
"goo(List<Integer>)");
}
+public void testBug425152() {
+ runConformTest(
+ new String[] {
+ "packDown/SorterNew.java",
+ "package packDown;\n" +
+ "\n" +
+ "import java.util.ArrayList;\n" +
+ "import java.util.Collections;\n" +
+ "import java.util.Comparator;\n" +
+ "\n" +
+ "public class SorterNew {\n" +
+ " void sort() {\n" +
+ " Collections.sort(new ArrayList<Person>(),\n" +
+ " Comparator.comparing((Person p) -> p.getName()));\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "class Person {\n" +
+ " public String getName() {\n" +
+ " return \"p\";\n" +
+ " }\n" +
+ "}\n"
+ });
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExpressionFormula.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExpressionFormula.java
index ec1a3ce748..1290764f21 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExpressionFormula.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ConstraintExpressionFormula.java
@@ -91,11 +91,9 @@ class ConstraintExpressionFormula extends ConstraintFormula {
MethodBinding previousMethod = invocation.binding(this.right);
MethodBinding method = previousMethod;
// ignore previous (inner) inference result and do a fresh start:
- if (previousMethod instanceof ParameterizedMethodBinding) {
- // avoid original(), since we only want to discard one level of instantiation
- // (method type variables - not class type variables)!
- method = ((ParameterizedMethodBinding)previousMethod).originalMethod;
- }
+ // avoid original(), since we only want to discard one level of instantiation
+ // (method type variables - not class type variables)!
+ method = previousMethod.shallowOriginal();
InvocationRecord prevInvocation = inferenceContext.enterPolyInvocation(invocation, invocation.arguments());
// Invocation Applicability Inference: 18.5.1 & Invocation Type Inference: 18.5.2
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 0b56504984..3910136831 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
@@ -962,7 +962,7 @@ public class InferenceContext18 {
MethodBinding binding = innerMessage.binding(innerTargetType);
if (binding == null)
continue;
- MethodBinding original = binding.original();
+ MethodBinding original = binding.shallowOriginal();
// apply inference results onto the allocation type of inner diamonds:
if (original.isConstructor() && inner.isPolyExpression()) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java
index 9bfc134fce..fb06983ab3 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -21,6 +21,7 @@
* Bug 392099 - [1.8][compiler][null] Apply null annotation on types for null analysis
* Bug 417295 - [1.8[[null] Massage type annotated null analysis to gel well with deep encoded type bindings.
* Bug 400874 - [1.8][compiler] Inference infrastructure should evolve to meet JLS8 18.x (Part G of JSR335 spec)
+ * Bug 425152 - [1.8] [compiler] Lambda Expression not resolved but flow analyzed leading to NPE.
* Jesper Steen Moller - Contributions for
* Bug 412150 [1.8] [compiler] Enable reflected parameter names during annotation processing
*******************************************************************************/
@@ -888,6 +889,14 @@ public MethodBinding original() {
return this;
}
+/**
+ * Strips one level of parameterization, so if both class & method are parameterized,
+ * leave the class parameters in place.
+ */
+public MethodBinding shallowOriginal() {
+ return original();
+}
+
public char[] readableName() /* foo(int, Thread) */ {
StringBuffer buffer = new StringBuffer(this.parameters.length + 1 * 20);
if (isConstructor())
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding.java
index b699eb95e7..44b3a006a2 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedMethodBinding.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -17,6 +17,7 @@
* bug 392384 - [1.8][compiler][null] Restore nullness info from type annotations in class files
* Bug 415043 - [1.8][null] Follow-up re null type annotations after bug 392099
* Bug 417295 - [1.8[[null] Massage type annotated null analysis to gel well with deep encoded type bindings.
+ * Bug 425152 - [1.8] [compiler] Lambda Expression not resolved but flow analyzed leading to NPE.
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.lookup;
@@ -336,4 +337,9 @@ public class ParameterizedMethodBinding extends MethodBinding {
public MethodBinding original() {
return this.originalMethod.original();
}
+
+
+ public MethodBinding shallowOriginal() {
+ return this.originalMethod;
+ }
}

Back to the top