test/langtools/tools/javac/warnings/Unchecked.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=Unchecked.noLint.out                         -XDrawDiagnostics Unchecked.java
d055fa8ced62 6971882: Remove -XDstdout from javac test
jjg
parents: 10
diff changeset
     5
 * @compile/ref=Unchecked.lintUnchecked.out -Xlint:unchecked -XDrawDiagnostics Unchecked.java
d055fa8ced62 6971882: Remove -XDstdout from javac test
jjg
parents: 10
diff changeset
     6
 * @compile/ref=Unchecked.lintAll.out       -Xlint:all,-path -XDrawDiagnostics Unchecked.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
import java.util.ArrayList;
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
import java.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
// control: this class should generate warnings
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
class Unchecked
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
{
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
    void m() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
        List l = new ArrayList<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
        l.add("abc");
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
// tests: the warnings that would otherwise be generated should all be suppressed
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
@SuppressWarnings("unchecked")
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
class Unchecked2
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
{
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
    void m() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
        List l = new ArrayList<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
        l.add("abc");
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
class Unchecked3
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
{
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
    @SuppressWarnings("unchecked")
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
    void m() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
        List l = new ArrayList<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
        l.add("abc");
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
class Unchecked4
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
{
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
    void m() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
        @SuppressWarnings("unchecked")
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
            class Inner {
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
                void m() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
                    List l = new ArrayList<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
                    l.add("abc");
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
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
// this class should produce warnings because @SuppressWarnings should not be inherited
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
class Unchecked5 extends Unchecked2
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
{
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    void m() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
        List l = new ArrayList<String>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        l.add("abc");
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
}