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

Subtle semantics changes for union types in cast conversion

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 9
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b92
    • Verification:
      Verified

      Backports

        Description

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

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved: