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 255635 - Incorrect "The 'throw' statement in 'finally' block may hide the original exception" hint
Summary: Incorrect "The 'throw' statement in 'finally' block may hide the original exc...
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0.2
Hardware: PC Windows 8.1
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
: 262556 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-10-01 07:26 UTC by in-ws5
Modified: 2016-07-14 01:52 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description in-ws5 2015-10-01 07:26:49 UTC
The following code produces the editor hint "The 'throw' statement in 'finally' block may hide the original exception" on the code line "throw ex"

public class A {

    public static void main(String... args) throws Exception {
        try {
            throw new Exception();
        } catch (final Exception ex) {
            try {

            } finally {
                throw ex;
            }
        }
    }
}

But since "ex" is declared "final", this can not be the case.
Comment 1 Svata Dedic 2015-10-01 07:51:38 UTC
ACK, re-throwing is not handled.
Comment 2 in-ws5 2015-10-19 12:08:59 UTC
Should we add this as blocking to 249320?
Comment 3 Svata Dedic 2015-10-19 12:18:02 UTC
No; the hint checks that the 'ex' value is "properly" used (i.e. assigned, passed somewhere else, logged...). Rethrowing the value is another (not yet handled) case.
Comment 4 Svata Dedic 2016-06-21 14:40:15 UTC
One correction: if the nested try block is more complex, it can also produce some exceptions. Those 'nested' exceptions would be masked by the throw ex statement.
This may or may not be intentional, depending on coding style.

I'll add additional logic, which (depending on option) suppresses the hint if the thrown value can only come from an enclosing exception handler parameter.

Implemented in jet-main#cf89e55cb774
Comment 5 Svata Dedic 2016-07-13 12:11:02 UTC
*** Bug 262556 has been marked as a duplicate of this bug. ***
Comment 6 Quality Engineering 2016-07-14 01:52:37 UTC
Integrated into 'main-silver', will be available in build *201607140002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/cf89e55cb774
User: Svata Dedic <sdedic@netbeans.org>
Log: #255635: rethrowing exception in nested finally needs special handling