Inferring that what exceptions are thrown from a lambda
Stuart Marks
stuart.marks at oracle.com
Fri Sep 6 16:53:50 PDT 2013
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