langtools/test/tools/javac/T6227617.java
author robm
Tue, 13 Sep 2016 14:47:29 +0100
changeset 40938 5b0977acc842
parent 6150 d055fa8ced62
permissions -rw-r--r--
6947916: JarURLConnection does not handle useCaches correctly Reviewed-by: chegar
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 6227617
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 * @summary Lint option for redundant casts
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * @compile -Werror T6227617.java
6150
d055fa8ced62 6971882: Remove -XDstdout from javac test
jjg
parents: 10
diff changeset
     6
 * @compile/ref=T6227617.out -XDrawDiagnostics -Xlint:cast T6227617.java
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
import java.util.HashMap;
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
import java.util.Map;
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
class T6227617 {
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
    void m() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
        int i1 = 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
        int i2 = (int) i1;  // warn
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
        float f1 = 1f;
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
        int i3 = (int) f1;
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
        String s = (String) ""; // warn
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
        Object o = (Object) "";
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
        Map<String, Integer> m = new HashMap<String, Integer>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
        Integer I1 = (Integer) m.get(""); // warn
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
    // The following cause NPE in Attr with an Attr-based solution for -Xlint:cast
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
    static final int i1 = Foo.i1;
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
    static final String s = Foo.s;
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 Foo
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
{
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
    static final int i1 = (int) 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
    static final int i2 = (int) 1L;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
    static final String s = (String) "abc";
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
}