Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2019-12-26 17:30:28 +0000
committerStephan Herrmann2019-12-26 17:30:28 +0000
commit785c7ca7509cb0eb9aef1b5862a374ffd0b0a5d7 (patch)
treedef339a3501d5d789d80d01a5f06eaa265228872
parent3f16176dca63531a876ad5417969b1b88503c387 (diff)
downloadeclipse.jdt.core-785c7ca7509cb0eb9aef1b5862a374ffd0b0a5d7.tar.gz
eclipse.jdt.core-785c7ca7509cb0eb9aef1b5862a374ffd0b0a5d7.tar.xz
eclipse.jdt.core-785c7ca7509cb0eb9aef1b5862a374ffd0b0a5d7.zip
Bug 400523 - Invalid Resource Leak Warning Reported for void Method;
Adding Empty Return Resolves Warning Change-Id: Ib90613da99b7fbb27b6eea03ffe41b9e3899116f
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java52
1 files changed, 52 insertions, 0 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 7a51008e99..4472955cbe 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
@@ -6091,4 +6091,56 @@ public void testBug552441() {
},
options);
}
+public void testBug400523() {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR);
+ options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR);
+
+ runConformTest(
+ new String[] {
+ "LeakWarning.java",
+ "import java.sql.Connection;\n" +
+ "import java.sql.PreparedStatement;\n" +
+ "import java.sql.ResultSet;\n" +
+ "import java.sql.SQLException;\n" +
+ "\n" +
+ "public class LeakWarning {\n" +
+ " String value = null;\n" +
+ " \n" +
+ " public void setValue(Connection conn)\n" +
+ " { \n" +
+ " PreparedStatement stmt = null;\n" +
+ " ResultSet rs = null;\n" +
+ " try { \n" +
+ " stmt = conn.prepareStatement(\"SELECT 'value'\"); /* marked as potential resource leak */\n" +
+ " rs = stmt.executeQuery(); /* marked as potential resource leak */\n" +
+ " if (rs.next()) value = rs.getString(1);\n" +
+ " } catch(SQLException e) {\n" +
+ " }\n" +
+ " finally {\n" +
+ " if (null != rs) try { rs.close(); } catch (SQLException e) {} finally { rs = null; }\n" +
+ " if (null != stmt) try { stmt.close(); } catch (SQLException e) {} finally { stmt = null; }\n" +
+ " }\n" +
+ " }\n" +
+ " \n" +
+ " public void setValueReturn(Connection conn)\n" +
+ " { \n" +
+ " PreparedStatement stmt = null;\n" +
+ " ResultSet rs = null;\n" +
+ " try { \n" +
+ " stmt = conn.prepareStatement(\"SELECT 'value'\");\n" +
+ " rs = stmt.executeQuery();\n" +
+ " if (rs.next()) value = rs.getString(1);\n" +
+ " } catch(SQLException e) {\n" +
+ " }\n" +
+ " finally {\n" +
+ " if (null != rs) try { rs.close(); } catch (SQLException e) {} finally { rs = null; }\n" +
+ " if (null != stmt) try { stmt.close(); } catch (SQLException e) {} finally { stmt = null; }\n" +
+ " }\n" +
+ " return; /* no warning now */\n" +
+ " }\n" +
+ "}\n"
+ },
+ options);
+}
}

Back to the top