Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
Bug 269962 - Statements including generics, streams and exceptions does not compile
Statements including generics, streams and exceptions does not compile
Status: RESOLVED WORKSFORME
Product: java
Classification: Unclassified
Component: Compiler
8.0.2
PC Linux
: P3 (vote)
: Dev
Assigned To: Dusan Balek
issues@java
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2017-03-01 20:59 UTC by bastik
Modified: 2017-09-22 12:12 UTC (History)
0 users

See Also:
Issue Type: DEFECT
:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bastik 2017-03-01 20:59:17 UTC
The following lines do not compile in Netbeans:

 java.io.File f = null;
 Collections.singleton(Optional.ofNullable(Optional.ofNullable(f).orElseThrow(null).getName()).orElseThrow(null));

The error is:
error: unreported exception X; must be caught or declared to be thrown
        Collections.singleton(Optional.ofNullable(Optional.ofNullable(f).orElseThrow(null).getName()).orElseThrow(null));
  where X,T are type-variables:
    X extends Throwable declared in method <X>orElseThrow(Supplier<? extends X>)
    T extends Object declared in class Optional

__

No problem is reported by the standard compiler (javac 1.8.0_91). Please ignore the fact that the code makes no sense, it is just a minimal demonstration of the compile time problem.

Workaround: add type hint like this:
 Collections.<String>singleton ...
Comment 1 Dusan Balek 2017-09-22 12:12:43 UTC
Seems to work fine in the current dev build.


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