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.

Bug 227787 - Nested try-with-resource refactoring hints for jdbc objects remove parameter binding
Summary: Nested try-with-resource refactoring hints for jdbc objects remove parameter ...
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.3
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Jan Lahoda
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-21 18:44 UTC by bgunnink
Modified: 2013-05-09 14:58 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Screenshot of Netbeans' try-with-resources refactor hint (16.98 KB, image/png)
2013-03-21 18:44 UTC, bgunnink
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bgunnink 2013-03-21 18:44:16 UTC
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).
Comment 1 Jan Lahoda 2013-04-03 17:44:00 UTC
http://hg.netbeans.org/jet-main/rev/6545d60f33d8
Comment 2 Jiri Prox 2013-04-15 14:45:08 UTC
verified
Comment 3 Jan Lahoda 2013-05-03 07:31:40 UTC
release73:
http://hg.netbeans.org/releases/rev/7835c91f8679
Comment 4 Quality Engineering 2013-05-05 00:26:27 UTC
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.