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

Summary: Incorrect "The 'throw' statement in 'finally' block may hide the original exception" hint
Product: java Reporter: in-ws5
Component: HintsAssignee: Svata Dedic <sdedic>
Status: RESOLVED FIXED    
Severity: normal CC: matthies
Priority: P3    
Version: 8.0.2   
Hardware: PC   
OS: Windows 8.1   
Issue Type: DEFECT Exception Reporter:

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