7034511: Loophole in typesafety

Tue, 12 Apr 2011 20:56:16 -0700

author
mcimadamore
date
Tue, 12 Apr 2011 20:56:16 -0700
changeset 970
f00986f55961
parent 969
8cc5b440fdde
child 971
bfbc197b560f

7034511: Loophole in typesafety
Summary: Type-variable substutution takes upper bound of replaced captured type-variable
Reviewed-by: dlsmith

src/share/classes/com/sun/tools/javac/code/Types.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/7034511/T7034511a.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/7034511/T7034511a.out file | annotate | diff | comparison | revisions
test/tools/javac/generics/7034511/T7034511b.java file | annotate | diff | comparison | revisions
test/tools/javac/generics/7034511/T7034511b.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Wed Apr 06 19:30:57 2011 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Tue Apr 12 20:56:16 2011 -0700
     1.3 @@ -2309,7 +2309,7 @@
     1.4              if (elemtype == t.elemtype)
     1.5                  return t;
     1.6              else
     1.7 -                return new ArrayType(upperBound(elemtype), t.tsym);
     1.8 +                return new ArrayType(elemtype, t.tsym);
     1.9          }
    1.10  
    1.11          @Override
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/generics/7034511/T7034511a.java	Tue Apr 12 20:56:16 2011 -0700
     2.3 @@ -0,0 +1,21 @@
     2.4 +/*
     2.5 + * @test /nodynamiccopyright/
     2.6 + * @bug     7034511
     2.7 + * @summary Loophole in typesafety
     2.8 + * @compile/fail/ref=T7034511a.out -XDrawDiagnostics T7034511a.java
     2.9 + */
    2.10 +
    2.11 +class T7034511a {
    2.12 +
    2.13 +    interface A<T> {
    2.14 +        void foo(T x);
    2.15 +    }
    2.16 +
    2.17 +    interface B<T> extends A<T[]> { }
    2.18 +
    2.19 +    static abstract class C implements B<Integer> {
    2.20 +        <T extends B<?>> void test(T x, String[] ss) {
    2.21 +            x.foo(ss);
    2.22 +        }
    2.23 +    }
    2.24 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/generics/7034511/T7034511a.out	Tue Apr 12 20:56:16 2011 -0700
     3.3 @@ -0,0 +1,2 @@
     3.4 +T7034511a.java:18:14: compiler.err.cant.apply.symbol.1: kindname.method, foo, compiler.misc.type.captureof: 1, ?[], java.lang.String[], kindname.interface, T7034511a.A<T>, (compiler.misc.no.conforming.assignment.exists: java.lang.String[], compiler.misc.type.captureof: 1, ?[])
     3.5 +1 error
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/generics/7034511/T7034511b.java	Tue Apr 12 20:56:16 2011 -0700
     4.3 @@ -0,0 +1,16 @@
     4.4 +/*
     4.5 + * @test /nodynamiccopyright/
     4.6 + * @bug     7034511
     4.7 + * @summary Loophole in typesafety
     4.8 + * @compile/fail/ref=T7034511b.out -XDrawDiagnostics T7034511b.java
     4.9 + */
    4.10 +
    4.11 +class T7034511b {
    4.12 +    static class MyList<E> {
    4.13 +        E toArray(E[] e) { return null; }
    4.14 +    }
    4.15 +
    4.16 +    void test(MyList<?> ml, Object o[]) {
    4.17 +        ml.toArray(o);
    4.18 +    }
    4.19 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/generics/7034511/T7034511b.out	Tue Apr 12 20:56:16 2011 -0700
     5.3 @@ -0,0 +1,2 @@
     5.4 +T7034511b.java:14:11: compiler.err.cant.apply.symbol.1: kindname.method, toArray, compiler.misc.type.captureof: 1, ?[], java.lang.Object[], kindname.class, T7034511b.MyList<E>, (compiler.misc.no.conforming.assignment.exists: java.lang.Object[], compiler.misc.type.captureof: 1, ?[])
     5.5 +1 error

mercurial