Wed, 30 Apr 2014 23:59:45 -0700
Merge
test/tools/javac/lambda/ErroneousLambdaExpr.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/lambda/ErroneousLambdaExpr.out | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Extern.java Wed Apr 30 11:17:22 2014 -0700 1.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Extern.java Wed Apr 30 23:59:45 2014 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -177,7 +177,7 @@ 1.11 try { 1.12 url = adjustEndFileSeparator(url); 1.13 if (isUrl(pkglisturl)) { 1.14 - readPackageListFromURL(url, toURL(pkglisturl)); 1.15 + readPackageListFromURL(url, toURL(adjustEndFileSeparator(pkglisturl))); 1.16 } else { 1.17 readPackageListFromFile(url, DocFile.createFileForInput(configuration, pkglisturl)); 1.18 }
2.1 --- a/src/share/classes/com/sun/tools/javac/code/Source.java Wed Apr 30 11:17:22 2014 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/code/Source.java Wed Apr 30 23:59:45 2014 -0700 2.3 @@ -191,6 +191,9 @@ 2.4 public boolean allowObjectToPrimitiveCast() { 2.5 return compareTo(JDK1_7) >= 0; 2.6 } 2.7 + public boolean enforceThisDotInit() { 2.8 + return compareTo(JDK1_7) >= 0; 2.9 + } 2.10 public boolean allowPoly() { 2.11 return compareTo(JDK1_8) >= 0; 2.12 }
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Apr 30 11:17:22 2014 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Apr 30 23:59:45 2014 -0700 3.3 @@ -249,7 +249,7 @@ 3.4 if (!owntype.hasTag(ERROR) && !resultInfo.pt.hasTag(METHOD) && !resultInfo.pt.hasTag(FORALL)) { 3.5 if (allowPoly && inferenceContext.free(found)) { 3.6 if ((ownkind & ~resultInfo.pkind) == 0) { 3.7 - owntype = resultInfo.check(tree, inferenceContext.asFree(owntype)); 3.8 + owntype = resultInfo.check(tree, inferenceContext.asUndetVar(owntype)); 3.9 } else { 3.10 log.error(tree.pos(), "unexpected.type", 3.11 kindNames(resultInfo.pkind), 3.12 @@ -2402,7 +2402,7 @@ 3.13 //add thrown types as bounds to the thrown types free variables if needed: 3.14 if (resultInfo.checkContext.inferenceContext().free(lambdaType.getThrownTypes())) { 3.15 List<Type> inferredThrownTypes = flow.analyzeLambdaThrownTypes(env, that, make); 3.16 - List<Type> thrownTypes = resultInfo.checkContext.inferenceContext().asFree(lambdaType.getThrownTypes()); 3.17 + List<Type> thrownTypes = resultInfo.checkContext.inferenceContext().asUndetVars(lambdaType.getThrownTypes()); 3.18 3.19 chk.unhandled(inferredThrownTypes, thrownTypes); 3.20 } 3.21 @@ -2543,7 +2543,7 @@ 3.22 @Override 3.23 public boolean compatible(Type found, Type req, Warner warn) { 3.24 //return type must be compatible in both current context and assignment context 3.25 - return chk.basicHandler.compatible(found, inferenceContext().asFree(req), warn); 3.26 + return chk.basicHandler.compatible(found, inferenceContext().asUndetVar(req), warn); 3.27 } 3.28 3.29 @Override 3.30 @@ -2576,7 +2576,7 @@ 3.31 * types must be compatible with the return type of the expected descriptor. 3.32 */ 3.33 private void checkLambdaCompatible(JCLambda tree, Type descriptor, CheckContext checkContext) { 3.34 - Type returnType = checkContext.inferenceContext().asFree(descriptor.getReturnType()); 3.35 + Type returnType = checkContext.inferenceContext().asUndetVar(descriptor.getReturnType()); 3.36 3.37 //return values have already been checked - but if lambda has no return 3.38 //values, we must ensure that void/value compatibility is correct; 3.39 @@ -2588,7 +2588,7 @@ 3.40 diags.fragment("missing.ret.val", returnType))); 3.41 } 3.42 3.43 - List<Type> argTypes = checkContext.inferenceContext().asFree(descriptor.getParameterTypes()); 3.44 + List<Type> argTypes = checkContext.inferenceContext().asUndetVars(descriptor.getParameterTypes()); 3.45 if (!types.isSameTypes(argTypes, TreeInfo.types(tree.params))) { 3.46 checkContext.report(tree, diags.fragment("incompatible.arg.types.in.lambda")); 3.47 } 3.48 @@ -2618,7 +2618,7 @@ 3.49 * - an instance field, we use the first constructor. 3.50 * - a static field, we create a fake clinit method. 3.51 */ 3.52 - private Env<AttrContext> lambdaEnv(JCLambda that, Env<AttrContext> env) { 3.53 + public Env<AttrContext> lambdaEnv(JCLambda that, Env<AttrContext> env) { 3.54 Env<AttrContext> lambdaEnv; 3.55 Symbol owner = env.info.scope.owner; 3.56 if (owner.kind == VAR && owner.owner.kind == TYP) { 3.57 @@ -2832,7 +2832,7 @@ 3.58 if (that.kind.isUnbound() && 3.59 resultInfo.checkContext.inferenceContext().free(argtypes.head)) { 3.60 //re-generate inference constraints for unbound receiver 3.61 - if (!types.isSubtype(resultInfo.checkContext.inferenceContext().asFree(argtypes.head), exprType)) { 3.62 + if (!types.isSubtype(resultInfo.checkContext.inferenceContext().asUndetVar(argtypes.head), exprType)) { 3.63 //cannot happen as this has already been checked - we just need 3.64 //to regenerate the inference constraints, as that has been lost 3.65 //as a result of the call to inferenceContext.save() 3.66 @@ -2870,7 +2870,7 @@ 3.67 3.68 @SuppressWarnings("fallthrough") 3.69 void checkReferenceCompatible(JCMemberReference tree, Type descriptor, Type refType, CheckContext checkContext, boolean speculativeAttr) { 3.70 - Type returnType = checkContext.inferenceContext().asFree(descriptor.getReturnType()); 3.71 + Type returnType = checkContext.inferenceContext().asUndetVar(descriptor.getReturnType()); 3.72 3.73 Type resType; 3.74 switch (tree.getMode()) { 3.75 @@ -2902,7 +2902,7 @@ 3.76 } 3.77 3.78 if (!speculativeAttr) { 3.79 - List<Type> thrownTypes = checkContext.inferenceContext().asFree(descriptor.getThrownTypes()); 3.80 + List<Type> thrownTypes = checkContext.inferenceContext().asUndetVars(descriptor.getThrownTypes()); 3.81 if (chk.unhandled(refType.getThrownTypes(), thrownTypes).nonEmpty()) { 3.82 log.error(tree, "incompatible.thrown.types.in.mref", refType.getThrownTypes()); 3.83 }
4.1 --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Wed Apr 30 11:17:22 2014 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Wed Apr 30 23:59:45 2014 -0700 4.3 @@ -1,5 +1,5 @@ 4.4 /* 4.5 - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 4.6 + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. 4.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.8 * 4.9 * This code is free software; you can redistribute it and/or modify it 4.10 @@ -25,7 +25,7 @@ 4.11 4.12 package com.sun.tools.javac.comp; 4.13 4.14 -import com.sun.source.tree.MemberReferenceTree; 4.15 +import com.sun.source.tree.LambdaExpressionTree.BodyKind; 4.16 import com.sun.tools.javac.code.*; 4.17 import com.sun.tools.javac.tree.*; 4.18 import com.sun.tools.javac.util.*; 4.19 @@ -35,10 +35,8 @@ 4.20 import com.sun.tools.javac.comp.Attr.ResultInfo; 4.21 import com.sun.tools.javac.comp.Infer.InferenceContext; 4.22 import com.sun.tools.javac.comp.Resolve.MethodResolutionPhase; 4.23 -import com.sun.tools.javac.comp.Resolve.ReferenceLookupHelper; 4.24 import com.sun.tools.javac.tree.JCTree.*; 4.25 4.26 - 4.27 import java.util.ArrayList; 4.28 import java.util.Collections; 4.29 import java.util.EnumSet; 4.30 @@ -48,6 +46,7 @@ 4.31 import java.util.Set; 4.32 import java.util.WeakHashMap; 4.33 4.34 +import static com.sun.tools.javac.code.Kinds.VAL; 4.35 import static com.sun.tools.javac.code.TypeTag.*; 4.36 import static com.sun.tools.javac.tree.JCTree.Tag.*; 4.37 4.38 @@ -76,6 +75,8 @@ 4.39 final Symtab syms; 4.40 final TreeMaker make; 4.41 final Types types; 4.42 + final Flow flow; 4.43 + final Names names; 4.44 4.45 public static DeferredAttr instance(Context context) { 4.46 DeferredAttr instance = context.get(deferredAttrKey); 4.47 @@ -96,7 +97,8 @@ 4.48 syms = Symtab.instance(context); 4.49 make = TreeMaker.instance(context); 4.50 types = Types.instance(context); 4.51 - Names names = Names.instance(context); 4.52 + flow = Flow.instance(context); 4.53 + names = Names.instance(context); 4.54 stuckTree = make.Ident(names.empty).setType(Type.stuckType); 4.55 emptyDeferredAttrContext = 4.56 new DeferredAttrContext(AttrMode.CHECK, null, MethodResolutionPhase.BOX, infer.emptyContext, null, null) { 4.57 @@ -139,6 +141,11 @@ 4.58 return DEFERRED; 4.59 } 4.60 4.61 + @Override 4.62 + public String toString() { 4.63 + return "DeferredType"; 4.64 + } 4.65 + 4.66 /** 4.67 * A speculative cache is used to keep track of all overload resolution rounds 4.68 * that triggered speculative attribution on a given deferred type. Each entry 4.69 @@ -378,7 +385,9 @@ 4.70 } 4.71 } 4.72 //where 4.73 - protected TreeScanner unenterScanner = new TreeScanner() { 4.74 + protected UnenterScanner unenterScanner = new UnenterScanner(); 4.75 + 4.76 + class UnenterScanner extends TreeScanner { 4.77 @Override 4.78 public void visitClassDef(JCClassDecl tree) { 4.79 ClassSymbol csym = tree.sym; 4.80 @@ -391,7 +400,7 @@ 4.81 syms.classes.remove(csym.flatname); 4.82 super.visitClassDef(tree); 4.83 } 4.84 - }; 4.85 + } 4.86 4.87 /** 4.88 * A deferred context is created on each method check. A deferred context is 4.89 @@ -595,19 +604,111 @@ 4.90 public void visitLambda(JCLambda tree) { 4.91 Check.CheckContext checkContext = resultInfo.checkContext; 4.92 Type pt = resultInfo.pt; 4.93 - if (inferenceContext.inferencevars.contains(pt)) { 4.94 - //ok 4.95 - return; 4.96 - } else { 4.97 + if (!inferenceContext.inferencevars.contains(pt)) { 4.98 //must be a functional descriptor 4.99 + Type descriptorType = null; 4.100 try { 4.101 - Type desc = types.findDescriptorType(pt); 4.102 - if (desc.getParameterTypes().length() != tree.params.length()) { 4.103 - checkContext.report(tree, diags.fragment("incompatible.arg.types.in.lambda")); 4.104 - } 4.105 + descriptorType = types.findDescriptorType(pt); 4.106 } catch (Types.FunctionDescriptorLookupError ex) { 4.107 checkContext.report(null, ex.getDiagnostic()); 4.108 } 4.109 + 4.110 + if (descriptorType.getParameterTypes().length() != tree.params.length()) { 4.111 + checkContext.report(tree, 4.112 + diags.fragment("incompatible.arg.types.in.lambda")); 4.113 + } 4.114 + 4.115 + Type currentReturnType = descriptorType.getReturnType(); 4.116 + boolean returnTypeIsVoid = currentReturnType.hasTag(VOID); 4.117 + if (tree.getBodyKind() == BodyKind.EXPRESSION) { 4.118 + boolean isExpressionCompatible = !returnTypeIsVoid || 4.119 + TreeInfo.isExpressionStatement((JCExpression)tree.getBody()); 4.120 + if (!isExpressionCompatible) { 4.121 + resultInfo.checkContext.report(tree.pos(), 4.122 + diags.fragment("incompatible.ret.type.in.lambda", 4.123 + diags.fragment("missing.ret.val", currentReturnType))); 4.124 + } 4.125 + } else { 4.126 + LambdaBodyStructChecker lambdaBodyChecker = 4.127 + new LambdaBodyStructChecker(); 4.128 + 4.129 + tree.body.accept(lambdaBodyChecker); 4.130 + boolean isVoidCompatible = lambdaBodyChecker.isVoidCompatible; 4.131 + 4.132 + if (returnTypeIsVoid) { 4.133 + if (!isVoidCompatible) { 4.134 + resultInfo.checkContext.report(tree.pos(), 4.135 + diags.fragment("unexpected.ret.val")); 4.136 + } 4.137 + } else { 4.138 + boolean isValueCompatible = lambdaBodyChecker.isPotentiallyValueCompatible 4.139 + && !canLambdaBodyCompleteNormally(tree); 4.140 + if (!isValueCompatible && !isVoidCompatible) { 4.141 + log.error(tree.body.pos(), 4.142 + "lambda.body.neither.value.nor.void.compatible"); 4.143 + } 4.144 + 4.145 + if (!isValueCompatible) { 4.146 + resultInfo.checkContext.report(tree.pos(), 4.147 + diags.fragment("incompatible.ret.type.in.lambda", 4.148 + diags.fragment("missing.ret.val", currentReturnType))); 4.149 + } 4.150 + } 4.151 + } 4.152 + } 4.153 + } 4.154 + 4.155 + boolean canLambdaBodyCompleteNormally(JCLambda tree) { 4.156 + JCLambda newTree = new TreeCopier<>(make).copy(tree); 4.157 + /* attr.lambdaEnv will create a meaningful env for the 4.158 + * lambda expression. This is specially useful when the 4.159 + * lambda is used as the init of a field. But we need to 4.160 + * remove any added symbol. 4.161 + */ 4.162 + Env<AttrContext> localEnv = attr.lambdaEnv(newTree, env); 4.163 + try { 4.164 + List<JCVariableDecl> tmpParams = newTree.params; 4.165 + while (tmpParams.nonEmpty()) { 4.166 + tmpParams.head.vartype = make.at(tmpParams.head).Type(syms.errType); 4.167 + tmpParams = tmpParams.tail; 4.168 + } 4.169 + 4.170 + attr.attribStats(newTree.params, localEnv); 4.171 + 4.172 + /* set pt to Type.noType to avoid generating any bound 4.173 + * which may happen if lambda's return type is an 4.174 + * inference variable 4.175 + */ 4.176 + Attr.ResultInfo bodyResultInfo = attr.new ResultInfo(VAL, Type.noType); 4.177 + localEnv.info.returnResult = bodyResultInfo; 4.178 + 4.179 + // discard any log output 4.180 + Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log); 4.181 + try { 4.182 + JCBlock body = (JCBlock)newTree.body; 4.183 + /* we need to attribute the lambda body before 4.184 + * doing the aliveness analysis. This is because 4.185 + * constant folding occurs during attribution 4.186 + * and the reachability of some statements depends 4.187 + * on constant values, for example: 4.188 + * 4.189 + * while (true) {...} 4.190 + */ 4.191 + attr.attribStats(body.stats, localEnv); 4.192 + 4.193 + attr.preFlow(newTree); 4.194 + /* make an aliveness / reachability analysis of the lambda 4.195 + * to determine if it can complete normally 4.196 + */ 4.197 + flow.analyzeLambda(localEnv, newTree, make, true); 4.198 + } finally { 4.199 + log.popDiagnosticHandler(diagHandler); 4.200 + } 4.201 + return newTree.canCompleteNormally; 4.202 + } finally { 4.203 + JCBlock body = (JCBlock)newTree.body; 4.204 + unenterScanner.scan(body.stats); 4.205 + localEnv.info.scope.leave(); 4.206 } 4.207 } 4.208 4.209 @@ -625,10 +726,7 @@ 4.210 public void visitReference(JCMemberReference tree) { 4.211 Check.CheckContext checkContext = resultInfo.checkContext; 4.212 Type pt = resultInfo.pt; 4.213 - if (inferenceContext.inferencevars.contains(pt)) { 4.214 - //ok 4.215 - return; 4.216 - } else { 4.217 + if (!inferenceContext.inferencevars.contains(pt)) { 4.218 try { 4.219 types.findDescriptorType(pt); 4.220 } catch (Types.FunctionDescriptorLookupError ex) { 4.221 @@ -658,6 +756,40 @@ 4.222 } 4.223 } 4.224 } 4.225 + 4.226 + /* This visitor looks for return statements, its analysis will determine if 4.227 + * a lambda body is void or value compatible. We must analyze return 4.228 + * statements contained in the lambda body only, thus any return statement 4.229 + * contained in an inner class or inner lambda body, should be ignored. 4.230 + */ 4.231 + class LambdaBodyStructChecker extends TreeScanner { 4.232 + boolean isVoidCompatible = true; 4.233 + boolean isPotentiallyValueCompatible = true; 4.234 + 4.235 + @Override 4.236 + public void visitClassDef(JCClassDecl tree) { 4.237 + // do nothing 4.238 + } 4.239 + 4.240 + @Override 4.241 + public void visitLambda(JCLambda tree) { 4.242 + // do nothing 4.243 + } 4.244 + 4.245 + @Override 4.246 + public void visitNewClass(JCNewClass tree) { 4.247 + // do nothing 4.248 + } 4.249 + 4.250 + @Override 4.251 + public void visitReturn(JCReturn tree) { 4.252 + if (tree.expr != null) { 4.253 + isVoidCompatible = false; 4.254 + } else { 4.255 + isPotentiallyValueCompatible = false; 4.256 + } 4.257 + } 4.258 + } 4.259 } 4.260 4.261 /** an empty deferred attribution context - all methods throw exceptions */ 4.262 @@ -769,7 +901,7 @@ 4.263 /** 4.264 * handler that is executed when a node has been discarded 4.265 */ 4.266 - abstract void skip(JCTree tree); 4.267 + void skip(JCTree tree) {} 4.268 } 4.269 4.270 /** 4.271 @@ -781,11 +913,6 @@ 4.272 PolyScanner() { 4.273 super(EnumSet.of(CONDEXPR, PARENS, LAMBDA, REFERENCE)); 4.274 } 4.275 - 4.276 - @Override 4.277 - void skip(JCTree tree) { 4.278 - //do nothing 4.279 - } 4.280 } 4.281 4.282 /** 4.283 @@ -798,11 +925,6 @@ 4.284 super(EnumSet.of(BLOCK, CASE, CATCH, DOLOOP, FOREACHLOOP, 4.285 FORLOOP, RETURN, SYNCHRONIZED, SWITCH, TRY, WHILELOOP)); 4.286 } 4.287 - 4.288 - @Override 4.289 - void skip(JCTree tree) { 4.290 - //do nothing 4.291 - } 4.292 } 4.293 4.294 /**
5.1 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java Wed Apr 30 11:17:22 2014 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java Wed Apr 30 23:59:45 2014 -0700 5.3 @@ -45,7 +45,7 @@ 5.4 import static com.sun.tools.javac.tree.JCTree.Tag.*; 5.5 5.6 /** This pass implements dataflow analysis for Java programs though 5.7 - * different AST visitor steps. Liveness analysis (see AliveAlanyzer) checks that 5.8 + * different AST visitor steps. Liveness analysis (see AliveAnalyzer) checks that 5.9 * every statement is reachable. Exception analysis (see FlowAnalyzer) ensures that 5.10 * every checked exception that is thrown is declared or caught. Definite assignment analysis 5.11 * (see AssignAnalyzer) ensures that each variable is assigned when used. Definite 5.12 @@ -197,6 +197,7 @@ 5.13 private final boolean allowImprovedRethrowAnalysis; 5.14 private final boolean allowImprovedCatchAnalysis; 5.15 private final boolean allowEffectivelyFinalInInnerClasses; 5.16 + private final boolean enforceThisDotInit; 5.17 5.18 public static Flow instance(Context context) { 5.19 Flow instance = context.get(flowKey); 5.20 @@ -207,7 +208,7 @@ 5.21 5.22 public void analyzeTree(Env<AttrContext> env, TreeMaker make) { 5.23 new AliveAnalyzer().analyzeTree(env, make); 5.24 - new AssignAnalyzer(log, syms, lint, names).analyzeTree(env); 5.25 + new AssignAnalyzer(log, syms, lint, names, enforceThisDotInit).analyzeTree(env); 5.26 new FlowAnalyzer().analyzeTree(env, make); 5.27 new CaptureAnalyzer().analyzeTree(env, make); 5.28 } 5.29 @@ -239,7 +240,7 @@ 5.30 //related errors, which will allow for more errors to be detected 5.31 Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log); 5.32 try { 5.33 - new AssignAnalyzer(log, syms, lint, names).analyzeTree(env); 5.34 + new AssignAnalyzer(log, syms, lint, names, enforceThisDotInit).analyzeTree(env); 5.35 LambdaFlowAnalyzer flowAnalyzer = new LambdaFlowAnalyzer(); 5.36 flowAnalyzer.analyzeTree(env, that, make); 5.37 return flowAnalyzer.inferredThrownTypes; 5.38 @@ -289,6 +290,7 @@ 5.39 allowImprovedRethrowAnalysis = source.allowImprovedRethrowAnalysis(); 5.40 allowImprovedCatchAnalysis = source.allowImprovedCatchAnalysis(); 5.41 allowEffectivelyFinalInInnerClasses = source.allowEffectivelyFinalInInnerClasses(); 5.42 + enforceThisDotInit = source.enforceThisDotInit(); 5.43 } 5.44 5.45 /** 5.46 @@ -1427,6 +1429,8 @@ 5.47 5.48 protected Names names; 5.49 5.50 + final boolean enforceThisDotInit; 5.51 + 5.52 public static class AbstractAssignPendingExit extends BaseAnalyzer.PendingExit { 5.53 5.54 final Bits inits; 5.55 @@ -1449,7 +1453,7 @@ 5.56 } 5.57 } 5.58 5.59 - public AbstractAssignAnalyzer(Bits inits, Symtab syms, Names names) { 5.60 + public AbstractAssignAnalyzer(Bits inits, Symtab syms, Names names, boolean enforceThisDotInit) { 5.61 this.inits = inits; 5.62 uninits = new Bits(); 5.63 uninitsTry = new Bits(); 5.64 @@ -1459,6 +1463,7 @@ 5.65 uninitsWhenFalse = new Bits(true); 5.66 this.syms = syms; 5.67 this.names = names; 5.68 + this.enforceThisDotInit = enforceThisDotInit; 5.69 } 5.70 5.71 private boolean isInitialConstructor = false; 5.72 @@ -2280,12 +2285,34 @@ 5.73 5.74 public void visitAssign(JCAssign tree) { 5.75 JCTree lhs = TreeInfo.skipParens(tree.lhs); 5.76 - if (!(lhs instanceof JCIdent)) { 5.77 + if (!isIdentOrThisDotIdent(lhs)) 5.78 scanExpr(lhs); 5.79 - } 5.80 scanExpr(tree.rhs); 5.81 letInit(lhs); 5.82 } 5.83 + private boolean isIdentOrThisDotIdent(JCTree lhs) { 5.84 + if (lhs.hasTag(IDENT)) 5.85 + return true; 5.86 + if (!lhs.hasTag(SELECT)) 5.87 + return false; 5.88 + 5.89 + JCFieldAccess fa = (JCFieldAccess)lhs; 5.90 + return fa.selected.hasTag(IDENT) && 5.91 + ((JCIdent)fa.selected).name == names._this; 5.92 + } 5.93 + 5.94 + // check fields accessed through this.<field> are definitely 5.95 + // assigned before reading their value 5.96 + public void visitSelect(JCFieldAccess tree) { 5.97 + super.visitSelect(tree); 5.98 + if (enforceThisDotInit && 5.99 + tree.selected.hasTag(IDENT) && 5.100 + ((JCIdent)tree.selected).name == names._this && 5.101 + tree.sym.kind == VAR) 5.102 + { 5.103 + checkInit(tree.pos(), (VarSymbol)tree.sym); 5.104 + } 5.105 + } 5.106 5.107 public void visitAssignop(JCAssignOp tree) { 5.108 scanExpr(tree.lhs); 5.109 @@ -2419,8 +2446,8 @@ 5.110 } 5.111 } 5.112 5.113 - public AssignAnalyzer(Log log, Symtab syms, Lint lint, Names names) { 5.114 - super(new Bits(), syms, names); 5.115 + public AssignAnalyzer(Log log, Symtab syms, Lint lint, Names names, boolean enforceThisDotInit) { 5.116 + super(new Bits(), syms, names, enforceThisDotInit); 5.117 this.log = log; 5.118 this.lint = lint; 5.119 }
6.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Wed Apr 30 11:17:22 2014 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Wed Apr 30 23:59:45 2014 -0700 6.3 @@ -220,9 +220,10 @@ 6.4 */ 6.5 Type generateReturnConstraints(Attr.ResultInfo resultInfo, 6.6 MethodType mt, InferenceContext inferenceContext) { 6.7 + InferenceContext rsInfoInfContext = resultInfo.checkContext.inferenceContext(); 6.8 Type from = mt.getReturnType(); 6.9 if (mt.getReturnType().containsAny(inferenceContext.inferencevars) && 6.10 - resultInfo.checkContext.inferenceContext() != emptyContext) { 6.11 + rsInfoInfContext != emptyContext) { 6.12 from = types.capture(from); 6.13 //add synthetic captured ivars 6.14 for (Type t : from.getTypeArguments()) { 6.15 @@ -231,13 +232,13 @@ 6.16 } 6.17 } 6.18 } 6.19 - Type qtype1 = inferenceContext.asFree(from); 6.20 + Type qtype1 = inferenceContext.asUndetVar(from); 6.21 Type to = returnConstraintTarget(qtype1, resultInfo.pt); 6.22 - Assert.check(allowGraphInference || !resultInfo.checkContext.inferenceContext().free(to), 6.23 + Assert.check(allowGraphInference || !rsInfoInfContext.free(to), 6.24 "legacy inference engine cannot handle constraints on both sides of a subtyping assertion"); 6.25 //we need to skip capture? 6.26 Warner retWarn = new Warner(); 6.27 - if (!resultInfo.checkContext.compatible(qtype1, resultInfo.checkContext.inferenceContext().asFree(to), retWarn) || 6.28 + if (!resultInfo.checkContext.compatible(qtype1, rsInfoInfContext.asUndetVar(to), retWarn) || 6.29 //unchecked conversion is not allowed in source 7 mode 6.30 (!allowGraphInference && retWarn.hasLint(Lint.LintCategory.UNCHECKED))) { 6.31 throw inferenceException 6.32 @@ -280,7 +281,7 @@ 6.33 ListBuffer<Type> todo = new ListBuffer<>(); 6.34 //step 1 - create fresh tvars 6.35 for (Type t : vars) { 6.36 - UndetVar uv = (UndetVar)inferenceContext.asFree(t); 6.37 + UndetVar uv = (UndetVar)inferenceContext.asUndetVar(t); 6.38 List<Type> upperBounds = uv.getBounds(InferenceBound.UPPER); 6.39 if (Type.containsAny(upperBounds, vars)) { 6.40 TypeSymbol fresh_tvar = new TypeVariableSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner); 6.41 @@ -399,7 +400,7 @@ 6.42 return types.createErrorType(funcInterface); 6.43 } 6.44 for (Type p : descParameterTypes) { 6.45 - if (!types.isSameType(funcInterfaceContext.asFree(p), paramTypes.head)) { 6.46 + if (!types.isSameType(funcInterfaceContext.asUndetVar(p), paramTypes.head)) { 6.47 checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface)); 6.48 return types.createErrorType(funcInterface); 6.49 } 6.50 @@ -515,6 +516,32 @@ 6.51 /** max number of incorporation rounds */ 6.52 static final int MAX_INCORPORATION_STEPS = 100; 6.53 6.54 + /* If for two types t and s there is a least upper bound that is a 6.55 + * parameterized type G, then there exists a supertype of 't' of the form 6.56 + * G<T1, ..., Tn> and a supertype of 's' of the form G<S1, ..., Sn> 6.57 + * which will be returned by this method. If no such supertypes exists then 6.58 + * null is returned. 6.59 + * 6.60 + * As an example for the following input: 6.61 + * 6.62 + * t = java.util.ArrayList<java.lang.String> 6.63 + * s = java.util.List<T> 6.64 + * 6.65 + * we get this ouput: 6.66 + * 6.67 + * Pair[java.util.List<java.lang.String>,java.util.List<T>] 6.68 + */ 6.69 + private Pair<Type, Type> getParameterizedSupers(Type t, Type s) { 6.70 + Type lubResult = types.lub(t, s); 6.71 + if (lubResult == syms.errType || lubResult == syms.botType || 6.72 + !lubResult.isParameterized()) { 6.73 + return null; 6.74 + } 6.75 + Type asSuperOfT = types.asSuper(t, lubResult.tsym); 6.76 + Type asSuperOfS = types.asSuper(s, lubResult.tsym); 6.77 + return new Pair<>(asSuperOfT, asSuperOfS); 6.78 + } 6.79 + 6.80 /** 6.81 * This enumeration defines an entry point for doing inference variable 6.82 * bound incorporation - it can be used to inject custom incorporation 6.83 @@ -533,22 +560,23 @@ 6.84 if (uv.inst != null) { 6.85 Type inst = uv.inst; 6.86 for (Type u : uv.getBounds(InferenceBound.UPPER)) { 6.87 - if (!isSubtype(inst, inferenceContext.asFree(u), warn, infer)) { 6.88 + if (!isSubtype(inst, inferenceContext.asUndetVar(u), warn, infer)) { 6.89 infer.reportBoundError(uv, BoundErrorKind.UPPER); 6.90 } 6.91 } 6.92 for (Type l : uv.getBounds(InferenceBound.LOWER)) { 6.93 - if (!isSubtype(inferenceContext.asFree(l), inst, warn, infer)) { 6.94 + if (!isSubtype(inferenceContext.asUndetVar(l), inst, warn, infer)) { 6.95 infer.reportBoundError(uv, BoundErrorKind.LOWER); 6.96 } 6.97 } 6.98 for (Type e : uv.getBounds(InferenceBound.EQ)) { 6.99 - if (!isSameType(inst, inferenceContext.asFree(e), infer)) { 6.100 + if (!isSameType(inst, inferenceContext.asUndetVar(e), infer)) { 6.101 infer.reportBoundError(uv, BoundErrorKind.EQ); 6.102 } 6.103 } 6.104 } 6.105 } 6.106 + 6.107 @Override 6.108 boolean accepts(UndetVar uv, InferenceContext inferenceContext) { 6.109 //applies to all undetvars 6.110 @@ -594,12 +622,12 @@ 6.111 for (Type e : uv.getBounds(InferenceBound.EQ)) { 6.112 if (e.containsAny(inferenceContext.inferenceVars())) continue; 6.113 for (Type u : uv.getBounds(InferenceBound.UPPER)) { 6.114 - if (!isSubtype(e, inferenceContext.asFree(u), warn, infer)) { 6.115 + if (!isSubtype(e, inferenceContext.asUndetVar(u), warn, infer)) { 6.116 infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_UPPER); 6.117 } 6.118 } 6.119 for (Type l : uv.getBounds(InferenceBound.LOWER)) { 6.120 - if (!isSubtype(inferenceContext.asFree(l), e, warn, infer)) { 6.121 + if (!isSubtype(inferenceContext.asUndetVar(l), e, warn, infer)) { 6.122 infer.reportBoundError(uv, BoundErrorKind.BAD_EQ_LOWER); 6.123 } 6.124 } 6.125 @@ -615,7 +643,7 @@ 6.126 Infer infer = inferenceContext.infer(); 6.127 for (Type b1 : uv.getBounds(InferenceBound.UPPER)) { 6.128 for (Type b2 : uv.getBounds(InferenceBound.LOWER)) { 6.129 - isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn , infer); 6.130 + isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn , infer); 6.131 } 6.132 } 6.133 } 6.134 @@ -629,7 +657,7 @@ 6.135 Infer infer = inferenceContext.infer(); 6.136 for (Type b1 : uv.getBounds(InferenceBound.UPPER)) { 6.137 for (Type b2 : uv.getBounds(InferenceBound.EQ)) { 6.138 - isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn, infer); 6.139 + isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn, infer); 6.140 } 6.141 } 6.142 } 6.143 @@ -643,12 +671,59 @@ 6.144 Infer infer = inferenceContext.infer(); 6.145 for (Type b1 : uv.getBounds(InferenceBound.EQ)) { 6.146 for (Type b2 : uv.getBounds(InferenceBound.LOWER)) { 6.147 - isSubtype(inferenceContext.asFree(b2), inferenceContext.asFree(b1), warn, infer); 6.148 + isSubtype(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), warn, infer); 6.149 } 6.150 } 6.151 } 6.152 }, 6.153 /** 6.154 + * Given a bound set containing {@code alpha <: P<T>} and 6.155 + * {@code alpha <: P<S>} where P is a parameterized type, 6.156 + * perform {@code T = S} (which could lead to new bounds). 6.157 + */ 6.158 + CROSS_UPPER_UPPER() { 6.159 + @Override 6.160 + public void apply(UndetVar uv, InferenceContext inferenceContext, Warner warn) { 6.161 + Infer infer = inferenceContext.infer(); 6.162 + List<Type> boundList = uv.getBounds(InferenceBound.UPPER); 6.163 + List<Type> boundListTail = boundList.tail; 6.164 + while (boundList.nonEmpty()) { 6.165 + List<Type> tmpTail = boundListTail; 6.166 + while (tmpTail.nonEmpty()) { 6.167 + Type b1 = boundList.head; 6.168 + Type b2 = tmpTail.head; 6.169 + if (b1 != b2) { 6.170 + Pair<Type, Type> commonSupers = infer.getParameterizedSupers(b1, b2); 6.171 + if (commonSupers != null) { 6.172 + List<Type> allParamsSuperBound1 = commonSupers.fst.allparams(); 6.173 + List<Type> allParamsSuperBound2 = commonSupers.snd.allparams(); 6.174 + while (allParamsSuperBound1.nonEmpty() && allParamsSuperBound2.nonEmpty()) { 6.175 + //traverse the list of all params comparing them 6.176 + if (!allParamsSuperBound1.head.hasTag(WILDCARD) && 6.177 + !allParamsSuperBound2.head.hasTag(WILDCARD)) { 6.178 + isSameType(inferenceContext.asUndetVar(allParamsSuperBound1.head), 6.179 + inferenceContext.asUndetVar(allParamsSuperBound2.head), infer); 6.180 + } 6.181 + allParamsSuperBound1 = allParamsSuperBound1.tail; 6.182 + allParamsSuperBound2 = allParamsSuperBound2.tail; 6.183 + } 6.184 + Assert.check(allParamsSuperBound1.isEmpty() && allParamsSuperBound2.isEmpty()); 6.185 + } 6.186 + } 6.187 + tmpTail = tmpTail.tail; 6.188 + } 6.189 + boundList = boundList.tail; 6.190 + boundListTail = boundList.tail; 6.191 + } 6.192 + } 6.193 + 6.194 + @Override 6.195 + boolean accepts(UndetVar uv, InferenceContext inferenceContext) { 6.196 + return !uv.isCaptured() && 6.197 + uv.getBounds(InferenceBound.UPPER).nonEmpty(); 6.198 + } 6.199 + }, 6.200 + /** 6.201 * Given a bound set containing {@code alpha == S} and {@code alpha == T} 6.202 * perform {@code S == T} (which could lead to new bounds). 6.203 */ 6.204 @@ -658,7 +733,7 @@ 6.205 for (Type b1 : uv.getBounds(InferenceBound.EQ)) { 6.206 for (Type b2 : uv.getBounds(InferenceBound.EQ)) { 6.207 if (b1 != b2) { 6.208 - isSameType(inferenceContext.asFree(b2), inferenceContext.asFree(b1), infer); 6.209 + isSameType(inferenceContext.asUndetVar(b2), inferenceContext.asUndetVar(b1), infer); 6.210 } 6.211 } 6.212 } 6.213 @@ -673,7 +748,7 @@ 6.214 Infer infer = inferenceContext.infer(); 6.215 for (Type b : uv.getBounds(InferenceBound.UPPER)) { 6.216 if (inferenceContext.inferenceVars().contains(b)) { 6.217 - UndetVar uv2 = (UndetVar)inferenceContext.asFree(b); 6.218 + UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b); 6.219 if (uv2.isCaptured()) continue; 6.220 //alpha <: beta 6.221 //0. set beta :> alpha 6.222 @@ -699,7 +774,7 @@ 6.223 Infer infer = inferenceContext.infer(); 6.224 for (Type b : uv.getBounds(InferenceBound.LOWER)) { 6.225 if (inferenceContext.inferenceVars().contains(b)) { 6.226 - UndetVar uv2 = (UndetVar)inferenceContext.asFree(b); 6.227 + UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b); 6.228 if (uv2.isCaptured()) continue; 6.229 //alpha :> beta 6.230 //0. set beta <: alpha 6.231 @@ -725,7 +800,7 @@ 6.232 Infer infer = inferenceContext.infer(); 6.233 for (Type b : uv.getBounds(InferenceBound.EQ)) { 6.234 if (inferenceContext.inferenceVars().contains(b)) { 6.235 - UndetVar uv2 = (UndetVar)inferenceContext.asFree(b); 6.236 + UndetVar uv2 = (UndetVar)inferenceContext.asUndetVar(b); 6.237 if (uv2.isCaptured()) continue; 6.238 //alpha == beta 6.239 //0. set beta == alpha 6.240 @@ -1475,7 +1550,7 @@ 6.241 StringBuilder buf = new StringBuilder(); 6.242 String sep = ""; 6.243 for (Type from : data) { 6.244 - UndetVar uv = (UndetVar)inferenceContext.asFree(from); 6.245 + UndetVar uv = (UndetVar)inferenceContext.asUndetVar(from); 6.246 for (Type bound : uv.getBounds(InferenceBound.values())) { 6.247 if (bound.containsAny(List.from(to.data))) { 6.248 buf.append(sep); 6.249 @@ -1684,7 +1759,7 @@ 6.250 Set<Type> optDepsByNode = stuckDeps.get(i); 6.251 for (Node n_j : nodes) { 6.252 Type j = n_j.data.first(); 6.253 - UndetVar uv_i = (UndetVar)inferenceContext.asFree(i); 6.254 + UndetVar uv_i = (UndetVar)inferenceContext.asUndetVar(i); 6.255 if (Type.containsAny(uv_i.getBounds(InferenceBound.values()), List.of(j))) { 6.256 //update i's bound dependencies 6.257 n_i.addDependency(DependencyKind.BOUND, n_j); 6.258 @@ -1833,6 +1908,8 @@ 6.259 }); 6.260 } 6.261 6.262 + /* Returns the corresponding inference variables. 6.263 + */ 6.264 private List<Type> filterVars(Filter<UndetVar> fu) { 6.265 ListBuffer<Type> res = new ListBuffer<>(); 6.266 for (Type t : undetvars) { 6.267 @@ -1890,14 +1967,14 @@ 6.268 * undet vars (used ahead of subtyping/compatibility checks to allow propagation 6.269 * of inference constraints). 6.270 */ 6.271 - final Type asFree(Type t) { 6.272 + final Type asUndetVar(Type t) { 6.273 return types.subst(t, inferencevars, undetvars); 6.274 } 6.275 6.276 - final List<Type> asFree(List<Type> ts) { 6.277 + final List<Type> asUndetVars(List<Type> ts) { 6.278 ListBuffer<Type> buf = new ListBuffer<>(); 6.279 for (Type t : ts) { 6.280 - buf.append(asFree(t)); 6.281 + buf.append(asUndetVar(t)); 6.282 } 6.283 return buf.toList(); 6.284 } 6.285 @@ -2073,7 +2150,7 @@ 6.286 private boolean solveBasic(List<Type> varsToSolve, EnumSet<InferenceStep> steps) { 6.287 boolean changed = false; 6.288 for (Type t : varsToSolve.intersect(restvars())) { 6.289 - UndetVar uv = (UndetVar)asFree(t); 6.290 + UndetVar uv = (UndetVar)asUndetVar(t); 6.291 for (InferenceStep step : steps) { 6.292 if (step.accepts(uv, this)) { 6.293 uv.inst = step.solve(uv, this);
7.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Wed Apr 30 11:17:22 2014 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Wed Apr 30 23:59:45 2014 -0700 7.3 @@ -1,5 +1,5 @@ 7.4 /* 7.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 7.6 + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 7.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.8 * 7.9 * This code is free software; you can redistribute it and/or modify it 7.10 @@ -2360,6 +2360,7 @@ 7.11 /** Visitor method: Translate a single node. 7.12 * Attach the source position from the old tree to its replacement tree. 7.13 */ 7.14 + @Override 7.15 public <T extends JCTree> T translate(T tree) { 7.16 if (tree == null) { 7.17 return null;
8.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed Apr 30 11:17:22 2014 -0700 8.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed Apr 30 23:59:45 2014 -0700 8.3 @@ -899,7 +899,7 @@ 8.4 8.5 @Override 8.6 public boolean compatible(Type found, Type req, Warner warn) { 8.7 - found = pendingInferenceContext.asFree(found); 8.8 + found = pendingInferenceContext.asUndetVar(found); 8.9 req = infer.returnConstraintTarget(found, req); 8.10 return super.compatible(found, req, warn); 8.11 } 8.12 @@ -936,8 +936,8 @@ 8.13 8.14 public boolean compatible(Type found, Type req, Warner warn) { 8.15 return strict ? 8.16 - types.isSubtypeUnchecked(found, deferredAttrContext.inferenceContext.asFree(req), warn) : 8.17 - types.isConvertible(found, deferredAttrContext.inferenceContext.asFree(req), warn); 8.18 + types.isSubtypeUnchecked(found, deferredAttrContext.inferenceContext.asUndetVar(req), warn) : 8.19 + types.isConvertible(found, deferredAttrContext.inferenceContext.asUndetVar(req), warn); 8.20 } 8.21 8.22 public void report(DiagnosticPosition pos, JCDiagnostic details) { 8.23 @@ -1142,7 +1142,7 @@ 8.24 Type desc_t = types.findDescriptorType(t); 8.25 Type desc_s = types.findDescriptorType(s); 8.26 if (types.isSameTypes(desc_t.getParameterTypes(), 8.27 - inferenceContext().asFree(desc_s.getParameterTypes()))) { 8.28 + inferenceContext().asUndetVars(desc_s.getParameterTypes()))) { 8.29 if (types.asSuper(t, s.tsym) != null || 8.30 types.asSuper(s, t.tsym) != null) { 8.31 result &= MostSpecificCheckContext.super.compatible(t, s, warn); 8.32 @@ -1169,7 +1169,7 @@ 8.33 Type desc_t = types.findDescriptorType(t); 8.34 Type desc_s = types.findDescriptorType(s); 8.35 if (types.isSameTypes(desc_t.getParameterTypes(), 8.36 - inferenceContext().asFree(desc_s.getParameterTypes()))) { 8.37 + inferenceContext().asUndetVars(desc_s.getParameterTypes()))) { 8.38 if (types.asSuper(t, s.tsym) != null || 8.39 types.asSuper(s, t.tsym) != null) { 8.40 result &= MostSpecificCheckContext.super.compatible(t, s, warn); 8.41 @@ -3152,7 +3152,7 @@ 8.42 if (TreeInfo.isStaticSelector(referenceTree.expr, names) && 8.43 argtypes.nonEmpty() && 8.44 (argtypes.head.hasTag(NONE) || 8.45 - types.isSubtypeUnchecked(inferenceContext.asFree(argtypes.head), site))) { 8.46 + types.isSubtypeUnchecked(inferenceContext.asUndetVar(argtypes.head), site))) { 8.47 return new UnboundMethodReferenceLookupHelper(referenceTree, name, 8.48 site, argtypes, typeargtypes, maxPhase); 8.49 } else { 8.50 @@ -4265,7 +4265,11 @@ 8.51 } 8.52 8.53 DeferredAttrContext deferredAttrContext(Symbol sym, InferenceContext inferenceContext, ResultInfo pendingResult, Warner warn) { 8.54 - return deferredAttr.new DeferredAttrContext(attrMode, sym, step, inferenceContext, pendingResult != null ? pendingResult.checkContext.deferredAttrContext() : deferredAttr.emptyDeferredAttrContext, warn); 8.55 + DeferredAttrContext parent = (pendingResult == null) 8.56 + ? deferredAttr.emptyDeferredAttrContext 8.57 + : pendingResult.checkContext.deferredAttrContext(); 8.58 + return deferredAttr.new DeferredAttrContext(attrMode, sym, step, 8.59 + inferenceContext, parent, warn); 8.60 } 8.61 8.62 /**
9.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Wed Apr 30 11:17:22 2014 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java Wed Apr 30 23:59:45 2014 -0700 9.3 @@ -512,14 +512,14 @@ 9.4 break; 9.5 case CONSTANT_Fieldref: { 9.6 ClassSymbol owner = readClassSymbol(getChar(index + 1)); 9.7 - NameAndType nt = (NameAndType)readPool(getChar(index + 3)); 9.8 + NameAndType nt = readNameAndType(getChar(index + 3)); 9.9 poolObj[i] = new VarSymbol(0, nt.name, nt.uniqueType.type, owner); 9.10 break; 9.11 } 9.12 case CONSTANT_Methodref: 9.13 case CONSTANT_InterfaceMethodref: { 9.14 ClassSymbol owner = readClassSymbol(getChar(index + 1)); 9.15 - NameAndType nt = (NameAndType)readPool(getChar(index + 3)); 9.16 + NameAndType nt = readNameAndType(getChar(index + 3)); 9.17 poolObj[i] = new MethodSymbol(0, nt.name, nt.uniqueType.type, owner); 9.18 break; 9.19 } 9.20 @@ -588,13 +588,34 @@ 9.21 /** Read class entry. 9.22 */ 9.23 ClassSymbol readClassSymbol(int i) { 9.24 - return (ClassSymbol) (readPool(i)); 9.25 + Object obj = readPool(i); 9.26 + if (obj != null && !(obj instanceof ClassSymbol)) 9.27 + throw badClassFile("bad.const.pool.entry", 9.28 + currentClassFile.toString(), 9.29 + "CONSTANT_Class_info", i); 9.30 + return (ClassSymbol)obj; 9.31 } 9.32 9.33 /** Read name. 9.34 */ 9.35 Name readName(int i) { 9.36 - return (Name) (readPool(i)); 9.37 + Object obj = readPool(i); 9.38 + if (obj != null && !(obj instanceof Name)) 9.39 + throw badClassFile("bad.const.pool.entry", 9.40 + currentClassFile.toString(), 9.41 + "CONSTANT_Utf8_info or CONSTANT_String_info", i); 9.42 + return (Name)obj; 9.43 + } 9.44 + 9.45 + /** Read name and type. 9.46 + */ 9.47 + NameAndType readNameAndType(int i) { 9.48 + Object obj = readPool(i); 9.49 + if (obj != null && !(obj instanceof NameAndType)) 9.50 + throw badClassFile("bad.const.pool.entry", 9.51 + currentClassFile.toString(), 9.52 + "CONSTANT_NameAndType_info", i); 9.53 + return (NameAndType)obj; 9.54 } 9.55 9.56 /************************************************************************ 9.57 @@ -1245,7 +1266,7 @@ 9.58 sym.owner.members().remove(sym); 9.59 ClassSymbol self = (ClassSymbol)sym; 9.60 ClassSymbol c = readClassSymbol(nextChar()); 9.61 - NameAndType nt = (NameAndType)readPool(nextChar()); 9.62 + NameAndType nt = readNameAndType(nextChar()); 9.63 9.64 if (c.members_field == null) 9.65 throw badClassFile("bad.enclosing.class", self, c);
10.1 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Wed Apr 30 11:17:22 2014 -0700 10.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Wed Apr 30 23:59:45 2014 -0700 10.3 @@ -1,5 +1,5 @@ 10.4 /* 10.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 10.6 + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 10.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.8 * 10.9 * This code is free software; you can redistribute it and/or modify it 10.10 @@ -2818,7 +2818,7 @@ 10.11 } 10.12 10.13 private LVTAssignAnalyzer(LVTRanges lvtRanges, Symtab syms, Names names) { 10.14 - super(new LVTBits(), syms, names); 10.15 + super(new LVTBits(), syms, names, false); 10.16 lvtInits = (LVTBits)inits; 10.17 this.lvtRanges = lvtRanges; 10.18 }
11.1 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Wed Apr 30 11:17:22 2014 -0700 11.2 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Wed Apr 30 23:59:45 2014 -0700 11.3 @@ -3406,16 +3406,28 @@ 11.4 * | ModifiersOpt 11.5 * ( Type Ident 11.6 * ( VariableDeclaratorsRest ";" | MethodDeclaratorRest ) 11.7 - * | VOID Ident MethodDeclaratorRest 11.8 - * | TypeParameters (Type | VOID) Ident MethodDeclaratorRest 11.9 + * | VOID Ident VoidMethodDeclaratorRest 11.10 + * | TypeParameters [Annotations] 11.11 + * ( Type Ident MethodDeclaratorRest 11.12 + * | VOID Ident VoidMethodDeclaratorRest 11.13 + * ) 11.14 * | Ident ConstructorDeclaratorRest 11.15 * | TypeParameters Ident ConstructorDeclaratorRest 11.16 * | ClassOrInterfaceOrEnumDeclaration 11.17 * ) 11.18 * InterfaceBodyDeclaration = 11.19 * ";" 11.20 - * | ModifiersOpt Type Ident 11.21 - * ( ConstantDeclaratorsRest | InterfaceMethodDeclaratorRest ";" ) 11.22 + * | ModifiersOpt 11.23 + * ( Type Ident 11.24 + * ( ConstantDeclaratorsRest ";" | MethodDeclaratorRest ) 11.25 + * | VOID Ident MethodDeclaratorRest 11.26 + * | TypeParameters [Annotations] 11.27 + * ( Type Ident MethodDeclaratorRest 11.28 + * | VOID Ident VoidMethodDeclaratorRest 11.29 + * ) 11.30 + * | ClassOrInterfaceOrEnumDeclaration 11.31 + * ) 11.32 + * 11.33 */ 11.34 protected List<JCTree> classOrInterfaceBodyDeclaration(Name className, boolean isInterface) { 11.35 if (token.kind == SEMI) { 11.36 @@ -3444,28 +3456,29 @@ 11.37 } 11.38 List<JCAnnotation> annosAfterParams = annotationsOpt(Tag.ANNOTATION); 11.39 11.40 + if (annosAfterParams.nonEmpty()) { 11.41 + checkAnnotationsAfterTypeParams(annosAfterParams.head.pos); 11.42 + mods.annotations = mods.annotations.appendList(annosAfterParams); 11.43 + if (mods.pos == Position.NOPOS) 11.44 + mods.pos = mods.annotations.head.pos; 11.45 + } 11.46 + 11.47 Token tk = token; 11.48 pos = token.pos; 11.49 JCExpression type; 11.50 boolean isVoid = token.kind == VOID; 11.51 if (isVoid) { 11.52 - if (annosAfterParams.nonEmpty()) 11.53 - illegal(annosAfterParams.head.pos); 11.54 type = to(F.at(pos).TypeIdent(TypeTag.VOID)); 11.55 nextToken(); 11.56 } else { 11.57 - if (annosAfterParams.nonEmpty()) { 11.58 - checkAnnotationsAfterTypeParams(annosAfterParams.head.pos); 11.59 - mods.annotations = mods.annotations.appendList(annosAfterParams); 11.60 - if (mods.pos == Position.NOPOS) 11.61 - mods.pos = mods.annotations.head.pos; 11.62 - } 11.63 // method returns types are un-annotated types 11.64 type = unannotatedType(); 11.65 } 11.66 if (token.kind == LPAREN && !isInterface && type.hasTag(IDENT)) { 11.67 if (isInterface || tk.name() != className) 11.68 error(pos, "invalid.meth.decl.ret.type.req"); 11.69 + else if (annosAfterParams.nonEmpty()) 11.70 + illegal(annosAfterParams.head.pos); 11.71 return List.of(methodDeclaratorRest( 11.72 pos, mods, null, names.init, typarams, 11.73 isInterface, true, dc)); 11.74 @@ -3497,13 +3510,9 @@ 11.75 } 11.76 11.77 /** MethodDeclaratorRest = 11.78 - * FormalParameters BracketsOpt [Throws TypeList] ( MethodBody | [DEFAULT AnnotationValue] ";") 11.79 + * FormalParameters BracketsOpt [THROWS TypeList] ( MethodBody | [DEFAULT AnnotationValue] ";") 11.80 * VoidMethodDeclaratorRest = 11.81 - * FormalParameters [Throws TypeList] ( MethodBody | ";") 11.82 - * InterfaceMethodDeclaratorRest = 11.83 - * FormalParameters BracketsOpt [THROWS TypeList] ";" 11.84 - * VoidInterfaceMethodDeclaratorRest = 11.85 - * FormalParameters [THROWS TypeList] ";" 11.86 + * FormalParameters [THROWS TypeList] ( MethodBody | ";") 11.87 * ConstructorDeclaratorRest = 11.88 * "(" FormalParameterListOpt ")" [THROWS TypeList] MethodBody 11.89 */
12.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Wed Apr 30 11:17:22 2014 -0700 12.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Wed Apr 30 23:59:45 2014 -0700 12.3 @@ -1,5 +1,5 @@ 12.4 # 12.5 -# Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 12.6 +# Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 12.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.8 # 12.9 # This code is free software; you can redistribute it and/or modify it 12.10 @@ -735,6 +735,9 @@ 12.11 bad return type in method reference\n\ 12.12 {0} 12.13 12.14 +compiler.err.lambda.body.neither.value.nor.void.compatible=\ 12.15 + lambda body is neither value nor void compatible 12.16 + 12.17 # 0: list of type 12.18 compiler.err.incompatible.thrown.types.in.mref=\ 12.19 incompatible thrown types {0} in method reference 12.20 @@ -1702,6 +1705,11 @@ 12.21 cannot access {0}\n\ 12.22 {1} 12.23 12.24 +# 0: file name, 1: expected CP entry type, 2: constant pool index 12.25 +compiler.misc.bad.const.pool.entry=\ 12.26 + bad constant pool entry in {0}\n\ 12.27 + expected {1} at index {2} 12.28 + 12.29 # 0: file name, 1: message segment 12.30 compiler.misc.bad.class.file.header=\ 12.31 bad class file: {0}\n\
13.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeTranslator.java Wed Apr 30 11:17:22 2014 -0700 13.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeTranslator.java Wed Apr 30 23:59:45 2014 -0700 13.3 @@ -1,5 +1,5 @@ 13.4 /* 13.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 13.6 + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 13.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.8 * 13.9 * This code is free software; you can redistribute it and/or modify it 13.10 @@ -56,9 +56,9 @@ 13.11 return null; 13.12 } else { 13.13 tree.accept(this); 13.14 - JCTree result = this.result; 13.15 + JCTree tmpResult = this.result; 13.16 this.result = null; 13.17 - return (T)result; // XXX cast 13.18 + return (T)tmpResult; // XXX cast 13.19 } 13.20 } 13.21
14.1 --- a/src/share/classes/com/sun/tools/javadoc/JavadocTool.java Wed Apr 30 11:17:22 2014 -0700 14.2 +++ b/src/share/classes/com/sun/tools/javadoc/JavadocTool.java Wed Apr 30 23:59:45 2014 -0700 14.3 @@ -68,6 +68,7 @@ 14.4 final Messager messager; 14.5 final JavadocClassReader javadocReader; 14.6 final JavadocEnter javadocEnter; 14.7 + final Set<JavaFileObject> uniquefiles; 14.8 14.9 /** 14.10 * Construct a new JavaCompiler processor, using appropriately 14.11 @@ -78,6 +79,7 @@ 14.12 messager = Messager.instance0(context); 14.13 javadocReader = JavadocClassReader.instance0(context); 14.14 javadocEnter = JavadocEnter.instance0(context); 14.15 + uniquefiles = new HashSet<>(); 14.16 } 14.17 14.18 /** 14.19 @@ -148,9 +150,7 @@ 14.20 String name = it.head; 14.21 if (!docClasses && fm != null && name.endsWith(".java") && new File(name).exists()) { 14.22 JavaFileObject fo = fm.getJavaFileObjects(name).iterator().next(); 14.23 - docenv.notice("main.Loading_source_file", name); 14.24 - JCCompilationUnit tree = parse(fo); 14.25 - classTrees.append(tree); 14.26 + parse(fo, classTrees, true); 14.27 } else if (isValidPackageName(name)) { 14.28 names = names.append(name); 14.29 } else if (name.endsWith(".java")) { 14.30 @@ -163,9 +163,7 @@ 14.31 } 14.32 } 14.33 for (JavaFileObject fo: fileObjects) { 14.34 - docenv.notice("main.Loading_source_file", fo.getName()); 14.35 - JCCompilationUnit tree = parse(fo); 14.36 - classTrees.append(tree); 14.37 + parse(fo, classTrees, true); 14.38 } 14.39 14.40 if (!docClasses) { 14.41 @@ -213,7 +211,7 @@ 14.42 * .java files found in such a directory to args. 14.43 */ 14.44 private void parsePackageClasses(String name, 14.45 - Iterable<JavaFileObject> files, 14.46 + List<JavaFileObject> files, 14.47 ListBuffer<JCCompilationUnit> trees, 14.48 List<String> excludedPackages) 14.49 throws IOException { 14.50 @@ -221,7 +219,6 @@ 14.51 return; 14.52 } 14.53 14.54 - boolean hasFiles = false; 14.55 docenv.notice("main.Loading_source_files_for_package", name); 14.56 14.57 if (files == null) { 14.58 @@ -238,19 +235,22 @@ 14.59 } 14.60 files = lb.toList(); 14.61 } 14.62 + if (files.nonEmpty()) { 14.63 + for (JavaFileObject fo : files) { 14.64 + parse(fo, trees, false); 14.65 + } 14.66 + } else { 14.67 + messager.warning(Messager.NOPOS, "main.no_source_files_for_package", 14.68 + name.replace(File.separatorChar, '.')); 14.69 + } 14.70 + } 14.71 14.72 - Set<JavaFileObject> ufiles = new HashSet<>(); 14.73 - for (JavaFileObject fo : files) { 14.74 - if (ufiles.add(fo)) { // ignore duplicates 14.75 - // messager.notice("main.Loading_source_file", fn); 14.76 - trees.append(parse(fo)); 14.77 - hasFiles = true; 14.78 - } 14.79 - } 14.80 - 14.81 - if (!hasFiles) { 14.82 - messager.warning(Messager.NOPOS, "main.no_source_files_for_package", 14.83 - name.replace(File.separatorChar, '.')); 14.84 + private void parse(JavaFileObject fo, ListBuffer<JCCompilationUnit> trees, 14.85 + boolean trace) { 14.86 + if (uniquefiles.add(fo)) { // ignore duplicates 14.87 + if (trace) 14.88 + docenv.notice("main.Loading_source_file", fo.getName()); 14.89 + trees.append(parse(fo)); 14.90 } 14.91 } 14.92
15.1 --- a/test/com/sun/javadoc/testLinkOption/TestLinkOption.java Wed Apr 30 11:17:22 2014 -0700 15.2 +++ b/test/com/sun/javadoc/testLinkOption/TestLinkOption.java Wed Apr 30 23:59:45 2014 -0700 15.3 @@ -23,18 +23,20 @@ 15.4 15.5 /* 15.6 * @test 15.7 - * @bug 4720957 5020118 8026567 15.8 + * @bug 4720957 5020118 8026567 8038976 15.9 * @summary Test to make sure that -link and -linkoffline link to 15.10 - * right files. 15.11 + * right files, and URLs with and without trailing slash are accepted. 15.12 * @author jamieh 15.13 * @library ../lib/ 15.14 * @build JavadocTester TestLinkOption 15.15 * @run main TestLinkOption 15.16 */ 15.17 15.18 +import java.io.File; 15.19 + 15.20 public class TestLinkOption extends JavadocTester { 15.21 15.22 - private static final String BUG_ID = "4720957-5020118"; 15.23 + private static final String BUG_ID = "4720957-5020118-8038976"; 15.24 15.25 //Generate the documentation using -linkoffline and a URL as the first parameter. 15.26 private static final String[] ARGS1 = new String[] { 15.27 @@ -83,7 +85,34 @@ 15.28 } 15.29 }; 15.30 private static final String[][] NEGATED_TEST2 = NO_TEST; 15.31 - 15.32 + /* 15.33 + * Create the documentation using the -link option, vary the behavior with 15.34 + * both trailing and no trailing slash. We are only interested in ensuring 15.35 + * that the command executes with no errors or related warnings. 15.36 + */ 15.37 + static String[] createArguments(boolean withTrailingSlash) { 15.38 + String packagePath = new File(BUG_ID + "-1").getAbsolutePath(); 15.39 + String outputDirName = BUG_ID; 15.40 + if (withTrailingSlash) { 15.41 + // add the trailing slash, if it is not present! 15.42 + if (!packagePath.endsWith(FS)) { 15.43 + packagePath = packagePath + FS; 15.44 + } 15.45 + outputDirName = outputDirName + "-3"; 15.46 + } else { 15.47 + // remove the trailing slash, if it is present! 15.48 + if (packagePath.endsWith(FS)) { 15.49 + packagePath = packagePath.substring(0, packagePath.length() - 1); 15.50 + } 15.51 + outputDirName = outputDirName + "-4"; 15.52 + } 15.53 + String args[] = { 15.54 + "-d", outputDirName, "-sourcepath", SRC_DIR, 15.55 + "-link", "file:///" + packagePath, "-package", "pkg2" 15.56 + }; 15.57 + System.out.println("packagePath: " + packagePath); 15.58 + return args; 15.59 + } 15.60 /** 15.61 * The entry point of the test. 15.62 * @param args the array of command line arguments. 15.63 @@ -92,6 +121,12 @@ 15.64 TestLinkOption tester = new TestLinkOption(); 15.65 run(tester, ARGS1, TEST1, NEGATED_TEST1); 15.66 run(tester, ARGS2, TEST2, NEGATED_TEST2); 15.67 + tester.runJavadoc(createArguments(true)); // with trailing slash 15.68 + tester.runJavadoc(createArguments(false)); // without trailing slash 15.69 + tester.printSummary(); 15.70 + if (tester.getWarningOutput().contains("warning - Error fetching URL")) { 15.71 + throw new Error("URL rejected ?"); 15.72 + } 15.73 tester.printSummary(); 15.74 } 15.75
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/tools/javac/DefiniteAssignment/T8039026.java Wed Apr 30 23:59:45 2014 -0700 16.3 @@ -0,0 +1,21 @@ 16.4 +/* 16.5 + * @test /nodynamiccopyright/ 16.6 + * @bug 8039026 16.7 + * @summary Definitely unassigned field can be accessed 16.8 + * @compile/fail/ref=T8039026.out -XDrawDiagnostics T8039026.java 16.9 + */ 16.10 + 16.11 +public class T8039026 { 16.12 + final int x,y,z; 16.13 + final int a = this.y; // <- error 16.14 + { 16.15 + int b = true ? this.x : 0; // <- error 16.16 + System.out.println(this.x); // <- error 16.17 + this.y = 1; 16.18 + } 16.19 + T8039026() { 16.20 + this.x = 1; // <- no error! 16.21 + this.y = 1; // <- error 16.22 + this.z = this.x; // <- no error 16.23 + } 16.24 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/test/tools/javac/DefiniteAssignment/T8039026.out Wed Apr 30 23:59:45 2014 -0700 17.3 @@ -0,0 +1,4 @@ 17.4 +T8039026.java:10:23: compiler.err.var.might.not.have.been.initialized: y 17.5 +T8039026.java:12:28: compiler.err.var.might.not.have.been.initialized: x 17.6 +T8039026.java:18:13: compiler.err.var.might.already.be.assigned: y 17.7 +3 errors
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/test/tools/javac/T8029002/MultipleUpperBoundsIncorporationTest.java Wed Apr 30 23:59:45 2014 -0700 18.3 @@ -0,0 +1,72 @@ 18.4 +/* 18.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 18.7 + * 18.8 + * This code is free software; you can redistribute it and/or modify it 18.9 + * under the terms of the GNU General Public License version 2 only, as 18.10 + * published by the Free Software Foundation. 18.11 + * 18.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 18.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18.15 + * version 2 for more details (a copy is included in the LICENSE file that 18.16 + * accompanied this code). 18.17 + * 18.18 + * You should have received a copy of the GNU General Public License version 18.19 + * 2 along with this work; if not, write to the Free Software Foundation, 18.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18.21 + * 18.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 18.23 + * or visit www.oracle.com if you need additional information or have any 18.24 + * questions. 18.25 + */ 18.26 + 18.27 +/* 18.28 + * @test 18.29 + * @bug 8029002 18.30 + * @summary javac should take multiple upper bounds into account in incorporation 18.31 + * @compile MultipleUpperBoundsIncorporationTest.java 18.32 + */ 18.33 + 18.34 +import java.util.ArrayList; 18.35 +import java.util.List; 18.36 + 18.37 +public class MultipleUpperBoundsIncorporationTest { 18.38 + 18.39 + static class TestCase1 { 18.40 + interface Task<E extends Exception> {} 18.41 + 18.42 + class Comparator<T> {} 18.43 + 18.44 + class CustomException extends Exception {} 18.45 + 18.46 + class TaskQueue<E extends Exception, T extends Task<E>> {} 18.47 + 18.48 + abstract class Test { 18.49 + abstract <E extends Exception, T extends Task<E>> TaskQueue<E, T> create(Comparator<? super T> comparator); 18.50 + 18.51 + void f(Comparator<Task<CustomException>> comp) { 18.52 + TaskQueue<CustomException, Task<CustomException>> queue = create(comp); 18.53 + queue.getClass(); 18.54 + } 18.55 + } 18.56 + } 18.57 + 18.58 + static class TestCase2 { 18.59 + public <T, E extends List<T>> E typedNull() { 18.60 + return null; 18.61 + } 18.62 + 18.63 + public void call() { 18.64 + ArrayList<String> list = typedNull(); 18.65 + } 18.66 + } 18.67 + 18.68 + static class TestCase3 { 18.69 + interface I extends Iterable<String> {} 18.70 + 18.71 + <T, Exp extends Iterable<T>> Exp typedNull() { return null; } 18.72 + I i = typedNull(); 18.73 + } 18.74 + 18.75 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/test/tools/javac/annotations/typeAnnotations/newlocations/AfterMethodTypeParams.java Wed Apr 30 23:59:45 2014 -0700 19.3 @@ -0,0 +1,138 @@ 19.4 +/* 19.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 19.7 + * 19.8 + * This code is free software; you can redistribute it and/or modify it 19.9 + * under the terms of the GNU General Public License version 2 only, as 19.10 + * published by the Free Software Foundation. 19.11 + * 19.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 19.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19.15 + * version 2 for more details (a copy is included in the LICENSE file that 19.16 + * accompanied this code). 19.17 + * 19.18 + * You should have received a copy of the GNU General Public License version 19.19 + * 2 along with this work; if not, write to the Free Software Foundation, 19.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19.21 + * 19.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19.23 + * or visit www.oracle.com if you need additional information or have any 19.24 + * questions. 19.25 + */ 19.26 + 19.27 +/** 19.28 + * @test 19.29 + * @bug 8038788 19.30 + * @summary Verify proper handling of annotations after method's type parameters. 19.31 + * @build AfterMethodTypeParams 19.32 + * @run main AfterMethodTypeParams 19.33 + */ 19.34 + 19.35 +import java.io.IOException; 19.36 +import java.io.StringWriter; 19.37 +import java.net.URI; 19.38 +import java.util.*; 19.39 + 19.40 +import javax.lang.model.element.Name; 19.41 +import javax.tools.*; 19.42 + 19.43 +import com.sun.source.tree.*; 19.44 +import com.sun.source.util.*; 19.45 + 19.46 +public class AfterMethodTypeParams { 19.47 + 19.48 + public static void main(String... args) throws IOException { 19.49 + new AfterMethodTypeParams().run(); 19.50 + } 19.51 + 19.52 + void run() throws IOException { 19.53 + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 19.54 + 19.55 + for (TestCase tc : testCases) { 19.56 + String test = TEMPLATE.replace("CONTENT", tc.snippet); 19.57 + List<JavaFileObject> files = Arrays.asList(new MyFileObject(test)); 19.58 + StringWriter out = new StringWriter(); 19.59 + List<String> options = Arrays.asList("-XDrawDiagnostics", "-XDshouldStopPolicy=FLOW"); 19.60 + JavacTask task = (JavacTask) compiler.getTask(out, null, null, options, null, files); 19.61 + 19.62 + new TreePathScanner<Void, Void>() { 19.63 + boolean seenAnnotation; 19.64 + @Override 19.65 + public Void visitAnnotation(AnnotationTree node, Void p) { 19.66 + Name name = ((IdentifierTree) node.getAnnotationType()).getName(); 19.67 + seenAnnotation |= name.contentEquals("TA") || name.contentEquals("DA"); 19.68 + return null; 19.69 + } 19.70 + @Override 19.71 + public Void visitCompilationUnit(CompilationUnitTree node, Void p) { 19.72 + super.visitCompilationUnit(node, p); 19.73 + if (!seenAnnotation) 19.74 + error(test, "Annotation was missing"); 19.75 + return null; 19.76 + } 19.77 + }.scan(task.parse(), null); 19.78 + 19.79 + task.analyze(); 19.80 + 19.81 + if (!tc.error.equals(out.toString().trim())) { 19.82 + error(test, "Incorrect errors: " + out.toString()); 19.83 + } 19.84 + } 19.85 + 19.86 + if (errors > 0) { 19.87 + throw new IllegalStateException("Errors found"); 19.88 + } 19.89 + } 19.90 + 19.91 + int errors; 19.92 + 19.93 + void error(String code, String error) { 19.94 + System.out.println("Error detected: " + error); 19.95 + System.out.println("Code:"); 19.96 + System.out.println(code); 19.97 + errors++; 19.98 + } 19.99 + 19.100 + static String TEMPLATE = 19.101 + "import java.lang.annotation.*;\n" + 19.102 + "public class Test {\n" + 19.103 + " CONTENT\n" + 19.104 + "}\n" + 19.105 + "@Target({ElementType.METHOD, ElementType.CONSTRUCTOR})\n" + 19.106 + "@interface DA { }\n" + 19.107 + "@Target(ElementType.TYPE_USE)\n" + 19.108 + "@interface TA { }\n"; 19.109 + 19.110 + static class MyFileObject extends SimpleJavaFileObject { 19.111 + final String text; 19.112 + public MyFileObject(String text) { 19.113 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 19.114 + this.text = text; 19.115 + } 19.116 + @Override 19.117 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 19.118 + return text; 19.119 + } 19.120 + } 19.121 + 19.122 + static TestCase[] testCases = new TestCase[] { 19.123 + new TestCase("<T> @DA int foo1() { return 0;}", ""), 19.124 + new TestCase("<T> @DA void foo2() { }", ""), 19.125 + new TestCase("<T> @TA int foo3() { return 0;}", ""), 19.126 + new TestCase("<T> @TA void foo4() { }", 19.127 + "Test.java:3:9: compiler.err.annotation.type.not.applicable"), 19.128 + new TestCase("<T> @DA Test() { }", "Test.java:3:9: compiler.err.illegal.start.of.type"), 19.129 + new TestCase("<T> @TA Test() { }", "Test.java:3:9: compiler.err.illegal.start.of.type"), 19.130 + }; 19.131 + 19.132 + static class TestCase { 19.133 + final String snippet; 19.134 + final String error; 19.135 + public TestCase(String snippet, String error) { 19.136 + this.snippet = snippet; 19.137 + this.error = error; 19.138 + } 19.139 + } 19.140 +} 19.141 +
20.1 --- a/test/tools/javac/classfiles/InnerClasses/SyntheticClasses.java Wed Apr 30 11:17:22 2014 -0700 20.2 +++ b/test/tools/javac/classfiles/InnerClasses/SyntheticClasses.java Wed Apr 30 23:59:45 2014 -0700 20.3 @@ -41,7 +41,7 @@ 20.4 20.5 private void run() throws IOException, ConstantPoolException { 20.6 File testClasses = new File(System.getProperty("test.classes")); 20.7 - for (File classFile : testClasses.listFiles()) { 20.8 + for (File classFile : testClasses.listFiles(f -> f.getName().endsWith(".class"))) { 20.9 ClassFile cf = ClassFile.read(classFile); 20.10 if (cf.getName().matches(".*\\$[0-9]+")) { 20.11 EnclosingMethod_attribute encl =
21.1 --- a/test/tools/javac/diags/examples.not-yet.txt Wed Apr 30 11:17:22 2014 -0700 21.2 +++ b/test/tools/javac/diags/examples.not-yet.txt Wed Apr 30 23:59:45 2014 -0700 21.3 @@ -111,3 +111,4 @@ 21.4 compiler.warn.unknown.enum.constant.reason # in bad class file 21.5 compiler.warn.override.equals.but.not.hashcode # when a class overrides equals but not hashCode method from Object 21.6 compiler.err.cant.inherit.from.anon # error for subclass of anonymous class 21.7 +compiler.misc.bad.const.pool.entry # constant pool entry has wrong type
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/test/tools/javac/diags/examples/LambdaBodyNeitherValueNorVoidCompatible.java Wed Apr 30 23:59:45 2014 -0700 22.3 @@ -0,0 +1,46 @@ 22.4 +/* 22.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 22.7 + * 22.8 + * This code is free software; you can redistribute it and/or modify it 22.9 + * under the terms of the GNU General Public License version 2 only, as 22.10 + * published by the Free Software Foundation. 22.11 + * 22.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 22.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 22.15 + * version 2 for more details (a copy is included in the LICENSE file that 22.16 + * accompanied this code). 22.17 + * 22.18 + * You should have received a copy of the GNU General Public License version 22.19 + * 2 along with this work; if not, write to the Free Software Foundation, 22.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22.21 + * 22.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22.23 + * or visit www.oracle.com if you need additional information or have any 22.24 + * questions. 22.25 + */ 22.26 + 22.27 +// key: compiler.err.lambda.body.neither.value.nor.void.compatible 22.28 +// key: compiler.err.cant.apply.symbol 22.29 +// key: compiler.misc.incompatible.ret.type.in.lambda 22.30 +// key: compiler.misc.missing.ret.val 22.31 +// key: compiler.misc.no.conforming.assignment.exists 22.32 + 22.33 +class LambdaBodyNeitherValueNorVoidCompatible { 22.34 + interface I { 22.35 + String f(String x); 22.36 + } 22.37 + 22.38 + static void foo(I i) {} 22.39 + 22.40 + void m() { 22.41 + foo((x) -> { 22.42 + if (x == null) { 22.43 + return; 22.44 + } else { 22.45 + return x; 22.46 + } 22.47 + }); 22.48 + } 22.49 +}
23.1 --- a/test/tools/javac/lambda/ErroneousLambdaExpr.java Wed Apr 30 11:17:22 2014 -0700 23.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 23.3 @@ -1,66 +0,0 @@ 23.4 -/* 23.5 - * Copyright (c) 2012, 2013 Oracle and/or its affiliates. All rights reserved. 23.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 23.7 - * 23.8 - * This code is free software; you can redistribute it and/or modify it 23.9 - * under the terms of the GNU General Public License version 2 only, as 23.10 - * published by the Free Software Foundation. 23.11 - * 23.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 23.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 23.15 - * version 2 for more details (a copy is included in the LICENSE file that 23.16 - * accompanied this code). 23.17 - * 23.18 - * You should have received a copy of the GNU General Public License version 23.19 - * 2 along with this work; if not, write to the Free Software Foundation, 23.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 23.21 - * 23.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 23.23 - * or visit www.oracle.com if you need additional information or have any 23.24 - * questions. 23.25 - */ 23.26 - 23.27 -/* 23.28 - * @test 23.29 - * @bug 8003280 23.30 - * @summary Add lambda tests 23.31 - * stale state after speculative attribution round leads to missing classfiles 23.32 - * @compile/fail/ref=ErroneousLambdaExpr.out -XDrawDiagnostics ErroneousLambdaExpr.java 23.33 - */ 23.34 -public class ErroneousLambdaExpr<T> { 23.35 - 23.36 - static int assertionCount = 0; 23.37 - 23.38 - static void assertTrue(boolean cond) { 23.39 - assertionCount++; 23.40 - if (!cond) 23.41 - throw new AssertionError(); 23.42 - } 23.43 - 23.44 - interface SAM1<X> { 23.45 - X m(X t, String s); 23.46 - } 23.47 - 23.48 - interface SAM2 { 23.49 - void m(String s, int i); 23.50 - } 23.51 - 23.52 - interface SAM3<X> { 23.53 - X m(X t, String s, int i); 23.54 - } 23.55 - 23.56 - void call(SAM1<T> s1) { assertTrue(true); } 23.57 - 23.58 - void call(SAM2 s2) { assertTrue(false); } 23.59 - 23.60 - void call(SAM3<T> s3) { assertTrue(false); } 23.61 - 23.62 - public static void main(String[] args) { 23.63 - ErroneousLambdaExpr<StringBuilder> test = 23.64 - new ErroneousLambdaExpr<>(); 23.65 - 23.66 - test.call((builder, string) -> { builder.append(string); return builder; }); 23.67 - assertTrue(assertionCount == 1); 23.68 - } 23.69 -}
24.1 --- a/test/tools/javac/lambda/ErroneousLambdaExpr.out Wed Apr 30 11:17:22 2014 -0700 24.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 24.3 @@ -1,2 +0,0 @@ 24.4 -ErroneousLambdaExpr.java:63:13: compiler.err.ref.ambiguous: call, kindname.method, call(ErroneousLambdaExpr.SAM1<T>), ErroneousLambdaExpr, kindname.method, call(ErroneousLambdaExpr.SAM2), ErroneousLambdaExpr 24.5 -1 error
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 25.2 +++ b/test/tools/javac/lambda/LambdaExprLeadsToMissingClassFilesTest.java Wed Apr 30 23:59:45 2014 -0700 25.3 @@ -0,0 +1,66 @@ 25.4 +/* 25.5 + * Copyright (c) 2012, 2014 Oracle and/or its affiliates. All rights reserved. 25.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 25.7 + * 25.8 + * This code is free software; you can redistribute it and/or modify it 25.9 + * under the terms of the GNU General Public License version 2 only, as 25.10 + * published by the Free Software Foundation. 25.11 + * 25.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 25.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 25.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 25.15 + * version 2 for more details (a copy is included in the LICENSE file that 25.16 + * accompanied this code). 25.17 + * 25.18 + * You should have received a copy of the GNU General Public License version 25.19 + * 2 along with this work; if not, write to the Free Software Foundation, 25.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 25.21 + * 25.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 25.23 + * or visit www.oracle.com if you need additional information or have any 25.24 + * questions. 25.25 + */ 25.26 + 25.27 +/* 25.28 + * @test 25.29 + * @bug 8003280 25.30 + * @summary Add lambda tests 25.31 + * stale state after speculative attribution round leads to missing classfiles 25.32 + */ 25.33 +public class LambdaExprLeadsToMissingClassFilesTest<T> { 25.34 + 25.35 + static int assertionCount = 0; 25.36 + 25.37 + static void assertTrue(boolean cond) { 25.38 + assertionCount++; 25.39 + if (!cond) { 25.40 + throw new AssertionError(); 25.41 + } 25.42 + } 25.43 + 25.44 + interface SAM1<X> { 25.45 + X m(X t, String s); 25.46 + } 25.47 + 25.48 + interface SAM2 { 25.49 + void m(String s, int i); 25.50 + } 25.51 + 25.52 + interface SAM3<X> { 25.53 + X m(X t, String s, int i); 25.54 + } 25.55 + 25.56 + void call(SAM1<T> s1) { assertTrue(true); } 25.57 + 25.58 + void call(SAM2 s2) { assertTrue(false); } 25.59 + 25.60 + void call(SAM3<T> s3) { assertTrue(false); } 25.61 + 25.62 + public static void main(String[] args) { 25.63 + LambdaExprLeadsToMissingClassFilesTest<StringBuilder> test = 25.64 + new LambdaExprLeadsToMissingClassFilesTest<>(); 25.65 + 25.66 + test.call((builder, string) -> { builder.append(string); return builder; }); 25.67 + assertTrue(assertionCount == 1); 25.68 + } 25.69 +}
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/test/tools/javac/lambda/MostSpecific09.java Wed Apr 30 23:59:45 2014 -0700 26.3 @@ -0,0 +1,81 @@ 26.4 +/* 26.5 + * @test /nodynamiccopyright/ 26.6 + * @bug 8029718 26.7 + * @summary Should always use lambda body structure to disambiguate overload resolution 26.8 + * @compile/fail/ref=MostSpecific09.out -XDrawDiagnostics -XDshouldStopPolicy=ATTR -XDverboseResolution=applicable,success MostSpecific09.java 26.9 + */ 26.10 + 26.11 +class MostSpecific09 { 26.12 + 26.13 + interface I { 26.14 + String xoo(String x); 26.15 + } 26.16 + 26.17 + interface J { 26.18 + void xoo(int x); 26.19 + } 26.20 + 26.21 + static void foo(I i) {} 26.22 + static void foo(J j) {} 26.23 + 26.24 + static void moo(I i) {} 26.25 + static void moo(J j) {} 26.26 + 26.27 + void m() { 26.28 + foo((x) -> { return x += 1; }); 26.29 + foo((x) -> { return ""; }); 26.30 + foo((x) -> { System.out.println(""); }); 26.31 + foo((x) -> { return ""; System.out.println(""); }); 26.32 + foo((x) -> { throw new RuntimeException(); }); 26.33 + foo((x) -> { while (true); }); 26.34 + 26.35 + foo((x) -> x += 1); 26.36 + foo((x) -> ""); 26.37 + } 26.38 + 26.39 + /* any return statement that is not in the body of the lambda but in an 26.40 + * inner class or another lambda should be ignored for value void compatibility 26.41 + * determination. 26.42 + */ 26.43 + void m1() { 26.44 + boolean cond = true; 26.45 + foo((x) -> { 26.46 + if (cond) { 26.47 + return ""; 26.48 + } 26.49 + System.out.println(""); 26.50 + }); 26.51 + 26.52 + foo((x)->{ 26.53 + class Bar { 26.54 + String m() { 26.55 + return "from Bar.m()"; 26.56 + } 26.57 + } 26.58 + class Boo { 26.59 + Bar b = new Bar (){ 26.60 + String m() { 26.61 + return "from Bar$1.m()"; 26.62 + } 26.63 + }; 26.64 + } 26.65 + moo((y) -> { return ""; }); 26.66 + return; 26.67 + }); 26.68 + 26.69 + foo((x)->{ 26.70 + class Bar { 26.71 + void m() {} 26.72 + } 26.73 + class Boo { 26.74 + Bar b = new Bar (){ 26.75 + void m() { 26.76 + return; 26.77 + } 26.78 + }; 26.79 + } 26.80 + moo((y) -> { System.out.println(""); }); 26.81 + return ""; 26.82 + }); 26.83 + } 26.84 +}
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/test/tools/javac/lambda/MostSpecific09.out Wed Apr 30 23:59:45 2014 -0700 27.3 @@ -0,0 +1,27 @@ 27.4 +MostSpecific09.java:25:9: compiler.note.verbose.resolve.multi: foo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, foo(MostSpecific09.I), null)} 27.5 +MostSpecific09.java:26:9: compiler.note.verbose.resolve.multi: foo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, foo(MostSpecific09.I), null)} 27.6 +MostSpecific09.java:27:9: compiler.note.verbose.resolve.multi: foo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, foo(MostSpecific09.J), null)} 27.7 +MostSpecific09.java:27:32: compiler.note.verbose.resolve.multi: println, java.io.PrintStream, 1, BASIC, java.lang.String, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, println(java.lang.Object), null),(compiler.misc.applicable.method.found: 1, println(java.lang.String), null)} 27.8 +MostSpecific09.java:28:13: compiler.err.lambda.body.neither.value.nor.void.compatible 27.9 +MostSpecific09.java:28:9: compiler.err.cant.apply.symbols: kindname.method, foo, @680,{(compiler.misc.inapplicable.method: kindname.method, MostSpecific09, foo(MostSpecific09.I), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.missing.ret.val: java.lang.String)))),(compiler.misc.inapplicable.method: kindname.method, MostSpecific09, foo(MostSpecific09.J), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.unexpected.ret.val)))} 27.10 +MostSpecific09.java:28:43: compiler.note.verbose.resolve.multi: println, java.io.PrintStream, 1, BASIC, java.lang.String, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, println(java.lang.Object), null),(compiler.misc.applicable.method.found: 1, println(java.lang.String), null)} 27.11 +MostSpecific09.java:29:9: compiler.err.ref.ambiguous: foo, kindname.method, foo(MostSpecific09.I), MostSpecific09, kindname.method, foo(MostSpecific09.J), MostSpecific09 27.12 +MostSpecific09.java:29:28: compiler.note.verbose.resolve.multi: <init>, java.lang.RuntimeException, 0, BASIC, compiler.misc.no.args, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, java.lang.RuntimeException(), null)} 27.13 +MostSpecific09.java:30:9: compiler.err.ref.ambiguous: foo, kindname.method, foo(MostSpecific09.I), MostSpecific09, kindname.method, foo(MostSpecific09.J), MostSpecific09 27.14 +MostSpecific09.java:32:9: compiler.err.ref.ambiguous: foo, kindname.method, foo(MostSpecific09.I), MostSpecific09, kindname.method, foo(MostSpecific09.J), MostSpecific09 27.15 +MostSpecific09.java:33:9: compiler.note.verbose.resolve.multi: foo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, foo(MostSpecific09.I), null)} 27.16 +MostSpecific09.java:42:13: compiler.err.lambda.body.neither.value.nor.void.compatible 27.17 +MostSpecific09.java:42:9: compiler.err.cant.apply.symbols: kindname.method, foo, @1129,{(compiler.misc.inapplicable.method: kindname.method, MostSpecific09, foo(MostSpecific09.I), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.missing.ret.val: java.lang.String)))),(compiler.misc.inapplicable.method: kindname.method, MostSpecific09, foo(MostSpecific09.J), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.unexpected.ret.val)))} 27.18 +MostSpecific09.java:46:23: compiler.note.verbose.resolve.multi: println, java.io.PrintStream, 1, BASIC, java.lang.String, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, println(java.lang.Object), null),(compiler.misc.applicable.method.found: 1, println(java.lang.String), null)} 27.19 +MostSpecific09.java:49:9: compiler.note.verbose.resolve.multi: foo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, foo(MostSpecific09.J), null)} 27.20 +MostSpecific09.java:56:25: compiler.note.verbose.resolve.multi: <init>, Bar, 0, BASIC, compiler.misc.no.args, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, Bar(), null)} 27.21 +MostSpecific09.java:56:35: compiler.note.verbose.resolve.multi: <init>, Bar, 0, BASIC, compiler.misc.no.args, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, Bar(), null)} 27.22 +MostSpecific09.java:56:25: compiler.note.verbose.resolve.multi: <init>, compiler.misc.anonymous.class: MostSpecific09$1Boo$1, 0, BASIC, compiler.misc.no.args, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, compiler.misc.anonymous.class: MostSpecific09$1Boo$1(), null)} 27.23 +MostSpecific09.java:62:13: compiler.note.verbose.resolve.multi: moo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, moo(MostSpecific09.I), null)} 27.24 +MostSpecific09.java:66:9: compiler.note.verbose.resolve.multi: foo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, foo(MostSpecific09.I), null)} 27.25 +MostSpecific09.java:71:25: compiler.note.verbose.resolve.multi: <init>, Bar, 0, BASIC, compiler.misc.no.args, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, Bar(), null)} 27.26 +MostSpecific09.java:71:35: compiler.note.verbose.resolve.multi: <init>, Bar, 0, BASIC, compiler.misc.no.args, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, Bar(), null)} 27.27 +MostSpecific09.java:71:25: compiler.note.verbose.resolve.multi: <init>, compiler.misc.anonymous.class: MostSpecific09$2Boo$1, 0, BASIC, compiler.misc.no.args, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, compiler.misc.anonymous.class: MostSpecific09$2Boo$1(), null)} 27.28 +MostSpecific09.java:77:13: compiler.note.verbose.resolve.multi: moo, MostSpecific09, 0, BASIC, compiler.misc.type.none, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, moo(MostSpecific09.J), null)} 27.29 +MostSpecific09.java:77:36: compiler.note.verbose.resolve.multi: println, java.io.PrintStream, 1, BASIC, java.lang.String, compiler.misc.no.args,{(compiler.misc.applicable.method.found: 0, println(java.lang.Object), null),(compiler.misc.applicable.method.found: 1, println(java.lang.String), null)} 27.30 +7 errors
28.1 --- a/test/tools/javac/lambda/TargetType01.java Wed Apr 30 11:17:22 2014 -0700 28.2 +++ b/test/tools/javac/lambda/TargetType01.java Wed Apr 30 23:59:45 2014 -0700 28.3 @@ -1,5 +1,5 @@ 28.4 /* 28.5 - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 28.6 + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 28.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 28.8 * 28.9 * This code is free software; you can redistribute it and/or modify it 28.10 @@ -42,6 +42,10 @@ 28.11 static String M(F_S_S f){ return null; } 28.12 28.13 static { 28.14 - M(x1 -> { return M( x2 -> { return x1 + x2; });}); //ambiguous 28.15 + M(x1 -> { 28.16 + return M( x2 -> { 28.17 + return x1 + x2; 28.18 + }); 28.19 + }); //ambiguous 28.20 } 28.21 }
29.1 --- a/test/tools/javac/lambda/TargetType01.out Wed Apr 30 11:17:22 2014 -0700 29.2 +++ b/test/tools/javac/lambda/TargetType01.out Wed Apr 30 23:59:45 2014 -0700 29.3 @@ -1,3 +1,3 @@ 29.4 TargetType01.java:45:9: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01 29.5 -TargetType01.java:45:26: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01 29.6 +TargetType01.java:46:20: compiler.err.ref.ambiguous: M, kindname.method, M(TargetType01.F_I_I), TargetType01, kindname.method, M(TargetType01.F_S_S), TargetType01 29.7 2 errors
30.1 --- a/test/tools/javac/lambda/TargetType02.java Wed Apr 30 11:17:22 2014 -0700 30.2 +++ b/test/tools/javac/lambda/TargetType02.java Wed Apr 30 23:59:45 2014 -0700 30.3 @@ -1,31 +1,9 @@ 30.4 /* 30.5 - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 30.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 30.7 - * 30.8 - * This code is free software; you can redistribute it and/or modify it 30.9 - * under the terms of the GNU General Public License version 2 only, as 30.10 - * published by the Free Software Foundation. 30.11 - * 30.12 - * This code is distributed in the hope that it will be useful, but WITHOUT 30.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 30.14 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 30.15 - * version 2 for more details (a copy is included in the LICENSE file that 30.16 - * accompanied this code). 30.17 - * 30.18 - * You should have received a copy of the GNU General Public License version 30.19 - * 2 along with this work; if not, write to the Free Software Foundation, 30.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 30.21 - * 30.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 30.23 - * or visit www.oracle.com if you need additional information or have any 30.24 - * questions. 30.25 - */ 30.26 - 30.27 -/* 30.28 - * @test 30.29 - * @bug 8003280 30.30 + * @test /nodynamiccopyright/ 30.31 + * @bug 8003280 8029718 30.32 * @summary Add lambda tests 30.33 * check overload resolution and target type inference w.r.t. generic methods 30.34 + * Should always use lambda body structure to disambiguate overload resolution 30.35 * @author Maurizio Cimadamore 30.36 * @compile/fail/ref=TargetType02.out -XDrawDiagnostics TargetType02.java 30.37 */ 30.38 @@ -47,9 +25,18 @@ 30.39 static <Z extends Number> void call3(S1<Z> s) { } 30.40 static <Z extends String> void call3(S2<Z> s) { } 30.41 30.42 + static <Z extends Number> Z call4(S1<Z> s) { return null; } 30.43 + static <Z extends String> Z call4(S2<Z> s) { return null; } 30.44 + 30.45 void test() { 30.46 call1(i -> { toString(); return i; }); 30.47 call2(i -> { toString(); return i; }); 30.48 call3(i -> { toString(); return i; }); 30.49 + call3(i -> { 30.50 + toString(); 30.51 + return call4(j -> { 30.52 + return j; 30.53 + }); 30.54 + }); 30.55 } 30.56 }
31.1 --- a/test/tools/javac/lambda/TargetType02.out Wed Apr 30 11:17:22 2014 -0700 31.2 +++ b/test/tools/javac/lambda/TargetType02.out Wed Apr 30 23:59:45 2014 -0700 31.3 @@ -1,3 +1,5 @@ 31.4 -TargetType02.java:52:14: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, java.lang.String) 31.5 -TargetType02.java:53:9: compiler.err.ref.ambiguous: call3, kindname.method, <Z>call3(TargetType02.S1<Z>), TargetType02, kindname.method, <Z>call3(TargetType02.S2<Z>), TargetType02 31.6 -2 errors 31.7 +TargetType02.java:33:14: compiler.err.prob.found.req: (compiler.misc.inferred.do.not.conform.to.upper.bounds: java.lang.Integer, java.lang.String) 31.8 +TargetType02.java:34:9: compiler.err.ref.ambiguous: call3, kindname.method, <Z>call3(TargetType02.S1<Z>), TargetType02, kindname.method, <Z>call3(TargetType02.S2<Z>), TargetType02 31.9 +TargetType02.java:35:9: compiler.err.ref.ambiguous: call3, kindname.method, <Z>call3(TargetType02.S1<Z>), TargetType02, kindname.method, <Z>call3(TargetType02.S2<Z>), TargetType02 31.10 +TargetType02.java:37:20: compiler.err.ref.ambiguous: call4, kindname.method, <Z>call4(TargetType02.S1<Z>), TargetType02, kindname.method, <Z>call4(TargetType02.S2<Z>), TargetType02 31.11 +4 errors
32.1 --- a/test/tools/javac/lambda/TargetType21.out Wed Apr 30 11:17:22 2014 -0700 32.2 +++ b/test/tools/javac/lambda/TargetType21.out Wed Apr 30 23:59:45 2014 -0700 32.3 @@ -1,7 +1,5 @@ 32.4 TargetType21.java:28:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM2), TargetType21, kindname.method, <R,A>call(TargetType21.SAM3<R,A>), TargetType21 32.5 -TargetType21.java:31:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM2), TargetType21, kindname.method, <R,A>call(TargetType21.SAM3<R,A>), TargetType21 32.6 -TargetType21.java:32:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM2), TargetType21, kindname.method, <R,A>call(TargetType21.SAM3<R,A>), TargetType21 32.7 -TargetType21.java:32:13: compiler.err.cant.apply.symbol: kindname.method, call, TargetType21.SAM2, @888, kindname.class, TargetType21, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.unexpected.ret.val))) 32.8 -TargetType21.java:33:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM2), TargetType21, kindname.method, <R,A>call(TargetType21.SAM3<R,A>), TargetType21 32.9 -TargetType21.java:33:13: compiler.err.cant.apply.symbol: kindname.method, call, TargetType21.SAM2, @946, kindname.class, TargetType21, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.unexpected.ret.val))) 32.10 -6 errors 32.11 +TargetType21.java:32:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM1), TargetType21, kindname.method, <R,A>call(TargetType21.SAM3<R,A>), TargetType21 32.12 +TargetType21.java:32:13: compiler.err.cant.apply.symbol: kindname.method, call, TargetType21.SAM1, @888, kindname.class, TargetType21, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: java.lang.Object, java.lang.String))) 32.13 +TargetType21.java:33:9: compiler.err.ref.ambiguous: call, kindname.method, call(TargetType21.SAM1), TargetType21, kindname.method, <R,A>call(TargetType21.SAM3<R,A>), TargetType21 32.14 +4 errors
33.1 --- a/test/tools/javac/lambda/TargetType42.java Wed Apr 30 11:17:22 2014 -0700 33.2 +++ b/test/tools/javac/lambda/TargetType42.java Wed Apr 30 23:59:45 2014 -0700 33.3 @@ -1,5 +1,5 @@ 33.4 /* 33.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 33.6 + * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. 33.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 33.8 * 33.9 * This code is free software; you can redistribute it and/or modify it 33.10 @@ -31,12 +31,18 @@ 33.11 class TargetType42 { 33.12 33.13 interface SAM<X, Y> { 33.14 - Y f(X x); 33.15 + Y f(X x); 33.16 } 33.17 33.18 <Z> void m(SAM<String, SAM<Z, Object>> s, Z z) { } 33.19 33.20 void test(Object obj) { 33.21 - m((x)->{ class Foo { }; return (x2)-> { new Foo(); return null; }; }, obj); 33.22 + m((x)->{ 33.23 + class Foo { } 33.24 + return (x2)-> { 33.25 + new Foo(); 33.26 + return null; 33.27 + }; 33.28 + }, obj); 33.29 } 33.30 }
34.1 --- a/test/tools/javac/lambda/lambdaExpression/LambdaTest1.java Wed Apr 30 11:17:22 2014 -0700 34.2 +++ b/test/tools/javac/lambda/lambdaExpression/LambdaTest1.java Wed Apr 30 23:59:45 2014 -0700 34.3 @@ -1,5 +1,5 @@ 34.4 /* 34.5 - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 34.6 + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 34.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 34.8 * 34.9 * This code is free software; you can redistribute it and/or modify it 34.10 @@ -33,7 +33,6 @@ 34.11 import java.util.Collections; 34.12 import java.util.List; 34.13 import java.util.ArrayList; 34.14 -import java.util.Date; 34.15 34.16 public class LambdaTest1 { 34.17
35.1 --- a/test/tools/javac/lambda/lambdaExpression/SamConversionComboTest.java Wed Apr 30 11:17:22 2014 -0700 35.2 +++ b/test/tools/javac/lambda/lambdaExpression/SamConversionComboTest.java Wed Apr 30 23:59:45 2014 -0700 35.3 @@ -1,5 +1,5 @@ 35.4 /* 35.5 - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 35.6 + * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 35.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 35.8 * 35.9 * This code is free software; you can redistribute it and/or modify it 35.10 @@ -209,7 +209,11 @@ 35.11 final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); 35.12 DiagnosticChecker dc = new DiagnosticChecker(); 35.13 JavacTask ct = (JavacTask)tool.getTask(null, null, dc, null, null, Arrays.asList(samSourceFile, clientSourceFile)); 35.14 - ct.analyze(); 35.15 + try { 35.16 + ct.analyze(); 35.17 + } catch (Exception e) { 35.18 + throw new AssertionError("failing SAM source file \n" + samSourceFile + "\n\n" + "failing client source file \n"+ clientSourceFile); 35.19 + } 35.20 if (dc.errorFound == checkSamConversion()) { 35.21 throw new AssertionError(samSourceFile + "\n\n" + clientSourceFile); 35.22 }
36.1 --- a/test/tools/javac/processing/environment/round/ErroneousAnnotations.out Wed Apr 30 11:17:22 2014 -0700 36.2 +++ b/test/tools/javac/processing/environment/round/ErroneousAnnotations.out Wed Apr 30 23:59:45 2014 -0700 36.3 @@ -1,4 +1,3 @@ 36.4 ErroneousAnnotations.java:8:2: compiler.err.cant.resolve: kindname.class, Undefined, , 36.5 ErroneousAnnotations.java:10:6: compiler.err.cant.resolve.location: kindname.class, Undefined, , , (compiler.misc.location: kindname.class, ErroneousAnnotations, null) 36.6 2 errors 36.7 -Results: []
37.1 --- a/test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java Wed Apr 30 11:17:22 2014 -0700 37.2 +++ b/test/tools/javac/processing/environment/round/TestElementsAnnotatedWith.java Wed Apr 30 23:59:45 2014 -0700 37.3 @@ -93,7 +93,8 @@ 37.4 roundEnvironment. 37.5 getElementsAnnotatedWith(elements.getTypeElement(annotatedElementInfo.annotationName())); 37.6 37.7 - System.err.println("Results: " + resultsMeta); 37.8 + if (!resultsMeta.isEmpty()) 37.9 + System.err.println("Results: " + resultsMeta); 37.10 37.11 if (resultsMeta.size() != annotatedElementInfo.expectedSize()) { 37.12 failed = true;
38.1 --- a/test/tools/javadoc/parser/7091528/T7091528.java Wed Apr 30 11:17:22 2014 -0700 38.2 +++ b/test/tools/javadoc/parser/7091528/T7091528.java Wed Apr 30 23:59:45 2014 -0700 38.3 @@ -23,7 +23,7 @@ 38.4 38.5 /** 38.6 * @test 38.7 - * @bug 7091528 8029145 38.8 + * @bug 7091528 8029145 8037484 38.9 * @summary ensures javadoc parses unique source files and ignores all class files 38.10 * @compile p/C1.java p/q/C2.java 38.11 * @run main T7091528 38.12 @@ -50,6 +50,16 @@ 38.13 "-sourcepath", testSrc.getAbsolutePath(), 38.14 "-subpackages", 38.15 "p:p.q"); 38.16 + File testPkgDir = new File(testSrc, "p"); 38.17 + File testFile = new File(testPkgDir, "C3.java"); 38.18 + runTest("-d", ".", 38.19 + "-sourcepath", testSrc.getAbsolutePath(), 38.20 + testFile.getAbsolutePath(), 38.21 + "p"); 38.22 + runTest("-d", ".", 38.23 + "-classpath", testSrc.getAbsolutePath(), 38.24 + testFile.getAbsolutePath(), 38.25 + "p"); 38.26 38.27 } 38.28 void runTest(String... args) { 38.29 @@ -65,7 +75,7 @@ 38.30 } 38.31 38.32 if (rc != 0) 38.33 - System.err.println("javadoc failed: exit code = " + rc); 38.34 + throw new Error("javadoc failed: exit code = " + rc); 38.35 38.36 if (out.matches("(?s).*p/[^ ]+\\.class.*")) 38.37 throw new Error("reading .class files");
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/test/tools/javadoc/parser/7091528/p/C3.java Wed Apr 30 23:59:45 2014 -0700 39.3 @@ -0,0 +1,27 @@ 39.4 +/* 39.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 39.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 39.7 + * 39.8 + * This code is free software; you can redistribute it and/or modify it 39.9 + * under the terms of the GNU General Public License version 2 only, as 39.10 + * published by the Free Software Foundation. 39.11 + * 39.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 39.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 39.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 39.15 + * version 2 for more details (a copy is included in the LICENSE file that 39.16 + * accompanied this code). 39.17 + * 39.18 + * You should have received a copy of the GNU General Public License version 39.19 + * 2 along with this work; if not, write to the Free Software Foundation, 39.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 39.21 + * 39.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 39.23 + * or visit www.oracle.com if you need additional information or have any 39.24 + * questions. 39.25 + */ 39.26 + 39.27 + 39.28 +/** This is class C3, and no package for me please */ 39.29 +public class C3 {} 39.30 +