aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2012-09-15 18:49:59 (EDT)
committerJayaprakash Arthanareeswaran2012-10-19 00:49:00 (EDT)
commit92d34a08c5b7cee27a23496b725828e445b4ac02 (patch)
tree4407f419569ce8b48d6aec485d1a283a94de8b51
parent1b2e1f16a7b68739fef072ffcd776d1f0d560caa (diff)
downloadeclipse.jdt.core-92d34a08c5b7cee27a23496b725828e445b4ac02.zip
eclipse.jdt.core-92d34a08c5b7cee27a23496b725828e445b4ac02.tar.gz
eclipse.jdt.core-92d34a08c5b7cee27a23496b725828e445b4ac02.tar.bz2
Bug 386534 - [compiler][resource] "Potential resource leak" false
positive warning
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java55
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FakedTrackingVariable.java11
2 files changed, 63 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java
index 031432d..d8aced8 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java
@@ -26,7 +26,7 @@ import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
public class ResourceLeakTests extends AbstractRegressionTest {
static {
-// TESTS_NAMES = new String[] { "testBug388996" };
+// TESTS_NAMES = new String[] { "testBug386534" };
// TESTS_NUMBERS = new int[] { 50 };
// TESTS_RANGE = new int[] { 11, -1 };
}
@@ -3870,4 +3870,57 @@ public void testBug388996() {
options,
null);
}
+
+// https://bugs.eclipse.org/386534 - [compiler][resource] "Potential resource leak" false positive warning
+public void testBug386534() {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR);
+ runConformTest(
+ new String[] {
+ "Bug386534.java",
+ "import java.io.FileNotFoundException;\n" +
+ "import java.io.IOException;\n" +
+ "import java.io.OutputStream;\n" +
+ "\n" +
+ "public class Bug386534 {\n" +
+ " private static final String DETAILS_FILE_NAME = null;\n" +
+ " private static final String LOG_TAG = null;\n" +
+ " private static Context sContext;\n" +
+ " static void saveDetails(byte[] detailsData) {\n" +
+ " OutputStream os = null;\n" +
+ " try {\n" +
+ " os = sContext.openFileOutput(DETAILS_FILE_NAME,\n" +
+ " Context.MODE_PRIVATE);\n" +
+ " os.write(detailsData);\n" +
+ " } catch (IOException e) {\n" +
+ " Log.w(LOG_TAG, \"Unable to save details\", e);\n" +
+ " } finally {\n" +
+ " if (os != null) {\n" +
+ " try {\n" +
+ " os.close();\n" +
+ " } catch (IOException ignored) {\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " static class Context {\n" +
+ " public static final String MODE_PRIVATE = null;\n" +
+ " public OutputStream openFileOutput(String detailsFileName,\n" +
+ " String modePrivate) throws FileNotFoundException{\n" +
+ " return null;\n" +
+ " }\n" +
+ " }\n" +
+ " static class Log {\n" +
+ " public static void w(String logTag, String string, IOException e) {\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ "",
+ null,
+ true,
+ null,
+ options,
+ null);
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FakedTrackingVariable.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FakedTrackingVariable.java
index 20dde0b..ca84393 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FakedTrackingVariable.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FakedTrackingVariable.java
@@ -91,8 +91,15 @@ public class FakedTrackingVariable extends LocalDeclaration {
((long)this.sourceStart <<32)+this.sourceEnd);
this.methodScope = original.declaringScope.methodScope();
this.originalBinding = original;
- if (flowContext instanceof FinallyFlowContext)
- this.tryContext = ((FinallyFlowContext) flowContext).tryContext;
+ // inside a finally block?
+ while (flowContext != null) {
+ if (flowContext instanceof FinallyFlowContext) {
+ // yes -> connect to the corresponding try block:
+ this.tryContext = ((FinallyFlowContext) flowContext).tryContext;
+ break;
+ }
+ flowContext = flowContext.parent;
+ }
resolve(original.declaringScope);
}