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 243095 - Missing throws declaration when converting lambda expression to anonymous inner class
Summary: Missing throws declaration when converting lambda expression to anonymous inn...
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0
Hardware: PC Windows 8
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-20 14:38 UTC by xehpuk
Modified: 2014-08-07 02:22 UTC (History)
0 users

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 xehpuk 2014-03-20 14:38:22 UTC
Product Version = NetBeans IDE 8.0 (Build 201403101706)
Operating System = Windows 8 version 6.2 running on amd64
Java; VM; Vendor = 1.8.0
Runtime = Java HotSpot(TM) 64-Bit Server VM 25.0-b70

Consider this class (imply an import for java.util.concurrent.Callable):

class MissingThrowsDeclarationWhenConvertingLambdaExpressionToAnonymousInnerClass {
    void bug() {
        java.util.concurrent.Callable<String> c = () -> {
            throw new Exception();
        };
    }
}

It compiles fine because Callable<V>'s method is declared as: V call() throws Exception;

NetBeans suggests "Use anonymous inner class" which results in:

class MissingThrowsDeclarationWhenConvertingLambdaExpressionToAnonymousInnerClass {
    void bug() {
        Callable<String> c = new Callable<String>() {
            public String call() {
                throw new Exception(); // "unreported exception Exception; must be caught or declared to be thrown"
            }
        };
    }
}

It does not add a throws declaration, therefore resulting in a compiler error.
Comment 1 Svata Dedic 2014-03-28 13:16:11 UTC
Fixed in jet-main#d5b5dabaf3df
Comment 2 Svata Dedic 2014-03-28 15:42:41 UTC
Apologies, incorrect bug for the message.
Comment 3 Svata Dedic 2014-08-05 20:02:53 UTC
Fixed in jet-main#2c75e687dc17
Comment 4 Quality Engineering 2014-08-07 02:22:20 UTC
Integrated into 'main-silver', will be available in build *201408070001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/2c75e687dc17
User: Svata Dedic <sdedic@netbeans.org>
Log: #243095: throws clause copied from the implemented iface method