Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2016-02-06 18:14:22 +0000
committerStephan Herrmann2016-02-06 18:33:37 +0000
commit266bcdeab31dc3881bcf84108cea53936b1adeca (patch)
tree765421df2dbe0d1d6747c4895827aac2e83a808a
parent1348d1b019d1173b39c4caeaa2daa962f282640d (diff)
downloadeclipse.jdt.core-266bcdeab31dc3881bcf84108cea53936b1adeca.tar.gz
eclipse.jdt.core-266bcdeab31dc3881bcf84108cea53936b1adeca.tar.xz
eclipse.jdt.core-266bcdeab31dc3881bcf84108cea53936b1adeca.zip
Bug 487390: [compiler] AIOOBE thrown when compiling lambda against
functional type with syntax error Change-Id: Ided761187741e0588f6514655efc80bfba27210b
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java59
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java2
2 files changed, 60 insertions, 1 deletions
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 295e41ee72..23282ac756 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
@@ -9868,6 +9868,65 @@ public void test474522() {
"The blank final field s may not have been initialized\n" +
"----------\n");
}
+public void testBug487390() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "interface ConsumeN {\n" +
+ " void consume(String.. strings); // syntax error here\n" +
+ "}\n" +
+ "public class X {\n" +
+ "\n" +
+ " void consu(ConsumeN c) { }\n" +
+ " void test() {\n" +
+ " consu((String... s) -> System.out.print(s.length));\n" +
+ " }\n" +
+ "}"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " void consume(String.. strings); // syntax error here\n" +
+ " ^\n" +
+ "Syntax error on token \".\", Identifier expected\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 8)\n" +
+ " consu((String... s) -> System.out.print(s.length));\n" +
+ " ^^^^^\n" +
+ "The method consu(ConsumeN) in the type X is not applicable for the arguments ((String... s) -> {})\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 8)\n" +
+ " consu((String... s) -> System.out.print(s.length));\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Lambda expression\'s signature does not match the signature of the functional interface method consume()\n" +
+ "----------\n");
+}
+public void testBug487390b() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "interface ConsumeN {\n" +
+ " void consume();\n" +
+ "}\n" +
+ "public class X {\n" +
+ "\n" +
+ " void consu(ConsumeN c) { }\n" +
+ " void test() {\n" +
+ " consu((String... s) -> System.out.print(s.length));\n" +
+ " }\n" +
+ "}"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " consu((String... s) -> System.out.print(s.length));\n" +
+ " ^^^^^\n" +
+ "The method consu(ConsumeN) in the type X is not applicable for the arguments ((String... s) -> {})\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 8)\n" +
+ " consu((String... s) -> System.out.print(s.length));\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Lambda expression\'s signature does not match the signature of the functional interface method consume()\n" +
+ "----------\n");
+}
public static Class testClass() {
return NegativeLambdaExpressionsTest.class;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
index 80c4a8dc20..8b5dc9a61d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LambdaExpression.java
@@ -381,7 +381,7 @@ public class LambdaExpression extends FunctionalExpression implements IPolyExpre
this.binding.setParameterAnnotations(parameterAnnotations);
}
- if (!argumentsTypeElided && this.binding.isVarargs()) {
+ if (!argumentsTypeElided && !argumentsHaveErrors && this.binding.isVarargs()) {
if (!this.binding.parameters[this.binding.parameters.length - 1].isReifiable()) {
this.scope.problemReporter().possibleHeapPollutionFromVararg(this.arguments[this.arguments.length - 1]);
}

Back to the top