Bug 227787 - Nested try-with-resource refactoring hints for jdbc objects remove parameter binding
Nested try-with-resource refactoring hints for jdbc objects remove parameter ...
Status: VERIFIED FIXED
Product: java
Classification: Unclassified
Component: Hints
7.3
PC Windows 7
: P3 (vote)
: 7.3.1
Assigned To: Jan Lahoda
issues@java
73patch2-verified
:
Depends on:
Blocks:
  Show dependency treegraph
 
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
:


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.


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo