test/langtools/tools/javac/warnings/FallThrough.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:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * @test  /nodynamiccopyright/
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * @bug 4986256
6150
d055fa8ced62 6971882: Remove -XDstdout from javac test
jjg
parents: 10
diff changeset
     4
 * @compile/ref=FallThrough.noLint.out                             -XDrawDiagnostics FallThrough.java
d055fa8ced62 6971882: Remove -XDstdout from javac test
jjg
parents: 10
diff changeset
     5
 * @compile/ref=FallThrough.lintAll.out         -Xlint:all,-path   -XDrawDiagnostics FallThrough.java
d055fa8ced62 6971882: Remove -XDstdout from javac test
jjg
parents: 10
diff changeset
     6
 * @compile/ref=FallThrough.lintFallThrough.out -Xlint:fallthrough -XDrawDiagnostics FallThrough.java
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
// control: this class should generate a warning
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
class FallThrough
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
{
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
    int m1(int i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
        switch (i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
        case 1: i++; case 2: i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
        return i;
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("fallthrough")
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
class FallThrough1
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
        switch (i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
        case 1: i++; case 2: i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
        return i;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
class FallThrough2
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
{
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
    @SuppressWarnings("fallthrough")
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
    class Bar {
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
        int m1(int i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
            switch (i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
            case 1: i++; case 2: i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
            return i;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
    @SuppressWarnings("fallthrough")
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    void m2(int i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
        switch (i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
        case 1: i++; case 2: i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    @SuppressWarnings("fallthrough")
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    static int x = new FallThrough2() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
            int m1(int i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
                switch (i) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
                case 1: i++; case 2: i++;
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
                return i;
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
        }.m1(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
}