test/tools/javac/T6227617.java

changeset 1
9a66ca7c79fa
child 611
4172cfff05f0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/T6227617.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,37 @@
     1.4 +/*
     1.5 + * @test  /nodynamiccopyright/
     1.6 + * @bug 6227617
     1.7 + * @summary Lint option for redundant casts
     1.8 + * @compile -Werror T6227617.java
     1.9 + * @compile/ref=T6227617.out -XDstdout -XDrawDiagnostics -Xlint:cast T6227617.java
    1.10 + */
    1.11 +import java.util.HashMap;
    1.12 +import java.util.Map;
    1.13 +
    1.14 +class T6227617 {
    1.15 +    void m() {
    1.16 +        int i1 = 2;
    1.17 +        int i2 = (int) i1;  // warn
    1.18 +
    1.19 +        float f1 = 1f;
    1.20 +        int i3 = (int) f1;
    1.21 +
    1.22 +        String s = (String) ""; // warn
    1.23 +        Object o = (Object) "";
    1.24 +
    1.25 +        Map<String, Integer> m = new HashMap<String, Integer>();
    1.26 +        Integer I1 = (Integer) m.get(""); // warn
    1.27 +    }
    1.28 +
    1.29 +    // The following cause NPE in Attr with an Attr-based solution for -Xlint:cast
    1.30 +    static final int i1 = Foo.i1;
    1.31 +    static final String s = Foo.s;
    1.32 +}
    1.33 +
    1.34 +class Foo
    1.35 +{
    1.36 +    static final int i1 = (int) 1;
    1.37 +    static final int i2 = (int) 1L;
    1.38 +
    1.39 +    static final String s = (String) "abc";
    1.40 +}

mercurial