-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8u51, 9
-
x86
-
windows_8
FULL PRODUCT VERSION :
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
A DESCRIPTION OF THE PROBLEM :
The Java compiler fails to match the intersection type returned by the ternary operator with a compatible multiple catch statement when the result of the ternary operator is thrown.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Attempt to compile the code provided below (MultiCatchBug.java)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Successful compilation with no errors
ACTUAL -
MultiCatchBug.java:15: error: unreported exception INT#1; must be caught or declared to be thrown
throw b ? new E1() : new E2();
^
where INT#1 is an intersection type:
INT#1 extends Exception,I
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class MultiCatchBug {
public int compiles(boolean b) {
try {
if (b) {
throw new E1();
}
throw new E2();
} catch(E1 | E2 e) {
return -1;
}
}
public int failsToCompile(boolean b) {
try {
throw b ? new E1() : new E2();
} catch(E1 | E2 e) {
return -1;
}
}
private static interface I { }
private static class E1 extends Exception implements I { }
private static class E2 extends Exception implements I { }
}
---------- END SOURCE ----------
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
A DESCRIPTION OF THE PROBLEM :
The Java compiler fails to match the intersection type returned by the ternary operator with a compatible multiple catch statement when the result of the ternary operator is thrown.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Attempt to compile the code provided below (MultiCatchBug.java)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Successful compilation with no errors
ACTUAL -
MultiCatchBug.java:15: error: unreported exception INT#1; must be caught or declared to be thrown
throw b ? new E1() : new E2();
^
where INT#1 is an intersection type:
INT#1 extends Exception,I
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class MultiCatchBug {
public int compiles(boolean b) {
try {
if (b) {
throw new E1();
}
throw new E2();
} catch(E1 | E2 e) {
return -1;
}
}
public int failsToCompile(boolean b) {
try {
throw b ? new E1() : new E2();
} catch(E1 | E2 e) {
return -1;
}
}
private static interface I { }
private static class E1 extends Exception implements I { }
private static class E2 extends Exception implements I { }
}
---------- END SOURCE ----------