langtools/test/tools/javac/warnings/Finally.java
author sogoel
Fri, 10 Oct 2014 14:41:50 -0700
changeset 27119 b80b6a2e137f
parent 5520 86e4b9a9da40
permissions -rw-r--r--
8058410: Group 10b: 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
/*
27119
b80b6a2e137f 8058410: Group 10b: golden files for tests in tools/javac dir
sogoel
parents: 5520
diff changeset
     2
 * @test /nodynamiccopyright/
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * @bug 4986256
27119
b80b6a2e137f 8058410: Group 10b: golden files for tests in tools/javac dir
sogoel
parents: 5520
diff changeset
     4
 * @compile/ref=Finally.out -XDrawDiagnostics -Xlint:all Finally.java
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
// control: this class should generate a warning
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
class Finally
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
{
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
    int m1(int i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
            return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
        finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
            throw new IllegalArgumentException();
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
// tests: the warnings that would otherwise be generated should all be suppressed
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
@SuppressWarnings("finally")
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
class Finally1
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
{
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
    int m1(int i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
            return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
        finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
            throw new IllegalArgumentException();
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
class Finally2
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
{
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
    @SuppressWarnings("finally")
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
    class Bar {
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
        int m1(int i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
                return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
            finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
                throw new IllegalArgumentException();
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    @SuppressWarnings("finally")
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    int m2(int i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
            return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
        finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
            throw new IllegalArgumentException();
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    @SuppressWarnings("finally")
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    static int x = new Finally2() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
            int m1(int i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
                    return 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
                finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
                    throw new IllegalArgumentException();
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        }.m1(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
}