diff --git a/src/share/classes/com/sun/tools/javac/code/Types.java b/src/share/classes/com/sun/tools/javac/code/Types.java index 5fc9d4547edd697734182fcb2867b6bd05c005c6..aac5c29f1a0419f1fe1226e9750db57f019a4994 100644 --- a/src/share/classes/com/sun/tools/javac/code/Types.java +++ b/src/share/classes/com/sun/tools/javac/code/Types.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -3600,39 +3600,44 @@ public class Types { @Override public Type visitCapturedType(CapturedType t, Void s) { - Type bound = visitWildcardType(t.wildcard, null); - return (bound.contains(t)) ? - erasure(bound) : - bound; + Type w_bound = t.wildcard.type; + Type bound = w_bound.contains(t) ? + erasure(w_bound) : + visit(w_bound); + return rewriteAsWildcardType(visit(bound), t.wildcard.bound, t.wildcard.kind); } @Override public Type visitTypeVar(TypeVar t, Void s) { if (rewriteTypeVars) { - Type bound = high ? - (t.bound.contains(t) ? + Type bound = t.bound.contains(t) ? erasure(t.bound) : - visit(t.bound)) : - syms.botType; - return rewriteAsWildcardType(bound, t); - } - else + visit(t.bound); + return rewriteAsWildcardType(bound, t, EXTENDS); + } else { return t; + } } @Override public Type visitWildcardType(WildcardType t, Void s) { - Type bound = high ? t.getExtendsBound() : - t.getSuperBound(); - if (bound == null) - bound = high ? syms.objectType : syms.botType; - return rewriteAsWildcardType(visit(bound), t.bound); - } - - private Type rewriteAsWildcardType(Type bound, TypeVar formal) { - return high ? - makeExtendsWildcard(B(bound), formal) : - makeSuperWildcard(B(bound), formal); + Type bound2 = visit(t.type); + return t.type == bound2 ? t : rewriteAsWildcardType(bound2, t.bound, t.kind); + } + + private Type rewriteAsWildcardType(Type bound, TypeVar formal, BoundKind bk) { + switch (bk) { + case EXTENDS: return high ? + makeExtendsWildcard(B(bound), formal) : + makeExtendsWildcard(syms.objectType, formal); + case SUPER: return high ? + makeSuperWildcard(syms.botType, formal) : + makeSuperWildcard(B(bound), formal); + case UNBOUND: return makeExtendsWildcard(syms.objectType, formal); + default: + Assert.error("Invalid bound kind " + bk); + return null; + } } Type B(Type t) { diff --git a/test/tools/javac/cast/7126754/T7126754.java b/test/tools/javac/cast/7126754/T7126754.java new file mode 100644 index 0000000000000000000000000000000000000000..79e49ecf23a2789bf2bb5921f7d75ffdeaa03910 --- /dev/null +++ b/test/tools/javac/cast/7126754/T7126754.java @@ -0,0 +1,14 @@ +/* + * @test /nodynamiccopyright/ + * @author mcimadamore + * @bug 7005671 + * @summary Generics compilation failure casting List to List + * @compile/fail/ref=T7126754.out -Xlint:unchecked -Werror -XDrawDiagnostics T7126754.java + */ + +import java.util.List; + +class T7126754 { + List> c = null; + List> d = (List>)c; +} diff --git a/test/tools/javac/cast/7126754/T7126754.out b/test/tools/javac/cast/7126754/T7126754.out new file mode 100644 index 0000000000000000000000000000000000000000..73baf16fe12b2706ca305aa245c3a23fe66cbbe3 --- /dev/null +++ b/test/tools/javac/cast/7126754/T7126754.out @@ -0,0 +1,4 @@ +T7126754.java:13:68: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.util.List>, java.util.List> +- compiler.err.warnings.and.werror +1 error +1 warning