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 ff4c4cf..9ed8c39 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[] { "test061c"}; +// TESTS_NAMES = new String[] { "test063e"}; // TESTS_NUMBERS = new int[] { 50 }; // TESTS_RANGE = new int[] { 11, -1 }; } @@ -1838,7 +1838,6 @@ public void test056throw5() { true, options); } - // Bug 358903 - Filter practically unimportant resource leak warnings // Bug 360908 - Avoid resource leak warning when the underlying/chained resource is closed explicitly // a resource wrapper is not closed but the underlying resource is @@ -2674,5 +2673,32 @@ public void test063d() throws IOException { "----------\n", options); } +// Bug 362332 - Only report potential leak when closeable not created in the local scope +// a resource is obtained from a field read, then re-assigned +public void test063e() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " FileInputStream input1;\n" + + " public void foo() throws IOException {\n" + + " FileInputStream input = input1;\n" + + " input = new FileInputStream(\"adfafd\");\n" + + " input.close();\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 e1330a7..4ec7620 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 @@ -351,8 +351,7 @@ public class FakedTrackingVariable extends LocalDeclaration { tracker.globalClosingState |= PASSED_TO_OUTSIDE; flowInfo.markPotentiallyNullBit(tracker.binding); // shed some doubt return tracker; - } else if (expression instanceof FieldReference - || expression instanceof QualifiedNameReference) + } else if ((expression.bits & RestrictiveFlagMASK) == Binding.FIELD) { // responsibility for this resource probably lies at a higher level FakedTrackingVariable tracker = new FakedTrackingVariable(local, location);