Inferring that what exceptions are thrown from a lambda
Esko Luontola
esko.luontola at gmail.com
Sat Sep 7 09:36:11 PDT 2013
I submitted the bug, but it didn't tell me any Bug ID; it just gave the
"Thank You, We will review your report" message.
The title of the bug report is "Inferring the exception thrown by a
lamdba: sometimes fails to compile", in case you as Oracle employee can
already see it.
Stuart Marks wrote on 7.9.2013 2:53:
> Yep, looks like a bug. I see exactly the behavior you describe.
>
> Could you do me a favor and file a bug report with this information at:
>
> http://bugreport.sun.com/bugreport/
>
> If you send me or post the bug ID I can transfer it into the right
> category.
>
> Thanks!
>
> s'marks
>
>
> On 9/6/13 10:19 AM, Esko Luontola wrote:
>> Stuart Marks wrote on 4.9.2013 23:11:
>>> A change to support this went in fairly recently. This now compiles for
>>> me using JDK 8 b105. It fails with the error you mention when using
>>> older builds, e.g., JDK 8 b88, which is one I happened to have lying
>>> around. (Note, I am referring to JDK 8 builds, not Lambda builds.)
>>
>> I think I found a bug related to that in 1.8.0-ea-b105: when I compile
>> both files with the same javac command, it compiles, but if I compile
>> them separately, it doesn't compile.
>>
>> Here is how to reproduce the issue. I used the
>> jdk-8-ea-bin-b105-windows-x64-29_aug_2013.exe build.
>>
>> -- Foo.java:
>> import java.io.IOException;
>>
>> class Foo {
>>
>> public void compiles() throws IOException {
>> String result = Bar.tryRepeatedly(10, () -> {
>> throw new IOException("dummy exception");
>> });
>> }
>>
>> public void doesNotCompile() {
>> String result = Bar.tryRepeatedly(10, () -> "result");
>> }
>>
>> public void compilesButUndesirable() throws Throwable {
>> String result = Bar.tryRepeatedly(10, () -> "result");
>> }
>> }
>> --
>>
>> -- Bar.java:
>> class Bar {
>> public static <T, E extends Throwable> T tryRepeatedly(int
>> maxTries, Action<T, E> action) throws E {
>> return action.run();
>> }
>> }
>>
>> interface Action<T, E extends Throwable> {
>> T run() throws E;
>> }
>> --
>>
>> This command succeeds:
>>
>> $ javac Foo.java Bar.java
>>
>> But this series of commands fails:
>>
>> $ javac Bar.java
>>
>> $ javac Foo.java
>> Foo.java:12: error: unreported exception Throwable; must be caught or
>> declared to be thrown
>> String result = Bar.tryRepeatedly(10, () -> "result");
>> ^
>> 1 error
>>
>>
--
Esko Luontola
www.orfjackal.net
More information about the lambda-dev
mailing list