diff options
author | Stephan Herrmann | 2017-04-07 18:51:02 +0000 |
---|---|---|
committer | Stephan Herrmann | 2017-04-13 12:24:18 +0000 |
commit | d48b999987f75582ae3625ee8d282a55891032ac (patch) | |
tree | 5096ba73971af888cf94510bf0ed14e1185f4c66 | |
parent | ac0b42790160d343511677594030fb898d07a7d9 (diff) | |
download | eclipse.jdt.core-d48b999987f75582ae3625ee8d282a55891032ac.tar.gz eclipse.jdt.core-d48b999987f75582ae3625ee8d282a55891032ac.tar.xz eclipse.jdt.core-d48b999987f75582ae3625ee8d282a55891032ac.zip |
Bug 514884: NPE in MessageSend#generateCode
Change-Id: I64dffb470d0ee8852e096b9ff75d544f8dd00ce9
Signed-off-by: Stephan Herrmann <stephan.herrmann@berlin.de>
2 files changed, 27 insertions, 7 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 9ff1fdb0c3..62a2cd055d 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 @@ -8090,4 +8090,23 @@ public void testBug508834_comment0() { "----------\n" ); } + public void testBug514884() { + runConformTest( + new String[] { + "Minimal.java", + "import java.io.*;\n" + + "public class Minimal {\n" + + " public void iCrash() throws IOException {\n" + + " try (Closeable o = consumes(sneaky()::withVarargs)) {\n" + + " }\n" + + " }\n" + + "\n" + + " private Minimal sneaky() { return this; }\n" + + "\n" + + " private void withVarargs(String... test) {}\n" + + "\n" + + " private Closeable consumes(Runnable r) { return null; }\n" + + "}\n" + }); + } } 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 3f78515a36..ba19ce25e4 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 @@ -247,20 +247,21 @@ public class ReferenceExpression extends FunctionalExpression implements IPolyEx } // Process the lambda, taking care not to double report diagnostics. Don't expect any from resolve, Any from code generation should surface, but not those from flow analysis. - implicitLambda.resolveType(currentScope, true); - IErrorHandlingPolicy oldPolicy = currentScope.problemReporter().switchErrorHandlingPolicy(silentErrorHandlingPolicy); + BlockScope lambdaScope = this.receiverVariable != null ? this.receiverVariable.declaringScope : currentScope; + implicitLambda.resolveType(lambdaScope, true); + IErrorHandlingPolicy oldPolicy = lambdaScope.problemReporter().switchErrorHandlingPolicy(silentErrorHandlingPolicy); try { - implicitLambda.analyseCode(currentScope, - new FieldInitsFakingFlowContext(null, this, Binding.NO_EXCEPTIONS, null, currentScope, FlowInfo.DEAD_END), - UnconditionalFlowInfo.fakeInitializedFlowInfo(currentScope.outerMostMethodScope().analysisIndex, currentScope.referenceType().maxFieldCount)); + implicitLambda.analyseCode(lambdaScope, + new FieldInitsFakingFlowContext(null, this, Binding.NO_EXCEPTIONS, null, lambdaScope, FlowInfo.DEAD_END), + UnconditionalFlowInfo.fakeInitializedFlowInfo(lambdaScope.outerMostMethodScope().analysisIndex, lambdaScope.referenceType().maxFieldCount)); } finally { - currentScope.problemReporter().switchErrorHandlingPolicy(oldPolicy); + lambdaScope.problemReporter().switchErrorHandlingPolicy(oldPolicy); } SyntheticArgumentBinding[] outerLocals = this.receiverType.syntheticOuterLocalVariables(); for (int i = 0, length = outerLocals == null ? 0 : outerLocals.length; i < length; i++) implicitLambda.addSyntheticArgument(outerLocals[i].actualOuterLocalVariable); - implicitLambda.generateCode(currentScope, codeStream, valueRequired); + implicitLambda.generateCode(lambdaScope, codeStream, valueRequired); if (generateSecretReceiverVariable) { codeStream.removeVariable(this.receiverVariable); this.receiverVariable = null; |