This commit is contained in:
Lana Steuck 2015-02-26 20:17:06 -08:00
commit 8d0e82310d
22 changed files with 436 additions and 98 deletions

@ -798,6 +798,10 @@ public abstract class Scope {
prependSubScope(new FilterImportScope(types, origin, null, filter, staticImport));
}
public boolean isFilled() {
return subScopes.nonEmpty();
}
}
public interface ImportFilter {

@ -477,6 +477,14 @@ public abstract class Type extends AnnoConstruct implements TypeMirror {
&& (tsym.flags() & COMPOUND) != 0;
}
public boolean isIntersection() {
return false;
}
public boolean isUnion() {
return false;
}
public boolean isInterface() {
return (tsym.flags() & INTERFACE) != 0;
}
@ -1079,6 +1087,11 @@ public abstract class Type extends AnnoConstruct implements TypeMirror {
return Collections.unmodifiableList(alternatives_field);
}
@Override
public boolean isUnion() {
return true;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.UNION;
@ -1125,6 +1138,11 @@ public abstract class Type extends AnnoConstruct implements TypeMirror {
return interfaces_field.prepend(supertype_field);
}
@Override
public boolean isIntersection() {
return true;
}
public List<Type> getExplicitComponents() {
return allInterfaces ?
interfaces_field :

@ -1402,8 +1402,7 @@ public class Types {
return isSameWildcard(t, s)
|| isCaptureOf(s, t)
|| ((t.isExtendsBound() || isSubtypeNoCapture(wildLowerBound(t), wildLowerBound(s))) &&
// TODO: JDK-8039214, cvarUpperBound call here is incorrect
(t.isSuperBound() || isSubtypeNoCapture(cvarUpperBound(wildUpperBound(s)), wildUpperBound(t))));
(t.isSuperBound() || isSubtypeNoCapture(wildUpperBound(s), wildUpperBound(t))));
}
}
@ -1517,8 +1516,8 @@ public class Types {
}
}
if (t.isCompound() || s.isCompound()) {
return !t.isCompound() ?
if (t.isIntersection() || s.isIntersection()) {
return !t.isIntersection() ?
visitIntersectionType((IntersectionClassType)s, t, true) :
visitIntersectionType((IntersectionClassType)t, s, false);
}
@ -2246,19 +2245,28 @@ public class Types {
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="makeCompoundType">
// <editor-fold defaultstate="collapsed" desc="makeIntersectionType">
/**
* Make a compound type from non-empty list of types. The list should be
* ordered according to {@link Symbol#precedes(TypeSymbol,Types)}.
* Make an intersection type from non-empty list of types. The list should be ordered according to
* {@link TypeSymbol#precedes(TypeSymbol, Types)}. Note that this might cause a symbol completion.
* Hence, this version of makeIntersectionType may not be called during a classfile read.
*
* @param bounds the types from which the compound type is formed
* @param supertype is objectType if all bounds are interfaces,
* null otherwise.
* @param bounds the types from which the intersection type is formed
*/
public Type makeCompoundType(List<Type> bounds) {
return makeCompoundType(bounds, bounds.head.tsym.isInterface());
public IntersectionClassType makeIntersectionType(List<Type> bounds) {
return makeIntersectionType(bounds, bounds.head.tsym.isInterface());
}
public Type makeCompoundType(List<Type> bounds, boolean allInterfaces) {
/**
* Make an intersection type from non-empty list of types. The list should be ordered according to
* {@link TypeSymbol#precedes(TypeSymbol, Types)}. This does not cause symbol completion as
* an extra parameter indicates as to whether all bounds are interfaces - in which case the
* supertype is implicitly assumed to be 'Object'.
*
* @param bounds the types from which the intersection type is formed
* @param allInterfaces are all bounds interface types?
*/
public IntersectionClassType makeIntersectionType(List<Type> bounds, boolean allInterfaces) {
Assert.check(bounds.nonEmpty());
Type firstExplicitBound = bounds.head;
if (allInterfaces) {
@ -2271,23 +2279,13 @@ public class Types {
: names.empty,
null,
syms.noSymbol);
bc.type = new IntersectionClassType(bounds, bc, allInterfaces);
IntersectionClassType intersectionType = new IntersectionClassType(bounds, bc, allInterfaces);
bc.type = intersectionType;
bc.erasure_field = (bounds.head.hasTag(TYPEVAR)) ?
syms.objectType : // error condition, recover
erasure(firstExplicitBound);
bc.members_field = WriteableScope.create(bc);
return bc.type;
}
/**
* A convenience wrapper for {@link #makeCompoundType(List)}; the
* arguments are converted to a list and passed to the other
* method. Note that this might cause a symbol completion.
* Hence, this version of makeCompoundType may not be called
* during a classfile read.
*/
public Type makeCompoundType(Type bound1, Type bound2) {
return makeCompoundType(List.of(bound1, bound2));
return intersectionType;
}
// </editor-fold>
@ -2427,7 +2425,7 @@ public class Types {
private final UnaryVisitor<List<Type>> directSupertypes = new UnaryVisitor<List<Type>>() {
public List<Type> visitType(final Type type, final Void ignored) {
if (!type.isCompound()) {
if (!type.isIntersection()) {
final Type sup = supertype(type);
return (sup == Type.noType || sup == type || sup == null)
? interfaces(type)
@ -2481,30 +2479,32 @@ public class Types {
// <editor-fold defaultstate="collapsed" desc="setBounds">
/**
* Set the bounds field of the given type variable to reflect a
* (possibly multiple) list of bounds.
* @param t a type variable
* @param bounds the bounds, must be nonempty
* @param supertype is objectType if all bounds are interfaces,
* null otherwise.
* Same as {@link Types#setBounds(TypeVar, List, boolean)}, except that third parameter is computed directly,
* as follows: if all all bounds are interface types, the computed supertype is Object,otherwise
* the supertype is simply left null (in this case, the supertype is assumed to be the head of
* the bound list passed as second argument). Note that this check might cause a symbol completion.
* Hence, this version of setBounds may not be called during a classfile read.
*
* @param t a type variable
* @param bounds the bounds, must be nonempty
*/
public void setBounds(TypeVar t, List<Type> bounds) {
setBounds(t, bounds, bounds.head.tsym.isInterface());
}
/**
* Same as {@link #setBounds(Type.TypeVar,List,Type)}, except that
* third parameter is computed directly, as follows: if all
* all bounds are interface types, the computed supertype is Object,
* otherwise the supertype is simply left null (in this case, the supertype
* is assumed to be the head of the bound list passed as second argument).
* Note that this check might cause a symbol completion. Hence, this version of
* setBounds may not be called during a classfile read.
* Set the bounds field of the given type variable to reflect a (possibly multiple) list of bounds.
* This does not cause symbol completion as an extra parameter indicates as to whether all bounds
* are interfaces - in which case the supertype is implicitly assumed to be 'Object'.
*
* @param t a type variable
* @param bounds the bounds, must be nonempty
* @param allInterfaces are all bounds interface types?
*/
public void setBounds(TypeVar t, List<Type> bounds, boolean allInterfaces) {
t.bound = bounds.tail.isEmpty() ?
bounds.head :
makeCompoundType(bounds, allInterfaces);
makeIntersectionType(bounds, allInterfaces);
t.rank_field = -1;
}
// </editor-fold>
@ -3036,7 +3036,7 @@ public class Types {
if (st == supertype(t) && is == interfaces(t))
return t;
else
return makeCompoundType(is.prepend(st));
return makeIntersectionType(is.prepend(st));
}
}
@ -3545,7 +3545,7 @@ public class Types {
else if (compound.tail.isEmpty())
return compound.head;
else
return makeCompoundType(compound);
return makeIntersectionType(compound);
}
/**
@ -3723,8 +3723,8 @@ public class Types {
synchronized (this) {
if (arraySuperType == null) {
// JLS 10.8: all arrays implement Cloneable and Serializable.
arraySuperType = makeCompoundType(List.of(syms.serializableType,
syms.cloneableType), true);
arraySuperType = makeIntersectionType(List.of(syms.serializableType,
syms.cloneableType), true);
}
}
}
@ -3790,7 +3790,7 @@ public class Types {
return glbFlattened(union(bounds, lowers), errT);
}
}
return makeCompoundType(bounds);
return makeIntersectionType(bounds);
}
// </editor-fold>

@ -2355,7 +2355,7 @@ public class Attr extends JCTree.Visitor {
@Override
public Type visitClassType(ClassType t, DiagnosticPosition pos) {
return t.isCompound() ?
return t.isIntersection() ?
visitIntersectionClassType((IntersectionClassType)t, pos) : t;
}
@ -2386,8 +2386,7 @@ public class Attr extends JCTree.Visitor {
}
supertypes.append(i.tsym.type);
}
IntersectionClassType notionalIntf =
(IntersectionClassType)types.makeCompoundType(supertypes.toList());
IntersectionClassType notionalIntf = types.makeIntersectionType(supertypes.toList());
notionalIntf.allparams_field = targs.toList();
notionalIntf.tsym.flags_field |= INTERFACE;
return notionalIntf.tsym;
@ -3947,7 +3946,7 @@ public class Attr extends JCTree.Visitor {
} else if (bounds.length() == 1) {
return bounds.head.type;
} else {
Type owntype = types.makeCompoundType(TreeInfo.types(bounds));
Type owntype = types.makeIntersectionType(TreeInfo.types(bounds));
// ... the variable's bound is a class type flagged COMPOUND
// (see comment for TypeVar.bound).
// In this case, generate a class tree that represents the

@ -3528,7 +3528,7 @@ public class Check {
for (Symbol sym : tsym.members().getSymbolsByName(name)) {
if (sym.isStatic() &&
staticImportAccessible(sym, packge) &&
importAccessible(sym, packge) &&
sym.isMemberOf(origin, types)) {
return true;
}
@ -3538,17 +3538,23 @@ public class Check {
}
// is the sym accessible everywhere in packge?
public boolean staticImportAccessible(Symbol sym, PackageSymbol packge) {
int flags = (int)(sym.flags() & AccessFlags);
switch (flags) {
default:
case PUBLIC:
return true;
case PRIVATE:
public boolean importAccessible(Symbol sym, PackageSymbol packge) {
try {
int flags = (int)(sym.flags() & AccessFlags);
switch (flags) {
default:
case PUBLIC:
return true;
case PRIVATE:
return false;
case 0:
case PROTECTED:
return sym.packge() == packge;
}
} catch (ClassFinder.BadClassFile err) {
throw err;
} catch (CompletionFailure ex) {
return false;
case 0:
case PROTECTED:
return sym.packge() == packge;
}
}

@ -417,7 +417,7 @@ public class Infer {
List<Type> upperBounds = uv.getBounds(InferenceBound.UPPER);
if (Type.containsAny(upperBounds, vars)) {
TypeSymbol fresh_tvar = new TypeVariableSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner);
fresh_tvar.type = new TypeVar(fresh_tvar, types.makeCompoundType(uv.getBounds(InferenceBound.UPPER)), null);
fresh_tvar.type = new TypeVar(fresh_tvar, types.makeIntersectionType(uv.getBounds(InferenceBound.UPPER)), null);
todo.append(uv);
uv.inst = fresh_tvar.type;
} else if (upperBounds.nonEmpty()) {
@ -670,7 +670,7 @@ public class Infer {
if (lubResult == syms.errType || lubResult == syms.botType) {
return List.nil();
}
List<Type> supertypesToCheck = lubResult.isCompound() ?
List<Type> supertypesToCheck = lubResult.isIntersection() ?
((IntersectionClassType)lubResult).getComponents() :
List.of(lubResult);
ListBuffer<Pair<Type, Type>> commonSupertypes = new ListBuffer<>();

@ -1667,7 +1667,7 @@ public class LambdaToMethod extends TreeTranslator {
* This class is used to store important information regarding translation of
* lambda expression/method references (see subclasses).
*/
private abstract class TranslationContext<T extends JCFunctionalExpression> {
abstract class TranslationContext<T extends JCFunctionalExpression> {
/** the underlying (untranslated) tree */
final T tree;
@ -1746,7 +1746,7 @@ public class LambdaToMethod extends TreeTranslator {
* and the used by the main translation routines in order to adjust references
* to captured locals/members, etc.
*/
private class LambdaTranslationContext extends TranslationContext<JCLambda> {
class LambdaTranslationContext extends TranslationContext<JCLambda> {
/** variable in the enclosing context to which this lambda is assigned */
final Symbol self;
@ -2040,7 +2040,7 @@ public class LambdaToMethod extends TreeTranslator {
* and the used by the main translation routines in order to adjust method
* references (i.e. in case a bridge is needed)
*/
private final class ReferenceTranslationContext extends TranslationContext<JCMemberReference> {
final class ReferenceTranslationContext extends TranslationContext<JCMemberReference> {
final boolean isSuper;
final Symbol sigPolySym;

@ -1098,10 +1098,17 @@ public class Resolve {
DeferredType.SpeculativeCache.Entry e =
dt.speculativeCache.get(deferredAttrContext.msym, deferredAttrContext.phase);
if (e != null && e.speculativeTree != deferredAttr.stuckTree) {
return functionalInterfaceMostSpecific(found, req, e.speculativeTree, warn);
return functionalInterfaceMostSpecific(found, req, e.speculativeTree);
}
}
return super.compatible(found, req, warn);
return compatibleBySubtyping(found, req);
}
private boolean compatibleBySubtyping(Type found, Type req) {
if (!strict && found.isPrimitive() != req.isPrimitive()) {
found = found.isPrimitive() ? types.boxedClass(found).type : types.unboxedType(found);
}
return types.isSubtypeNoCapture(found, deferredAttrContext.inferenceContext.asUndetVar(req));
}
/** Whether {@code t} and {@code s} are unrelated functional interface types. */
@ -1113,8 +1120,8 @@ public class Resolve {
}
/** Parameters {@code t} and {@code s} are unrelated functional interface types. */
private boolean functionalInterfaceMostSpecific(Type t, Type s, JCTree tree, Warner warn) {
FunctionalInterfaceMostSpecificChecker msc = new FunctionalInterfaceMostSpecificChecker(t, s, warn);
private boolean functionalInterfaceMostSpecific(Type t, Type s, JCTree tree) {
FunctionalInterfaceMostSpecificChecker msc = new FunctionalInterfaceMostSpecificChecker(t, s);
msc.scan(tree);
return msc.result;
}
@ -1127,14 +1134,12 @@ public class Resolve {
final Type t;
final Type s;
final Warner warn;
boolean result;
/** Parameters {@code t} and {@code s} are unrelated functional interface types. */
FunctionalInterfaceMostSpecificChecker(Type t, Type s, Warner warn) {
FunctionalInterfaceMostSpecificChecker(Type t, Type s) {
this.t = t;
this.s = s;
this.warn = warn;
result = true;
}
@ -1172,7 +1177,7 @@ public class Resolve {
result &= (retValIsPrimitive == ret_t.isPrimitive()) &&
(retValIsPrimitive != ret_s.isPrimitive());
} else {
result &= MostSpecificCheckContext.super.compatible(ret_t, ret_s, warn);
result &= compatibleBySubtyping(ret_t, ret_s);
}
}
}
@ -1195,7 +1200,7 @@ public class Resolve {
result &= false;
} else if (unrelatedFunctionalInterfaces(ret_t, ret_s)) {
for (JCExpression expr : lambdaResults(tree)) {
result &= functionalInterfaceMostSpecific(ret_t, ret_s, expr, warn);
result &= functionalInterfaceMostSpecific(ret_t, ret_s, expr);
}
} else if (ret_t.isPrimitive() != ret_s.isPrimitive()) {
for (JCExpression expr : lambdaResults(tree)) {
@ -1204,7 +1209,7 @@ public class Resolve {
(retValIsPrimitive != ret_s.isPrimitive());
}
} else {
result &= MostSpecificCheckContext.super.compatible(ret_t, ret_s, warn);
result &= compatibleBySubtyping(ret_t, ret_s);
}
}
}

@ -764,7 +764,7 @@ public class TransTypes extends TreeTranslator {
? typeCast.expr
: newExpression;
}
if (originalTarget.isCompound()) {
if (originalTarget.isIntersection()) {
Type.IntersectionClassType ict = (Type.IntersectionClassType)originalTarget;
for (Type c : ict.getExplicitComponents()) {
Type ec = erasure(c);

@ -160,7 +160,7 @@ public class TypeEnter implements Completer {
// if there remain any unimported toplevels (these must have
// no classes at all), process their import statements as well.
for (JCCompilationUnit tree : trees) {
if (tree.starImportScope.isEmpty()) {
if (!tree.starImportScope.isFilled()) {
Env<AttrContext> topEnv = enter.topLevelEnv(tree);
finishImports(tree, () -> { completeClass.resolveImports(tree, topEnv); });
}
@ -280,12 +280,7 @@ public class TypeEnter implements Completer {
Env<AttrContext> env;
ImportFilter staticImportFilter;
ImportFilter typeImportFilter = new ImportFilter() {
@Override
public boolean accepts(Scope origin, Symbol t) {
return t.kind == TYP;
}
};
ImportFilter typeImportFilter;
@Override
protected void doRunPhase(Env<AttrContext> env) {
@ -304,26 +299,26 @@ public class TypeEnter implements Completer {
}
private void resolveImports(JCCompilationUnit tree, Env<AttrContext> env) {
if (!tree.starImportScope.isEmpty()) {
if (tree.starImportScope.isFilled()) {
// we must have already processed this toplevel
return;
}
ImportFilter prevStaticImportFilter = staticImportFilter;
ImportFilter prevTypeImportFilter = typeImportFilter;
DiagnosticPosition prevLintPos = deferredLintHandler.immediate();
Lint prevLint = chk.setLint(lint);
Env<AttrContext> prevEnv = this.env;
try {
this.env = env;
final PackageSymbol packge = env.toplevel.packge;
this.staticImportFilter = new ImportFilter() {
@Override
public boolean accepts(Scope origin, Symbol sym) {
return sym.isStatic() &&
chk.staticImportAccessible(sym, packge) &&
sym.isMemberOf((TypeSymbol) origin.owner, types);
}
};
this.staticImportFilter =
(origin, sym) -> sym.isStatic() &&
chk.importAccessible(sym, packge) &&
sym.isMemberOf((TypeSymbol) origin.owner, types);
this.typeImportFilter =
(origin, sym) -> sym.kind == TYP &&
chk.importAccessible(sym, packge);
// Import-on-demand java.lang.
importAll(tree.pos, syms.enterPackage(names.java_lang), env);
@ -340,6 +335,7 @@ public class TypeEnter implements Completer {
chk.setLint(prevLint);
deferredLintHandler.setPos(prevLintPos);
this.staticImportFilter = prevStaticImportFilter;
this.typeImportFilter = prevTypeImportFilter;
}
}

@ -687,7 +687,6 @@ sun.rmi.server.*: proprietary compact2
sun.rmi.transport.*: proprietary compact2
sun.rmi.transport.proxy.*: proprietary compact2
sun.rmi.transport.tcp.*: proprietary compact2
sun.security.acl.*: proprietary compact1
sun.security.action.*: proprietary compact1
sun.security.jca.*: proprietary compact1
sun.security.jgss.*: proprietary compact3

@ -532,7 +532,6 @@ sun.rmi.server = tiger legacy
sun.rmi.transport = tiger legacy
sun.rmi.transport.proxy = tiger legacy
sun.rmi.transport.tcp = tiger legacy
sun.security.acl = tiger legacy
sun.security.action = tiger legacy
sun.security.jca = tiger legacy
sun.security.jgss = tiger legacy

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2015, 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
@ -382,8 +382,9 @@ public class RootDocImpl extends DocImpl implements RootDoc {
}
public boolean isFunctionalInterface(AnnotationDesc annotationDesc) {
return annotationDesc.annotationType().qualifiedName().equals(
env.syms.functionalInterfaceType.toString()) && env.source.allowLambda();
return env.source.allowLambda()
&& annotationDesc.annotationType().qualifiedName().equals(
env.syms.functionalInterfaceType.toString());
}
public boolean showTagMessages() {

@ -0,0 +1,42 @@
/*
* Copyright (c) 2014, 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
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8039214
* @summary Capture variable as an inference variable's lower bound
* @compile CaptureLowerBound.java
*/
public class CaptureLowerBound {
interface I<X1,X2> {}
static class C<T> implements I<T,T> {}
<X> void m(I<? extends X, X> arg) {}
void test(C<?> arg) {
m(arg);
}
}

@ -0,0 +1,19 @@
/*
* @test /nodynamiccopyright/
* @bug 8039214
* @summary Capture variable as an inference variable's lower bound
* @compile/fail/ref=CaptureLowerBoundNeg.out -XDrawDiagnostics CaptureLowerBoundNeg.java
*/
public class CaptureLowerBoundNeg {
static class D<T> {
void take(T arg) {}
static <T> D<T> make(Class<? extends T> c) { return new D<T>(); }
}
void test(Object o) {
D.make(o.getClass()).take(o);
}
}

@ -0,0 +1,2 @@
CaptureLowerBoundNeg.java:16:29: compiler.err.cant.apply.symbol: kindname.method, take, compiler.misc.type.captureof: 1, ? extends java.lang.Object, java.lang.Object, kindname.class, CaptureLowerBoundNeg.D<T>, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.Object, compiler.misc.type.captureof: 1, ? extends java.lang.Object))
1 error

@ -0,0 +1,44 @@
/*
* Copyright (c) 2014, 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
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8039214
* @summary Capture variable passed through multiple levels of nested inference
* @compile NestedCapture.java
*/
abstract class NestedCapture {
interface List<T> {}
abstract <T> List<T> copyOf(List<? extends T> lx);
abstract <E> List<E> filter(List<E> lx);
<U> void test1(List<U> lx) {
copyOf(filter(lx));
}
void test2(List<?> lx) {
copyOf(filter(lx));
}
}

@ -0,0 +1,44 @@
/*
* Copyright (c) 2014, 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
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8039214
* @summary Nested generic methods that work on wildcard-parameterized types
* @compile NestedWildcards.java
*/
public class NestedWildcards {
public static void test(Box<String> b) {
foo(bar(b));
}
private static <X> Box<? extends X> foo(Box<? extends X> ts) {
return null;
}
public static <Y> Box<? extends Y> bar(Box<? extends Y> language) {
return null;
}
interface Box<T> {}
}

@ -0,0 +1,72 @@
/*
* Copyright (c) 2014, 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
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8039214
* @summary Capture variables used for subtyping should not leak out of inference
* @compile SubtypeCaptureLeak.java
*/
public class SubtypeCaptureLeak {
interface Parent<T> {}
interface Child<T> extends Parent<T> {}
interface Box<T> {}
interface SubBox<T> extends Box<T> {}
// applicability inference
<T> void m1(Parent<? extends T> arg) {}
void testApplicable(Child<?> arg) {
m1(arg);
}
// applicability inference, nested
<T> void m2(Box<? extends Parent<? extends T>> arg) {}
void testApplicable(Box<Child<?>> arg) {
m2(arg);
}
// most specific inference
<T> void m3(Parent<? extends T> arg) {}
void m3(Child<?> arg) {}
void testMostSpecific(Child<?> arg) {
m3(arg);
}
// most specific inference, nested
<T> void m4(Box<? extends Parent<? extends T>> arg) {}
void m4(SubBox<Child<?>> arg) {}
void testMostSpecificNested(SubBox<Child<?>> arg) {
m4(arg);
}
}

@ -0,0 +1,37 @@
/*
* Copyright (c) 2014, 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
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8067886
* @summary Verify that type import on demand won't put inaccessible types into the Scope
* @compile/fail/ref=ImportInaccessible.out -XDrawDiagnostics ImportInaccessible.java
*/
package p;
import p.ImportInaccessible.Nested.*;
class ImportInaccessible {
static class Nested<X extends Inner> {
private static class Inner{}
}
}

@ -0,0 +1,2 @@
ImportInaccessible.java:34:35: compiler.err.cant.resolve.location: kindname.class, Inner, , , (compiler.misc.location: kindname.class, p.ImportInaccessible, null)
1 error

@ -0,0 +1,49 @@
/*
* Copyright (c) 2015, 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
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8071291
* @summary Compiler crashes trying to cast UnionType to IntersectionClassType
* @compile T8071291.java
*/
class T8071291 {
interface A { }
class Exception1 extends Exception implements A { }
class Exception2 extends Exception implements A { }
void test(boolean cond) {
try {
if (cond) {
throw new Exception1();
} else {
throw new Exception2();
}
}
catch (Exception1|Exception2 x) {
if (x instanceof Exception1) { }
}
}
}