This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Summary: | Nested try-with-resource refactoring hints for jdbc objects remove parameter binding | ||
---|---|---|---|
Product: | java | Reporter: | bgunnink |
Component: | Hints | Assignee: | Jan Lahoda <jlahoda> |
Status: | VERIFIED FIXED | ||
Severity: | normal | CC: | mmirilovic |
Priority: | P3 | ||
Version: | 7.3 | ||
Hardware: | PC | ||
OS: | Windows 7 | ||
Issue Type: | DEFECT | Exception Reporter: | |
Attachments: | Screenshot of Netbeans' try-with-resources refactor hint |
verified Integrated into 'releases', will be available in build *201305042200* or newer. Wait for official and publicly available build. Changeset: http://hg.netbeans.org/releases/rev/7835c91f8679 User: Jan Lahoda <jlahoda@netbeans.org> Log: #227787: preventing convert-to-arm hint in a case it would break source. |
Created attachment 132920 [details] Screenshot of Netbeans' try-with-resources refactor hint Given a piece of code like the following: ===================================== public void test(java.sql.Connection conn) throws Exception { String sqlQuery = "SELECT foo FROM bar WHERE baz = ? AND qux = ? "; try (java.sql.PreparedStatement stmt = conn.prepareStatement(sqlQuery)) { stmt.setString(1, "baz"); stmt.setString(2, "qux"); java.sql.ResultSet rset = stmt.executeQuery(); while (rset.next()) { /* magic */ } rset.close(); } } ===================================== Netbeans 7.3 will recommend two visually-identical refactoring hints (see attachment). Selecting one of them will refactor the code incorrectly, producing this code: ===================================== public void test(java.sql.Connection conn) throws Exception { String sqlQuery = "SELECT foo FROM bar WHERE baz = ? AND qux = ? "; try (java.sql.PreparedStatement stmt = conn.prepareStatement(sqlQuery); java.sql.ResultSet rset = stmt.executeQuery()) { while (rset.next()) { /* magic */ } } } ===================================== The second hint will produce correct output, however. I realize that it's ultimately incumbent upon the user to be careful when refactoring, but as far as I'm concerned, Netbeans should *never* suggest a refactoring that is destructive (read: removes functional code).