diff options
author | Stephan Herrmann | 2016-02-06 18:14:22 +0000 |
---|---|---|
committer | Stephan Herrmann | 2016-02-06 18:33:37 +0000 |
commit | 266bcdeab31dc3881bcf84108cea53936b1adeca (patch) | |
tree | 765421df2dbe0d1d6747c4895827aac2e83a808a | |
parent | 1348d1b019d1173b39c4caeaa2daa962f282640d (diff) | |
download | eclipse.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
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]); } |