test/langtools/tools/javac/multicatch/Neg07.java
author darcy
Fri, 02 Feb 2018 10:29:25 -0800
changeset 48723 6cb86bf0b51e
parent 47216 71c04702a3d5
permissions -rw-r--r--
8196623: Update JavaBaseTest.java to be version agnostic Reviewed-by: vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9596
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
     1
/*
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
     2
 * @test  /nodynamiccopyright/
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
     3
 * @bug 7039822
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
     4
 * @summary Verify typing of lub of exception parameter w.r.t getClass
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
     5
 * @author Joseph D. Darcy
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
     6
 * @compile/fail/ref=Neg07.out -XDrawDiagnostics Neg07.java
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
     7
 */
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
     8
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
     9
public class Neg07 {
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    10
    private static void test(int i) {
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    11
        try {
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    12
            thrower(i);
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    13
        } catch (SonException | DaughterException e) {
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    14
            Class<? extends HasFoo> clazz2 = e.getClass(); // Rejected!
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    15
            HasFoo m = e;
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    16
            e.foo();
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    17
        }
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    18
    }
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    19
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    20
    private static interface HasFoo {
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    21
        void foo();
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    22
    }
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    23
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    24
    static void thrower(int i) throws SonException, DaughterException {
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    25
        if (i == 0)
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    26
            throw new SonException();
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    27
        else
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    28
            throw new DaughterException();
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    29
    }
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    30
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    31
    private static class ParentException extends RuntimeException {}
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    32
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    33
    private static class SonException
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    34
        extends ParentException
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    35
        implements HasFoo {
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    36
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    37
        public void foo() {
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    38
            System.out.println("SonException.foo");
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    39
        }
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    40
    }
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    41
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    42
    private static class DaughterException
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    43
        extends ParentException
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    44
        implements HasFoo {
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    45
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    46
        public void foo() {
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    47
            System.out.println("DaughterException.foo");
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    48
        }
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    49
    }
9f318e729e2b 7039822: Project Coin: add explicit tests for the lub of an exception parameter
darcy
parents:
diff changeset
    50
}