Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTill Brychcy2017-04-19 18:34:15 +0000
committerTill Brychcy2017-04-19 18:43:15 +0000
commit07238913f56a97ba44a9303668e05bdac0c99e0a (patch)
treec12e171e1911c92bffec1500177fd5133c101ebb
parent19857c5d65a5d971d4c102b369a8f8fb88c55e41 (diff)
downloadeclipse.jdt.core-07238913f56a97ba44a9303668e05bdac0c99e0a.tar.gz
eclipse.jdt.core-07238913f56a97ba44a9303668e05bdac0c99e0a.tar.xz
eclipse.jdt.core-07238913f56a97ba44a9303668e05bdac0c99e0a.zip
Bug 515473 - [1.8] Bogus resource leak warning caused by return
statement in lambda Change-Id: I54b4995af6d4d963272d3a5176832488e39a18e8
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java30
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java2
2 files changed, 31 insertions, 1 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java
index 37023f15de..0d9f6a1455 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java
@@ -6416,6 +6416,36 @@ public void testBug514105() {
"public class FunctionalInterfaceBug {}\n"
});
}
+public void testBug515473() {
+ runConformTest(
+ new String[] {
+ "test/LambdaResourceLeak.java",
+ "package test;\n" +
+ "\n" +
+ "class X implements AutoCloseable {\n" +
+ " @Override\n" +
+ " public void close() {\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "interface SAM {\n" +
+ " Object m();\n" +
+ "}\n" +
+ "\n" +
+ "public class LambdaResourceLeak {\n" +
+ " void f() {\n" +
+ " X x1 = new X();\n" +
+ " SAM sam = () -> {\n" +
+ " return \"\";\n" +
+ " };\n" +
+ " sam.m();\n" +
+ " x1.close();\n" +
+ " }\n" +
+ "}\n" +
+ "",
+ }
+ );
+}
public static Class testClass() {
return LambdaExpressionsTest.class;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java
index 3f5b926ae8..32de2db36c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java
@@ -1072,7 +1072,7 @@ public void checkUnclosedCloseables(FlowInfo flowInfo, FlowContext flowContext,
if (!compilerOptions().analyseResourceLeaks) return;
if (this.trackingVariables == null) {
// at a method return we also consider enclosing scopes
- if (location != null && this.parent instanceof BlockScope)
+ if (location != null && this.parent instanceof BlockScope && !isLambdaScope())
((BlockScope) this.parent).checkUnclosedCloseables(flowInfo, flowContext, location, locationScope);
return;
}

Back to the top