Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
Bug 215546 - Too aggressive refactoring to use multi-catch statement
Too aggressive refactoring to use multi-catch statement
Status: RESOLVED FIXED
Product: java
Classification: Unclassified
Component: Hints
7.2
PC Windows 7
: P3 (vote)
: 8.0
Assigned To: Svata Dedic
issues@java
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-07-14 17:46 UTC by DVyazelenko
Modified: 2013-11-24 02:20 UTC (History)
0 users

See Also:
Issue Type: DEFECT
:


Attachments
Sample NetBeans project to reproduce bug (15.34 KB, application/zip)
2012-07-14 17:46 UTC, DVyazelenko
Details

Note You need to log in before you can comment on or make changes to this bug.
Description DVyazelenko 2012-07-14 17:46:05 UTC
Created attachment 122026 [details]
Sample NetBeans project to reproduce bug

I've recently migrated big project to Java 7 and used NetBeans 7.2 RC1 to convert code to use new Java 7 features.
However I've noticed problems in the code were existing catch statements were replaced with multi-catch alternatives.

For example this method:
<pre>
private void doImport(File f, Collection<?> importLog) {
        startTransaction();
        try {
            doImportFromFile(f, importLog);
            commitTransaction();
        } catch (Throwable t) {
            rollbackTransaction();
            reThrow(t);
        }
    }
</pre>

Was converted to:
<pre>
private void doImport(File f, Collection<?> importLog) {
        startTransaction();
        try {
            doImportFromFile(f, importLog);
            commitTransaction();
        } catch (IOException | XMLStreamException t) {
            rollbackTransaction();
            reThrow(t);
        }
    }
</pre>

Which is *not* semantically equivalent, because new code does not handle unchecked exceptions anymore!!!

Please find sample project attached. The error can be reproduced always, both using "Inspect and Transform"->"Convert to JDK 7" and using Alt-Enter hint menu on the line with "catch(Throwable)".

JDK version:
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)

NetBeans version:
Product Version: NetBeans IDE 7.2 RC1 (Build 201206272359)
Java: 1.7.0_05; Java HotSpot(TM) 64-Bit Server VM 23.1-b03
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
Comment 1 Svata Dedic 2013-11-14 08:37:17 UTC
The "Use specific catch" is designed to help with exactly the transformation you describe. However it needs a human inspection to see whether the semantic change is good.

In general catching Throwable (or RuntimeException) is a bad thing, since it usually traps other than expected issues. In your case, I would recommend somewhat more verbose, but cleaner construction using finally block (unless you require the Throwable to be e.g. logged).

But as 'convert to JDK7' is meant to be more or less automatic, and semantic changes are not expected, I'll leave this inspection out of the profile.

Fixed in revision http://hg.netbeans.org/jet-main/rev/36369c95080d
Comment 2 Quality Engineering 2013-11-24 02:20:25 UTC
Integrated into 'main-silver', will be available in build *201311240002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/36369c95080d
User: Svata Dedic <sdedic@netbeans.org>
Log: #215546: use specific catch left out of JDK7 migration


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