Inferring that what exceptions are thrown from a lambda

Stuart Marks stuart.marks at oracle.com
Mon Sep 9 13:25:58 PDT 2013


Thanks for submitting this. I thought you'd get a bug ID. Anyway, based 
on your description I found the bug and I moved it out of the staging 
area into the compiler category. Someone is looking at it now.

The bug *ought* to be visible here by now:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8024437

since I actually moved it a couple days ago, but for some reason it's 
not. Maybe the public bug viewer synchronization process is clogged up 
again. In any case, the bug should be visible at that link sometime soon.

Anyway, thanks again. Finding and reporting bugs is a great help!

s'marks


On 9/7/13 9:36 AM, Esko Luontola wrote:
> 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
>>>
>>>
>


More information about the lambda-dev mailing list