6594284: NPE thrown when calling a method on an intersection type
Javac should report an error when the capture of an actual type parameter does not exist Reviewed-by: jjg
This commit is contained in:
parent
fec04e0a18
commit
9879011723
@ -979,6 +979,10 @@ public class Type implements PrimitiveType {
|
||||
return TypeKind.TYPEVAR;
|
||||
}
|
||||
|
||||
public boolean isCaptured() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
|
||||
return v.visitTypeVariable(this, p);
|
||||
}
|
||||
@ -1014,6 +1018,11 @@ public class Type implements PrimitiveType {
|
||||
return lower;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCaptured() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "capture#"
|
||||
|
@ -835,7 +835,7 @@ public class Types {
|
||||
};
|
||||
|
||||
public boolean isCaptureOf(Type s, WildcardType t) {
|
||||
if (s.tag != TYPEVAR || !(s instanceof CapturedType))
|
||||
if (s.tag != TYPEVAR || !((TypeVar)s).isCaptured())
|
||||
return false;
|
||||
return isSameWildcard(t, ((CapturedType)s).wildcard);
|
||||
}
|
||||
|
@ -422,7 +422,34 @@ public class Check {
|
||||
* @param bs The bound.
|
||||
*/
|
||||
private void checkExtends(DiagnosticPosition pos, Type a, TypeVar bs) {
|
||||
if (!(a instanceof CapturedType)) {
|
||||
if (a.tag == TYPEVAR && ((TypeVar)a).isCaptured()) {
|
||||
CapturedType ct = (CapturedType)a;
|
||||
boolean ok;
|
||||
if (ct.bound.isErroneous()) {//capture doesn't exist
|
||||
ok = false;
|
||||
}
|
||||
else {
|
||||
switch (ct.wildcard.kind) {
|
||||
case EXTENDS:
|
||||
ok = types.isCastable(bs.getUpperBound(),
|
||||
types.upperBound(a),
|
||||
Warner.noWarnings);
|
||||
break;
|
||||
case SUPER:
|
||||
ok = !types.notSoftSubtype(types.lowerBound(a),
|
||||
bs.getUpperBound());
|
||||
break;
|
||||
case UNBOUND:
|
||||
ok = true;
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Invalid bound kind");
|
||||
}
|
||||
}
|
||||
if (!ok)
|
||||
log.error(pos, "not.within.bounds", a);
|
||||
}
|
||||
else {
|
||||
a = types.upperBound(a);
|
||||
for (List<Type> l = types.getBounds(bs); l.nonEmpty(); l = l.tail) {
|
||||
if (!types.isSubtype(a, l.head)) {
|
||||
@ -431,25 +458,6 @@ public class Check {
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
CapturedType ct = (CapturedType)a;
|
||||
boolean ok = false;
|
||||
switch (ct.wildcard.kind) {
|
||||
case EXTENDS:
|
||||
ok = types.isCastable(bs.getUpperBound(),
|
||||
types.upperBound(a),
|
||||
Warner.noWarnings);
|
||||
break;
|
||||
case SUPER:
|
||||
ok = !types.notSoftSubtype(types.lowerBound(a),
|
||||
bs.getUpperBound());
|
||||
break;
|
||||
case UNBOUND:
|
||||
ok = true;
|
||||
}
|
||||
if (!ok)
|
||||
log.error(pos, "not.within.bounds", a);
|
||||
}
|
||||
}
|
||||
|
||||
/** Check that type is different from 'void'.
|
||||
|
43
langtools/test/tools/javac/capture/T6594284.java
Normal file
43
langtools/test/tools/javac/capture/T6594284.java
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2008 Sun Microsystems, Inc. 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6594284
|
||||
* @summary NPE thrown when calling a method on an intersection type
|
||||
* @author Maurizio Cimadamore
|
||||
*
|
||||
* @compile/fail T6594284.java
|
||||
*/
|
||||
|
||||
public class T6594284 {
|
||||
class A{ public void a(){}}
|
||||
class B extends A{ public void b(){}}
|
||||
interface I{ void i();}
|
||||
interface I1 { void i1(); }
|
||||
class E extends B implements I{ public void i(){};}
|
||||
|
||||
class C<W extends B & I1, T extends W>{
|
||||
C<? extends I, ? extends E> arg;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user