Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8141343

Subtle semantics changes for union types in cast conversion

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • None
    • tools
    • b92
    • Verified

        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).

              mcimadamore Maurizio Cimadamore
              mcimadamore Maurizio Cimadamore
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: