-
Bug
-
Resolution: Fixed
-
P2
-
8
-
b15
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8037239 | 9 | Robert Field | P2 | Closed | Fixed | b12 |
JDK-8045156 | 8u25 | Robert Field | P2 | Resolved | Fixed | b01 |
JDK-8052595 | emb-8u26 | Robert Field | P2 | Resolved | Fixed | b17 |
import java.io.IOException;
public class FunWithMultiCatch {
public static void main(String[] args) {
Runnable r = () -> {
try {
Object o = null;
o.getClass();
throw new IOException();
} catch(IOException | IllegalArgumentException e) {
System.out.println("KO !");
} catch(RuntimeException e) {
System.out.println("OK !");
}
};
r.run();
}
}
javac generates this code:
private static void lambda$main$0();
descriptor: ()V
flags: ACC_PRIVATE, ACC_STATIC, ACC_SYNTHETIC
Code:
stack=2, locals=1, args_size=0
0: aconst_null
1: astore_0
2: aload_0
3: invokevirtual #4 // Method java/lang/Object.getClass:()Ljava/lang/Class;
6: pop
7: new #5 // class java/io/IOException
10: dup
11: invokespecial #6 // Method java/io/IOException."<init>":()V
14: athrow
15: astore_0
16: getstatic #8 // Field java/lang/System.out:Ljava/io/PrintStream;
19: ldc #9 // String KO !
21: invokevirtual #10 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
24: goto 36
27: astore_0
28: getstatic #8 // Field java/lang/System.out:Ljava/io/PrintStream;
31: ldc #12 // String OK !
33: invokevirtual #10 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
36: return
Exception table:
from to target type
0 15 15 Class java/lang/Exception <----- this will capture all exceptions.
0 15 27 Class java/lang/RuntimeException
if the original code is modified to:
import java.io.IOException;
class FunWithMultiCatch {
public static void main(String[] args) {
try {
Object o = null;
o.getClass();
throw new IOException();
} catch(IOException | IllegalArgumentException e) {
System.out.println("KO !");
} catch(RuntimeException e) {
System.out.println("OK !");
}
}
}
then we obtain this exception table:
Exception table:
from to target type
0 15 15 Class java/io/IOException
0 15 15 Class java/lang/IllegalArgumentException
0 15 27 Class java/lang/RuntimeException
reported in lambda-dev: http://mail.openjdk.java.net/pipermail/lambda-dev/2014-March/011940.html
- backported by
-
JDK-8045156 javac generates incorrect exception table for multi-catch statements inside a lambda
- Resolved
-
JDK-8052595 javac generates incorrect exception table for multi-catch statements inside a lambda
- Resolved
-
JDK-8037239 javac generates incorrect exception table for multi-catch statements inside a lambda
- Closed
- duplicates
-
JDK-8013178 Multi-catch in a lambda expression catches any Exceptions
- Closed
- relates to
-
JDK-8042158 LambdaToMethod: consistent variable translation
- Open
-
JDK-8036958 doc, release notes for JDK-8036942 should be added
- Closed
-
JDK-8042239 javac: TreeMaker.Type(Type t) does not handle UnionClassType
- Closed