langtools/test/tools/javac/DefiniteAssignment/DefAssignAfterTry2.java
author sogoel
Fri, 05 Sep 2014 16:43:00 -0700
changeset 26528 a1a7ad15183e
parent 25308 190cac01c316
permissions -rw-r--r--
8055075: Group 9b: golden files for tests in tools/javac dir Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
25308
190cac01c316 8044236: create .out files for DefiniteAssignment tests in tools/javac dir
sogoel
parents: 5520
diff changeset
     2
 * @test /nodynamiccopyright/
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * @bug 4240487
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 * @summary Verify that we keep track of init/uninits in Try statement
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * without finalizer.
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 *
25308
190cac01c316 8044236: create .out files for DefiniteAssignment tests in tools/javac dir
sogoel
parents: 5520
diff changeset
     7
 * @compile/fail/ref=DefAssignAfterTry2.out -XDrawDiagnostics  DefAssignAfterTry2.java
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
class E1 extends Exception {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
class E2 extends Exception {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
public class DefAssignAfterTry2 {
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
    public static void main(String argv[]) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
        boolean t = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
        E1 se1 = new E1();
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
        E2 se2 = new E2();
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
        int i;
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
            if (t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
                i = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
                throw se1;
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
                throw se2;
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
        } catch (E1 e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
        } catch (E2 e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
            i = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
        // the following line should result in a compile-time error
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
        // variable i may not have been initialized
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
        System.out.println(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
        System.out.println("Error : there should be compile-time errors");
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
}