JDK-8141343 : Subtle semantics changes for union types in cast conversion
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2015-11-03
  • Updated: 2016-01-06
  • Resolved: 2015-11-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
9 b92Fixed
Related Reports
Relates :  
Following the fix for JDK-8071291, some operations for union types started to behave strangely; for instance the following code should be rejected by javac:

interface Foo<X> { }

class A extends Exception implements Foo<A> { }
class B extends Exception implements Foo<B> { }

interface D { }

class Test {
	<Z> void test(boolean cond) {
		try {
			if (cond) {         
				throw new A();
			} else {
				throw new B();
		} catch (A | B ex) {
                         Foo<Integer> fa = (Foo<Integer>)ex;

Following the fix, this code started to pass (this was failing in JDK 7 and was crashing in 8).