6806876: ClassCastException occurs in assignment expressions without any heap pollutions

Tue, 11 Aug 2009 01:11:37 +0100

author
mcimadamore
date
Tue, 11 Aug 2009 01:11:37 +0100
changeset 356
d5f6c475f475
parent 355
961dc3acdb06
child 357
abe992640c5a

6806876: ClassCastException occurs in assignment expressions without any heap pollutions
Summary: intersection types should be considered as non-reifiable by javac
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/code/Types.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/resources/compiler.properties file | annotate | diff | comparison | revisions
test/tools/javac/varargs/6806876/T6806876.java file | annotate | diff | comparison | revisions
test/tools/javac/varargs/6806876/T6806876.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Sat Aug 08 17:56:37 2009 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Tue Aug 11 01:11:37 2009 +0100
     1.3 @@ -1247,14 +1247,18 @@
     1.4  
     1.5              @Override
     1.6              public Boolean visitClassType(ClassType t, Void ignored) {
     1.7 -                if (!t.isParameterized())
     1.8 +                if (t.isCompound())
     1.9 +                    return false;
    1.10 +                else {
    1.11 +                    if (!t.isParameterized())
    1.12 +                        return true;
    1.13 +
    1.14 +                    for (Type param : t.allparams()) {
    1.15 +                        if (!param.isUnbound())
    1.16 +                            return false;
    1.17 +                    }
    1.18                      return true;
    1.19 -
    1.20 -                for (Type param : t.allparams()) {
    1.21 -                    if (!param.isUnbound())
    1.22 -                        return false;
    1.23                  }
    1.24 -                return true;
    1.25              }
    1.26  
    1.27              @Override
     2.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Sat Aug 08 17:56:37 2009 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties	Tue Aug 11 01:11:37 2009 +0100
     2.3 @@ -761,7 +761,7 @@
     2.4      found: {3}
     2.5  
     2.6  compiler.warn.unchecked.generic.array.creation=\
     2.7 -    [unchecked] unchecked generic array creation of type {0} for varargs parameter
     2.8 +    [unchecked] unchecked generic array creation for varargs parameter of type {0}
     2.9  
    2.10  compiler.warn.missing.deprecated.annotation=\
    2.11      [dep-ann] deprecated item is not annotated with @Deprecated
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/varargs/6806876/T6806876.java	Tue Aug 11 01:11:37 2009 +0100
     3.3 @@ -0,0 +1,40 @@
     3.4 +/*
     3.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    3.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    3.24 + * have any questions.
    3.25 + */
    3.26 +
    3.27 +/*
    3.28 + * @test
    3.29 + * @bug     6806876
    3.30 + * @author mcimadamore
    3.31 + * @summary  ClassCastException occurs in assignment expressions without any heap pollutions
    3.32 + * @compile/fail/ref=T6806876.out -Xlint:unchecked -Werror -XDrawDiagnostics T6806876.java
    3.33 + */
    3.34 +
    3.35 +class T6806876 {
    3.36 +    void test(Integer i, Long l) {
    3.37 +        Comparable<?>[] res = m(i, l);
    3.38 +    }
    3.39 +
    3.40 +    <T> T[] m(T...a) {
    3.41 +        return null;
    3.42 +    }
    3.43 +}
    3.44 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/varargs/6806876/T6806876.out	Tue Aug 11 01:11:37 2009 +0100
     4.3 @@ -0,0 +1,4 @@
     4.4 +T6806876.java:34:32: compiler.warn.unchecked.generic.array.creation: java.lang.Number&java.lang.Comparable<? extends java.lang.Number&java.lang.Comparable<?>>[]
     4.5 +- compiler.err.warnings.and.werror
     4.6 +1 error
     4.7 +1 warning

mercurial