# HG changeset patch # User lana # Date 1298599510 28800 # Node ID e3d011d59a33acef79eff7523bef069557e91002 # Parent 80bbd1da4a72b96e5a9a9edc011116575515b05c# Parent de5524670f8010141f3f1a0ba39cb71d64864422 Merge diff -r 80bbd1da4a72 -r e3d011d59a33 make/build.xml --- a/make/build.xml Thu Feb 24 15:16:13 2011 -0800 +++ b/make/build.xml Thu Feb 24 18:05:10 2011 -0800 @@ -868,8 +868,10 @@ executable="${boot.java.home}/bin/javac" srcdir="${make.tools.dir}/GenStubs" destdir="${build.toolclasses.dir}/" - classpath="${build.bootstrap.dir}/classes:${ant.core.lib}" - includeantruntime="false"/> + classpath="${ant.core.lib}" + includeantruntime="false"> + + diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/bin/launcher.sh-template --- a/src/share/bin/launcher.sh-template Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/bin/launcher.sh-template Thu Feb 24 18:05:10 2011 -0800 @@ -31,8 +31,7 @@ mydir=`cygpath -m $mydir` ;; esac - -mylib="`dirname $mydir`"/lib +mylib="$mydir/../lib" # By default, put the jar file and its dependencies on the bootclasspath. # This is always required on a Mac, because the system langtools classes @@ -73,4 +72,4 @@ unset DUALCASE IFS=$nl -"#TARGET_JAVA#" "${bcp:+-Xbootclasspath/p:"$bcp"}" ${ea} ${javaOpts} -jar "${mydir}"/../lib/#PROGRAM#.jar ${toolOpts} +"#TARGET_JAVA#" "${bcp:+-Xbootclasspath/p:"$bcp"}" ${ea} ${javaOpts} -jar "${mylib}/#PROGRAM#.jar" ${toolOpts} diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/classes/com/sun/tools/javac/code/Scope.java --- a/src/share/classes/com/sun/tools/javac/code/Scope.java Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/code/Scope.java Thu Feb 24 18:05:10 2011 -0800 @@ -74,7 +74,7 @@ /** A list of scopes to be notified if items are to be removed from this scope. */ - List listeners = List.nil(); + List listeners = List.nil(); /** Use as a "not-found" result for lookup. * Also used to mark deleted entries in the table. @@ -219,12 +219,27 @@ Entry e = makeEntry(sym, old, elems, s, origin); table[hash] = e; elems = e; + + //notify listeners + for (List l = listeners; l.nonEmpty(); l = l.tail) { + l.head.symbolAdded(sym, this); + } } Entry makeEntry(Symbol sym, Entry shadowed, Entry sibling, Scope scope, Scope origin) { return new Entry(sym, shadowed, sibling, scope); } + + public interface ScopeListener { + public void symbolAdded(Symbol sym, Scope s); + public void symbolRemoved(Symbol sym, Scope s); + } + + public void addScopeListener(ScopeListener sl) { + listeners = listeners.prepend(sl); + } + /** Remove symbol from this scope. Used when an inner class * attribute tells us that the class isn't a package member. */ @@ -258,9 +273,9 @@ te = te.sibling; } - // remove items from scopes that have done importAll - for (List l = listeners; l.nonEmpty(); l = l.tail) { - l.head.remove(sym); + //notify listeners + for (List l = listeners; l.nonEmpty(); l = l.tail) { + l.head.symbolRemoved(sym, this); } } @@ -393,7 +408,32 @@ }; } }; + } + public Iterable getElementsByName(Name name) { + return getElementsByName(name, noFilter); + } + + public Iterable getElementsByName(final Name name, final Filter sf) { + return new Iterable() { + public Iterator iterator() { + return new Iterator() { + Scope.Entry currentEntry = lookup(name, sf); + + public boolean hasNext() { + return currentEntry.scope != null; + } + public Symbol next() { + Scope.Entry prevEntry = currentEntry; + currentEntry = currentEntry.next(sf); + return prevEntry.sym; + } + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + }; } public String toString() { @@ -488,7 +528,7 @@ } } - public static class StarImportScope extends ImportScope { + public static class StarImportScope extends ImportScope implements ScopeListener { public StarImportScope(Symbol owner) { super(owner); @@ -500,8 +540,13 @@ enter(e.sym, fromScope); } // Register to be notified when imported items are removed - fromScope.listeners = fromScope.listeners.prepend(this); + fromScope.addScopeListener(this); } + + public void symbolRemoved(Symbol sym, Scope s) { + remove(sym); + } + public void symbolAdded(Symbol sym, Scope s) { } } /** An empty scope, into which you can't place anything. Used for @@ -538,6 +583,151 @@ } } + /** A class scope adds capabilities to keep track of changes in related + * class scopes - this allows client to realize whether a class scope + * has changed, either directly (because a new member has been added/removed + * to this scope) or indirectly (i.e. because a new member has been + * added/removed into a supertype scope) + */ + public static class CompoundScope extends Scope implements ScopeListener { + + public static final Entry[] emptyTable = new Entry[0]; + + private List subScopes = List.nil(); + private int mark = 0; + + public CompoundScope(Symbol owner) { + super(null, owner, emptyTable); + } + + public void addSubScope(Scope that) { + if (that != null) { + subScopes = subScopes.prepend(that); + that.addScopeListener(this); + mark++; + for (ScopeListener sl : listeners) { + sl.symbolAdded(null, this); //propagate upwards in case of nested CompoundScopes + } + } + } + + public void symbolAdded(Symbol sym, Scope s) { + mark++; + for (ScopeListener sl : listeners) { + sl.symbolAdded(sym, s); + } + } + + public void symbolRemoved(Symbol sym, Scope s) { + mark++; + for (ScopeListener sl : listeners) { + sl.symbolRemoved(sym, s); + } + } + + public int getMark() { + return mark; + } + + @Override + public String toString() { + StringBuilder buf = new StringBuilder(); + buf.append("CompoundScope{"); + String sep = ""; + for (Scope s : subScopes) { + buf.append(sep); + buf.append(s); + sep = ","; + } + buf.append("}"); + return buf.toString(); + } + + @Override + public Iterable getElements(final Filter sf) { + return new Iterable() { + public Iterator iterator() { + return new CompoundScopeIterator(subScopes) { + Iterator nextIterator(Scope s) { + return s.getElements().iterator(); + } + }; + } + }; + } + + @Override + public Iterable getElementsByName(final Name name, final Filter sf) { + return new Iterable() { + public Iterator iterator() { + return new CompoundScopeIterator(subScopes) { + Iterator nextIterator(Scope s) { + return s.getElementsByName(name, sf).iterator(); + } + }; + } + }; + } + + abstract class CompoundScopeIterator implements Iterator { + + private Iterator currentIterator; + private List scopesToScan; + + public CompoundScopeIterator(List scopesToScan) { + this.scopesToScan = scopesToScan; + update(); + } + + abstract Iterator nextIterator(Scope s); + + public boolean hasNext() { + return currentIterator != null; + } + + public Symbol next() { + Symbol sym = currentIterator.next(); + if (!currentIterator.hasNext()) { + update(); + } + return sym; + } + + public void remove() { + throw new UnsupportedOperationException(); + } + + private void update() { + while (scopesToScan.nonEmpty()) { + currentIterator = nextIterator(scopesToScan.head); + scopesToScan = scopesToScan.tail; + if (currentIterator.hasNext()) return; + } + currentIterator = null; + } + } + + @Override + public Entry lookup(Name name, Filter sf) { + throw new UnsupportedOperationException(); + } + + @Override + public Scope dup(Symbol newOwner) { + throw new UnsupportedOperationException(); + } + + @Override + public void enter(Symbol sym, Scope s, Scope origin) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(Symbol sym) { + throw new UnsupportedOperationException(); + } + } + /** An error scope, for which the owner should be an error symbol. */ public static class ErrorScope extends Scope { ErrorScope(Scope next, Symbol errSymbol, Entry[] table) { diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/classes/com/sun/tools/javac/code/Symbol.java --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Thu Feb 24 18:05:10 2011 -0800 @@ -731,7 +731,7 @@ /** members closure cache (set by Types.membersClosure) */ - Scope membersClosure; + Scope.CompoundScope membersClosure; public ClassSymbol(long flags, Name name, Type type, Symbol owner) { super(flags, name, type, owner); diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/classes/com/sun/tools/javac/code/Type.java --- a/src/share/classes/com/sun/tools/javac/code/Type.java Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Thu Feb 24 18:05:10 2011 -0800 @@ -270,10 +270,6 @@ public Type getUpperBound() { return null; } public Type getLowerBound() { return null; } - public void setThrown(List ts) { - throw new AssertionError(); - } - /** Navigation methods, these will work for classes, type variables, * foralls, but will return null for arrays and methods. */ @@ -388,14 +384,6 @@ */ public void complete() {} - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - throw new AssertionError(e); - } - } - public TypeSymbol asElement() { return tsym; } @@ -817,8 +805,7 @@ } } - public static class MethodType extends Type - implements Cloneable, ExecutableType { + public static class MethodType extends Type implements ExecutableType { public List argtypes; public Type restype; @@ -880,10 +867,6 @@ public Type getReturnType() { return restype; } public List getThrownTypes() { return thrown; } - public void setThrown(List t) { - thrown = t; - } - public boolean isErroneous() { return isErroneous(argtypes) || @@ -1068,12 +1051,10 @@ public List getThrownTypes() { return qtype.getThrownTypes(); } public List allparams() { return qtype.allparams(); } public Type getUpperBound() { return qtype.getUpperBound(); } - public Object clone() { DelegatedType t = (DelegatedType)super.clone(); t.qtype = (Type)qtype.clone(); return t; } public boolean isErroneous() { return qtype.isErroneous(); } } - public static class ForAll extends DelegatedType - implements Cloneable, ExecutableType { + public static class ForAll extends DelegatedType implements ExecutableType { public List tvars; public ForAll(List tvars, Type qtype) { @@ -1092,16 +1073,6 @@ public List getTypeArguments() { return tvars; } - public void setThrown(List t) { - qtype.setThrown(t); - } - - public Object clone() { - ForAll result = (ForAll)super.clone(); - result.qtype = (Type)result.qtype.clone(); - return result; - } - public boolean isErroneous() { return qtype.isErroneous(); } diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/classes/com/sun/tools/javac/code/Types.java --- a/src/share/classes/com/sun/tools/javac/code/Types.java Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Thu Feb 24 18:05:10 2011 -0800 @@ -2023,18 +2023,22 @@ final MethodSymbol cachedImpl; final Filter implFilter; final boolean checkResult; + final int prevMark; public Entry(MethodSymbol cachedImpl, Filter scopeFilter, - boolean checkResult) { + boolean checkResult, + int prevMark) { this.cachedImpl = cachedImpl; this.implFilter = scopeFilter; this.checkResult = checkResult; + this.prevMark = prevMark; } - boolean matches(Filter scopeFilter, boolean checkResult) { + boolean matches(Filter scopeFilter, boolean checkResult, int mark) { return this.implFilter == scopeFilter && - this.checkResult == checkResult; + this.checkResult == checkResult && + this.prevMark == mark; } } @@ -2046,10 +2050,11 @@ _map.put(ms, new SoftReference>(cache)); } Entry e = cache.get(origin); + CompoundScope members = membersClosure(origin.type); if (e == null || - !e.matches(implFilter, checkResult)) { - MethodSymbol impl = implementationInternal(ms, origin, Types.this, checkResult, implFilter); - cache.put(origin, new Entry(impl, implFilter, checkResult)); + !e.matches(implFilter, checkResult, members.getMark())) { + MethodSymbol impl = implementationInternal(ms, origin, checkResult, implFilter); + cache.put(origin, new Entry(impl, implFilter, checkResult, members.getMark())); return impl; } else { @@ -2057,8 +2062,8 @@ } } - private MethodSymbol implementationInternal(MethodSymbol ms, TypeSymbol origin, Types types, boolean checkResult, Filter implFilter) { - for (Type t = origin.type; t.tag == CLASS || t.tag == TYPEVAR; t = types.supertype(t)) { + private MethodSymbol implementationInternal(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter implFilter) { + for (Type t = origin.type; t.tag == CLASS || t.tag == TYPEVAR; t = supertype(t)) { while (t.tag == TYPEVAR) t = t.getUpperBound(); TypeSymbol c = t.tsym; @@ -2066,7 +2071,7 @@ e.scope != null; e = e.next(implFilter)) { if (e.sym != null && - e.sym.overrides(ms, origin, types, checkResult)) + e.sym.overrides(ms, origin, Types.this, checkResult)) return (MethodSymbol)e.sym; } } @@ -2082,46 +2087,35 @@ // // - public Scope membersClosure(Type site) { + public CompoundScope membersClosure(Type site) { return membersClosure.visit(site); } - UnaryVisitor membersClosure = new UnaryVisitor() { - - public Scope visitType(Type t, Void s) { + UnaryVisitor membersClosure = new UnaryVisitor() { + + public CompoundScope visitType(Type t, Void s) { return null; } @Override - public Scope visitClassType(ClassType t, Void s) { + public CompoundScope visitClassType(ClassType t, Void s) { ClassSymbol csym = (ClassSymbol)t.tsym; if (csym.membersClosure == null) { - Scope membersClosure = new Scope(csym); + CompoundScope membersClosure = new CompoundScope(csym); for (Type i : interfaces(t)) { - enterAll(visit(i), membersClosure); + membersClosure.addSubScope(visit(i)); } - enterAll(visit(supertype(t)), membersClosure); - enterAll(csym.members(), membersClosure); + membersClosure.addSubScope(visit(supertype(t))); + membersClosure.addSubScope(csym.members()); csym.membersClosure = membersClosure; } return csym.membersClosure; } @Override - public Scope visitTypeVar(TypeVar t, Void s) { + public CompoundScope visitTypeVar(TypeVar t, Void s) { return visit(t.getUpperBound()); } - - public void enterAll(Scope s, Scope to) { - if (s == null) return; - List syms = List.nil(); - for (Scope.Entry e = s.elems ; e != null ; e = e.sibling) { - syms = syms.prepend(e.sym); - } - for (Symbol sym : syms) { - to.enter(sym); - } - } }; // @@ -2413,6 +2407,38 @@ }; // + public Type createMethodTypeWithParameters(Type original, List newParams) { + return original.accept(methodWithParameters, newParams); + } + // where + private final MapVisitor> methodWithParameters = new MapVisitor>() { + public Type visitType(Type t, List newParams) { + throw new IllegalArgumentException("Not a method type: " + t); + } + public Type visitMethodType(MethodType t, List newParams) { + return new MethodType(newParams, t.restype, t.thrown, t.tsym); + } + public Type visitForAll(ForAll t, List newParams) { + return new ForAll(t.tvars, t.qtype.accept(this, newParams)); + } + }; + + public Type createMethodTypeWithThrown(Type original, List newThrown) { + return original.accept(methodWithThrown, newThrown); + } + // where + private final MapVisitor> methodWithThrown = new MapVisitor>() { + public Type visitType(Type t, List newThrown) { + throw new IllegalArgumentException("Not a method type: " + t); + } + public Type visitMethodType(MethodType t, List newThrown) { + return new MethodType(t.argtypes, t.restype, newThrown, t.tsym); + } + public Type visitForAll(ForAll t, List newThrown) { + return new ForAll(t.tvars, t.qtype.accept(this, newThrown)); + } + }; + // public Type createErrorType(Type originalType) { return new ErrorType(originalType, syms.errSymbol); diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Feb 24 18:05:10 2011 -0800 @@ -1584,6 +1584,11 @@ if (!TreeInfo.isDiamond(tree)) { clazztype = chk.checkClassType( tree.clazz.pos(), clazztype, true); + } else if (!clazztype.isErroneous() && + !clazztype.tsym.type.isParameterized()) { + log.error(tree.clazz.pos(), + "cant.apply.diamond.1", + clazztype, diags.fragment("diamond.non.generic", clazztype)); } chk.validate(clazz, localEnv); if (tree.encl != null) { @@ -1609,7 +1614,7 @@ List argtypes = attribArgs(tree.args, localEnv); List typeargtypes = attribTypes(tree.typeargs, localEnv); - if (TreeInfo.isDiamond(tree)) { + if (TreeInfo.isDiamond(tree) && clazztype.tsym.type.isParameterized()) { clazztype = attribDiamond(localEnv, tree, clazztype, mapping, argtypes, typeargtypes); clazz.type = clazztype; } else if (allowDiamondFinder && diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/classes/com/sun/tools/javac/comp/Check.java --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Feb 24 18:05:10 2011 -0800 @@ -2106,32 +2106,32 @@ void checkOverrideClashes(DiagnosticPosition pos, Type site, MethodSymbol sym) { ClashFilter cf = new ClashFilter(site); //for each method m1 that is a member of 'site'... - for (Scope.Entry e1 = types.membersClosure(site).lookup(sym.name, cf) ; - e1.scope != null ; e1 = e1.next(cf)) { + for (Symbol s1 : types.membersClosure(site).getElementsByName(sym.name, cf)) { //...find another method m2 that is overridden (directly or indirectly) //by method 'sym' in 'site' - for (Scope.Entry e2 = types.membersClosure(site).lookup(sym.name, cf) ; - e2.scope != null ; e2 = e2.next(cf)) { - if (e1.sym == e2.sym || !sym.overrides(e2.sym, site.tsym, types, false)) continue; + for (Symbol s2 : types.membersClosure(site).getElementsByName(sym.name, cf)) { + if (s1 == s2 || !sym.overrides(s2, site.tsym, types, false)) continue; //if (i) the signature of 'sym' is not a subsignature of m1 (seen as //a member of 'site') and (ii) m1 has the same erasure as m2, issue an error - if (!types.isSubSignature(sym.type, types.memberType(site, e1.sym)) && - types.hasSameArgs(e1.sym.erasure(types), e2.sym.erasure(types))) { + if (!types.isSubSignature(sym.type, types.memberType(site, s1)) && + types.hasSameArgs(s1.erasure(types), s2.erasure(types))) { sym.flags_field |= CLASH; - String key = e2.sym == sym ? + String key = s2 == sym ? "name.clash.same.erasure.no.override" : "name.clash.same.erasure.no.override.1"; log.error(pos, key, sym, sym.location(), - e1.sym, e1.sym.location(), - e2.sym, e2.sym.location()); + s1, s1.location(), + s2, s2.location()); return; } } } } + + /** Check that all static methods accessible from 'site' are * mutually compatible (JLS 8.4.8). * @@ -2142,16 +2142,15 @@ void checkHideClashes(DiagnosticPosition pos, Type site, MethodSymbol sym) { ClashFilter cf = new ClashFilter(site); //for each method m1 that is a member of 'site'... - for (Scope.Entry e = types.membersClosure(site).lookup(sym.name, cf) ; - e.scope != null ; e = e.next(cf)) { + for (Symbol s : types.membersClosure(site).getElementsByName(sym.name, cf)) { //if (i) the signature of 'sym' is not a subsignature of m1 (seen as //a member of 'site') and (ii) 'sym' has the same erasure as m1, issue an error - if (!types.isSubSignature(sym.type, types.memberType(site, e.sym)) && - types.hasSameArgs(e.sym.erasure(types), sym.erasure(types))) { + if (!types.isSubSignature(sym.type, types.memberType(site, s)) && + types.hasSameArgs(s.erasure(types), sym.erasure(types))) { log.error(pos, "name.clash.same.erasure.no.hide", sym, sym.location(), - e.sym, e.sym.location()); + s, s.location()); return; } } diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/classes/com/sun/tools/javac/comp/Flow.java --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java Thu Feb 24 18:05:10 2011 -0800 @@ -314,13 +314,22 @@ for (PendingExit exit = pendingExits.next(); exit != null; exit = pendingExits.next()) { - boolean synthetic = classDef != null && - classDef.pos == exit.tree.pos; - log.error(exit.tree.pos(), - synthetic - ? "unreported.exception.default.constructor" - : "unreported.exception.need.to.catch.or.throw", - exit.thrown); + if (classDef != null && + classDef.pos == exit.tree.pos) { + log.error(exit.tree.pos(), + "unreported.exception.default.constructor", + exit.thrown); + } else if (exit.tree.getTag() == JCTree.VARDEF && + ((JCVariableDecl)exit.tree).sym.isResourceVariable()) { + log.error(exit.tree.pos(), + "unreported.exception.implicit.close", + exit.thrown, + ((JCVariableDecl)exit.tree).sym.name); + } else { + log.error(exit.tree.pos(), + "unreported.exception.need.to.catch.or.throw", + exit.thrown); + } } } @@ -664,12 +673,15 @@ // in an anonymous class, add the set of thrown exceptions to // the throws clause of the synthetic constructor and propagate // outwards. + // Changing the throws clause on the fly is okay here because + // the anonymous constructor can't be invoked anywhere else, + // and its type hasn't been cached. if (tree.name == names.empty) { for (List l = tree.defs; l.nonEmpty(); l = l.tail) { if (TreeInfo.isInitialConstructor(l.head)) { JCMethodDecl mdef = (JCMethodDecl)l.head; mdef.thrown = make.Types(thrown); - mdef.sym.type.setThrown(thrown); + mdef.sym.type = types.createMethodTypeWithThrown(mdef.sym.type, thrown); } } thrownPrev = chk.union(thrown, thrownPrev); @@ -1021,7 +1033,7 @@ List.nil()); if (closeMethod.kind == MTH) { for (Type t : ((MethodSymbol)closeMethod).getThrownTypes()) { - markThrown(tree.body, t); + markThrown(resource, t); } } } diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/classes/com/sun/tools/javac/comp/Lower.java --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Feb 24 18:05:10 2011 -0800 @@ -1425,25 +1425,55 @@ } } - /** Optionally replace a try statement with an automatic resource - * management (ARM) block. + /** + * Optionally replace a try statement with the desugaring of a + * try-with-resources statement. The canonical desugaring of + * + * try ResourceSpecification + * Block + * + * is + * + * { + * final VariableModifiers_minus_final R #resource = Expression; + * Throwable #primaryException = null; + * + * try ResourceSpecificationtail + * Block + * catch (Throwable #t) { + * #primaryException = t; + * throw #t; + * } finally { + * if (#resource != null) { + * if (#primaryException != null) { + * try { + * #resource.close(); + * } catch(Throwable #suppressedException) { + * #primaryException.addSuppressed(#suppressedException); + * } + * } else { + * #resource.close(); + * } + * } + * } + * * @param tree The try statement to inspect. - * @return An ARM block, or the original try block if there are no - * resources to manage. + * @return A a desugared try-with-resources tree, or the original + * try block if there are no resources to manage. */ - JCTree makeArmTry(JCTry tree) { + JCTree makeTwrTry(JCTry tree) { make_at(tree.pos()); twrVars = twrVars.dup(); - JCBlock armBlock = makeArmBlock(tree.resources, tree.body, 0); + JCBlock twrBlock = makeTwrBlock(tree.resources, tree.body, 0); if (tree.catchers.isEmpty() && tree.finalizer == null) - result = translate(armBlock); + result = translate(twrBlock); else - result = translate(make.Try(armBlock, tree.catchers, tree.finalizer)); + result = translate(make.Try(twrBlock, tree.catchers, tree.finalizer)); twrVars = twrVars.leave(); return result; } - private JCBlock makeArmBlock(List resources, JCBlock block, int depth) { + private JCBlock makeTwrBlock(List resources, JCBlock block, int depth) { if (resources.isEmpty()) return block; @@ -1497,16 +1527,16 @@ int oldPos = make.pos; make.at(TreeInfo.endPos(block)); - JCBlock finallyClause = makeArmFinallyClause(primaryException, expr); + JCBlock finallyClause = makeTwrFinallyClause(primaryException, expr); make.at(oldPos); - JCTry outerTry = make.Try(makeArmBlock(resources.tail, block, depth + 1), + JCTry outerTry = make.Try(makeTwrBlock(resources.tail, block, depth + 1), List.of(catchClause), finallyClause); stats.add(outerTry); return make.Block(0L, stats.toList()); } - private JCBlock makeArmFinallyClause(Symbol primaryException, JCExpression resource) { + private JCBlock makeTwrFinallyClause(Symbol primaryException, JCExpression resource) { // primaryException.addSuppressed(catchException); VarSymbol catchException = new VarSymbol(0, make.paramName(2), @@ -1525,22 +1555,30 @@ List catchClauses = List.of(make.Catch(catchExceptionDecl, catchBlock)); JCTry tryTree = make.Try(tryBlock, catchClauses, null); - // if (resource != null) resourceClose; - JCExpression nullCheck = makeBinary(JCTree.NE, - make.Ident(primaryException), - makeNull()); - JCIf closeIfStatement = make.If(nullCheck, + // if (primaryException != null) {try...} else resourceClose; + JCIf closeIfStatement = make.If(makeNonNullCheck(make.Ident(primaryException)), tryTree, makeResourceCloseInvocation(resource)); - return make.Block(0L, List.of(closeIfStatement)); + + // if (#resource != null) { if (primaryException ... } + return make.Block(0L, + List.of(make.If(makeNonNullCheck(resource), + closeIfStatement, + null))); } private JCStatement makeResourceCloseInvocation(JCExpression resource) { // create resource.close() method invocation - JCExpression resourceClose = makeCall(resource, names.close, List.nil()); + JCExpression resourceClose = makeCall(resource, + names.close, + List.nil()); return make.Exec(resourceClose); } + private JCExpression makeNonNullCheck(JCExpression expression) { + return makeBinary(JCTree.NE, expression, makeNull()); + } + /** Construct a tree that represents the outer instance * . Never pick the current `this'. * @param pos The source code position to be used for the tree. @@ -3573,7 +3611,7 @@ if (tree.resources.isEmpty()) { super.visitTry(tree); } else { - result = makeArmTry(tree); + result = makeTwrTry(tree); } } diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/classes/com/sun/tools/javac/comp/Resolve.java --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Feb 24 18:05:10 2011 -0800 @@ -776,10 +776,12 @@ // due to error recovery or mixing incompatible class files return ambiguityError(m1, m2); } + List allThrown = chk.intersect(mt1.getThrownTypes(), mt2.getThrownTypes()); + Type newSig = types.createMethodTypeWithThrown(mostSpecific.type, allThrown); MethodSymbol result = new MethodSymbol( mostSpecific.flags(), mostSpecific.name, - null, + newSig, mostSpecific.owner) { @Override public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) { @@ -789,9 +791,6 @@ return super.implementation(origin, types, checkResult); } }; - result.type = (Type)mostSpecific.type.clone(); - result.type.setThrown(chk.intersect(mt1.getThrownTypes(), - mt2.getThrownTypes())); return result; } if (m1SignatureMoreSpecific) return m1; @@ -852,13 +851,8 @@ } //append varargs element type as last synthetic formal args.append(types.elemtype(varargsTypeTo)); - MethodSymbol msym = new MethodSymbol(to.flags_field, - to.name, - (Type)to.type.clone(), //see: 6990136 - to.owner); - MethodType mtype = msym.type.asMethodType(); - mtype.argtypes = args.toList(); - return msym; + Type mtype = types.createMethodTypeWithParameters(to.type, args.toList()); + return new MethodSymbol(to.flags_field, to.name, mtype, to.owner); } else { return to; } diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/classes/com/sun/tools/javac/file/CacheFSInfo.java --- a/src/share/classes/com/sun/tools/javac/file/CacheFSInfo.java Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/file/CacheFSInfo.java Thu Feb 24 18:05:10 2011 -0800 @@ -49,16 +49,13 @@ public static void preRegister(final Context context) { context.put(FSInfo.class, new Context.Factory() { public FSInfo make() { - if (singleton == null) - singleton = new CacheFSInfo(); - context.put(FSInfo.class, singleton); - return singleton; + FSInfo instance = new CacheFSInfo(); + context.put(FSInfo.class, instance); + return instance; } }); } - static CacheFSInfo singleton; - public void clearCache() { cache.clear(); } diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/classes/com/sun/tools/javac/file/JavacFileManager.java --- a/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Thu Feb 24 18:05:10 2011 -0800 @@ -164,9 +164,7 @@ fsInfo = FSInfo.instance(context); - // retain check for system property for compatibility - useZipFileIndex = options.isUnset("useJavaUtilZip") - && System.getProperty("useJavaUtilZip") == null; + useZipFileIndex = options.isSet("useOptimizedZip"); if (useZipFileIndex) zipFileIndexCache = ZipFileIndexCache.getSharedInstance(); @@ -499,8 +497,7 @@ if (!useZipFileIndex) { zdir = new ZipFile(zipFileName); - } - else { + } else { usePreindexedCache = options.isSet("usezipindex"); preindexCacheLocation = options.get("java.io.tmpdir"); String optCacheLoc = options.get("cachezipindexdir"); diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/classes/com/sun/tools/javac/file/Paths.java --- a/src/share/classes/com/sun/tools/javac/file/Paths.java Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/file/Paths.java Thu Feb 24 18:05:10 2011 -0800 @@ -247,10 +247,16 @@ public Path() { super(); } public Path addDirectories(String dirs, boolean warn) { - if (dirs != null) - for (File dir : getPathEntries(dirs)) - addDirectory(dir, warn); - return this; + boolean prev = expandJarClassPaths; + expandJarClassPaths = true; + try { + if (dirs != null) + for (File dir : getPathEntries(dirs)) + addDirectory(dir, warn); + return this; + } finally { + expandJarClassPaths = prev; + } } public Path addDirectories(String dirs) { diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/classes/com/sun/tools/javac/parser/Scanner.java --- a/src/share/classes/com/sun/tools/javac/parser/Scanner.java Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/parser/Scanner.java Thu Feb 24 18:05:10 2011 -0800 @@ -282,12 +282,6 @@ sbuf[sp++] = ch; } - /** For debugging purposes: print character. - */ - private void dch() { - System.err.print(ch); System.out.flush(); - } - /** Read next character in character or string literal and copy into sbuf. */ private void scanLitChar() { diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Feb 24 18:05:10 2011 -0800 @@ -55,6 +55,7 @@ import com.sun.tools.javac.api.JavacTrees; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Symbol.*; +import com.sun.tools.javac.file.FSInfo; import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.jvm.*; import com.sun.tools.javac.main.JavaCompiler; @@ -1069,6 +1070,10 @@ if (tl != null) next.put(TaskListener.class, tl); + FSInfo fsInfo = context.get(FSInfo.class); + if (fsInfo != null) + next.put(FSInfo.class, fsInfo); + JavaFileManager jfm = context.get(JavaFileManager.class); Assert.checkNonNull(jfm); next.put(JavaFileManager.class, jfm); diff -r 80bbd1da4a72 -r e3d011d59a33 src/share/classes/com/sun/tools/javac/resources/compiler.properties --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Feb 24 15:16:13 2011 -0800 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Feb 24 18:05:10 2011 -0800 @@ -800,6 +800,11 @@ compiler.err.unreported.exception.default.constructor=\ unreported exception {0} in default constructor +# 0: type, 1: name +compiler.err.unreported.exception.implicit.close=\ + unreported exception {0}; must be caught or declared to be thrown\n\ + exception thrown from implicit call to close() on resource variable ''{1}'' + compiler.err.unsupported.cross.fp.lit=\ hexadecimal floating-point literals are not supported on this VM @@ -1579,6 +1584,10 @@ compiler.misc.diamond=\ {0}<> +# 0: type +compiler.misc.diamond.non.generic=\ + cannot use ''<>'' with non-generic class {0} + # 0: list of type, 1: message segment compiler.misc.diamond.invalid.arg=\ type argument {0} inferred for {1} is not allowed in this context diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/4241573/T4241573.java --- a/test/tools/javac/4241573/T4241573.java Thu Feb 24 15:16:13 2011 -0800 +++ b/test/tools/javac/4241573/T4241573.java Thu Feb 24 18:05:10 2011 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -123,7 +123,7 @@ if (!dir.mkdirs()) throw new Exception("cannot create directories " + dir); for (String e: entries) { - writeFile(new File(dir, getPathForEntry(e)), getBodyForEntry(e)); + writeFile(new File(dir, getPathForDirEntry(e)), getBodyForEntry(e)); } return dir; } @@ -134,7 +134,7 @@ try { JarOutputStream jos = new JarOutputStream(out); for (String e: entries) { - jos.putNextEntry(new JarEntry(getPathForEntry(e))); + jos.putNextEntry(new JarEntry(getPathForZipEntry(e))); jos.write(getBodyForEntry(e).getBytes()); } jos.close(); @@ -144,11 +144,16 @@ return jar; } - /** Return the path for an entry given to createDir or createJar. */ - String getPathForEntry(String e) { + /** Return the path for an entry given to createDir */ + String getPathForDirEntry(String e) { return e.replace(".", File.separator) + ".java"; } + /** Return the path for an entry given to createJar. */ + String getPathForZipEntry(String e) { + return e.replace(".", "/") + ".java"; + } + /** Return the body text for an entry given to createDir or createJar. */ String getBodyForEntry(String e) { int sep = e.lastIndexOf("."); diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/4917091/Test255.java --- a/test/tools/javac/4917091/Test255.java Thu Feb 24 15:16:13 2011 -0800 +++ b/test/tools/javac/4917091/Test255.java Thu Feb 24 18:05:10 2011 -0800 @@ -1,5 +1,5 @@ /* - * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -16,9 +16,9 @@ * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. */ /* diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/4917091/Test256a.java --- a/test/tools/javac/4917091/Test256a.java Thu Feb 24 15:16:13 2011 -0800 +++ b/test/tools/javac/4917091/Test256a.java Thu Feb 24 18:05:10 2011 -0800 @@ -1,5 +1,5 @@ /* - * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -16,9 +16,9 @@ * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. */ /* diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/4917091/Test256b.java --- a/test/tools/javac/4917091/Test256b.java Thu Feb 24 15:16:13 2011 -0800 +++ b/test/tools/javac/4917091/Test256b.java Thu Feb 24 18:05:10 2011 -0800 @@ -1,5 +1,5 @@ /* - * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -16,9 +16,9 @@ * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. */ /* diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/6508981/TestInferBinaryName.java --- a/test/tools/javac/6508981/TestInferBinaryName.java Thu Feb 24 15:16:13 2011 -0800 +++ b/test/tools/javac/6508981/TestInferBinaryName.java Thu Feb 24 18:05:10 2011 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2011 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -138,12 +138,11 @@ boolean zipFileIndexKind) throws IOException { Context ctx = new Context(); + Options options = Options.instance(ctx); // uugh, ugly back door, should be cleaned up, someday if (zipFileIndexKind == USE_ZIP_FILE_INDEX) - System.clearProperty("useJavaUtilZip"); - else - System.setProperty("useJavaUtilZip", "true"); - Options options = Options.instance(ctx); + options.put("useOptimizedZip", "true"); + if (symFileKind == IGNORE_SYMBOL_FILE) options.put("ignore.symbol.file", "true"); JavacFileManager fm = new JavacFileManager(ctx, false, null); diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/Paths/Class-Path.sh --- a/test/tools/javac/Paths/Class-Path.sh Thu Feb 24 15:16:13 2011 -0800 +++ b/test/tools/javac/Paths/Class-Path.sh Thu Feb 24 18:05:10 2011 -0800 @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -24,7 +24,7 @@ # -# @test @(#)Class-Path.sh 1.3 03/10/31 +# @test # @bug 4212732 # @summary Test handling of the Class-Path attribute in jar file manifests # @author Martin Buchholz @@ -184,8 +184,8 @@ # Success "$jar" cfe "Hello.jar" "Hello" Bye.class -# Jar creation and update when there is no manifest and inputfiles -specified +# Jar creation and update when there is no manifest and inputfiles +# specified Failure "$jar" cvf "A.jar" Failure "$jar" uvf "A.jar" diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/Paths/Class-Path2.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/Paths/Class-Path2.sh Thu Feb 24 18:05:10 2011 -0800 @@ -0,0 +1,111 @@ +#!/bin/sh +# +# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +# @test +# @bug 4212732 6485027 +# @summary Test handling of the Class-Path attribute in jar file manifests +# @author Martin Buchholz +# +# @run shell Class-Path2.sh + +# To run this test manually, simply do ./Class-Path2.sh + +. ${TESTSRC-.}/Util.sh + +set -u + +Cleanup() { + Sys rm -rf pkg Main.java Main.class Main.jar jars + Sys rm -rf MANIFEST.MF A.jar B.zip +} + +Cleanup +Sys mkdir pkg + +#---------------------------------------------------------------- +# Create mutually referential jar files +#---------------------------------------------------------------- +cat >pkg/A.java <pkg/B.java <Main.java <not added as a + * suppressed exception to an exception from try block. + */ + private static void testNoSuppression() { + try(AutoCloseable resource = null) { + throw new java.io.IOException(); + } catch(java.io.IOException ioe) { + Throwable[] suppressed = ioe.getSuppressed(); + if (suppressed.length != 0) { + throw new AssertionError("Non-empty suppressed exceptions", + ioe); + } + } catch (Exception e) { + throw new AssertionError("Should not be reached", e); + } + } +} diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/api/6411310/Test.java --- a/test/tools/javac/api/6411310/Test.java Thu Feb 24 15:16:13 2011 -0800 +++ b/test/tools/javac/api/6411310/Test.java Thu Feb 24 18:05:10 2011 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -59,12 +59,12 @@ test(createFileManager(), createDir("dir", entries), "p", entries); test(createFileManager(), createDir("a b/dir", entries), "p", entries); - for (boolean useJavaUtilZip: new boolean[] { false, true }) { - test(createFileManager(useJavaUtilZip), createJar("jar", entries), "p", entries); - test(createFileManager(useJavaUtilZip), createJar("jar jar", entries), "p", entries); + for (boolean useOptimizedZip: new boolean[] { false, true }) { + test(createFileManager(useOptimizedZip), createJar("jar", entries), "p", entries); + test(createFileManager(useOptimizedZip), createJar("jar jar", entries), "p", entries); for (boolean useSymbolFile: new boolean[] { false, true }) { - test(createFileManager(useJavaUtilZip, useSymbolFile), rt_jar, "java.lang.ref", null); + test(createFileManager(useOptimizedZip, useSymbolFile), rt_jar, "java.lang.ref", null); } } @@ -145,42 +145,22 @@ return createFileManager(false, false); } - JavacFileManager createFileManager(boolean useJavaUtilZip) { - return createFileManager(useJavaUtilZip, false); + JavacFileManager createFileManager(boolean useOptimizedZip) { + return createFileManager(useOptimizedZip, false); } - JavacFileManager createFileManager(boolean useJavaUtilZip, boolean useSymbolFile) { - // javac should really not be using system properties like this - // -- it should really be using (hidden) options -- but until then - // take care to leave system properties as we find them, so as not - // to adversely affect other tests that might follow. - String prev = System.getProperty("useJavaUtilZip"); - boolean resetProperties = false; - try { - if (useJavaUtilZip) { - System.setProperty("useJavaUtilZip", "true"); - resetProperties = true; - } else if (System.getProperty("useJavaUtilZip") != null) { - System.getProperties().remove("useJavaUtilZip"); - resetProperties = true; + JavacFileManager createFileManager(boolean useOptimizedZip, boolean useSymbolFile) { + Context c = new Context(); + Options options = Options.instance(c); + + if (useOptimizedZip) { + options.put("useOptimizedZip", "true"); } - Context c = new Context(); if (!useSymbolFile) { - Options options = Options.instance(c); options.put("ignore.symbol.file", "true"); } - return new JavacFileManager(c, false, null); - } finally { - if (resetProperties) { - if (prev == null) { - System.getProperties().remove("useJavaUtilZip"); - } else { - System.setProperty("useJavaUtilZip", prev); - } - } - } } File createDir(String name, String... entries) throws Exception { diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/api/T6838467.java --- a/test/tools/javac/api/T6838467.java Thu Feb 24 15:16:13 2011 -0800 +++ b/test/tools/javac/api/T6838467.java Thu Feb 24 18:05:10 2011 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,7 +32,9 @@ import java.util.zip.*; import javax.tools.*; import com.sun.tools.javac.file.JavacFileManager; +import com.sun.tools.javac.main.OptionName; import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.Options; public class T6838467 { boolean fileSystemIsCaseSignificant = !new File("a").equals(new File("A")); @@ -176,33 +178,13 @@ return fm; } - JavacFileManager createFileManager(boolean useJavaUtilZip) { - // javac should really not be using system properties like this - // -- it should really be using (hidden) options -- but until then - // take care to leave system properties as we find them, so as not - // to adversely affect other tests that might follow. - String prev = System.getProperty("useJavaUtilZip"); - boolean resetProperties = false; - try { - if (useJavaUtilZip) { - System.setProperty("useJavaUtilZip", "true"); - resetProperties = true; - } else if (System.getProperty("useJavaUtilZip") != null) { - System.getProperties().remove("useJavaUtilZip"); - resetProperties = true; - } - - Context c = new Context(); - return new JavacFileManager(c, false, null); - } finally { - if (resetProperties) { - if (prev == null) { - System.getProperties().remove("useJavaUtilZip"); - } else { - System.setProperty("useJavaUtilZip", prev); - } - } + JavacFileManager createFileManager(boolean useOptimedZipIndex) { + Context ctx = new Context(); + if (useOptimedZipIndex) { + Options options = Options.instance(ctx); + options.put("useOptimizedZip", "true"); } + return new JavacFileManager(ctx, false, null); } // create a directory containing a given set of paths diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/api/T6877206.java --- a/test/tools/javac/api/T6877206.java Thu Feb 24 15:16:13 2011 -0800 +++ b/test/tools/javac/api/T6877206.java Thu Feb 24 18:05:10 2011 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -63,12 +63,12 @@ test(createFileManager(), createDir("dir", entries), "p", entries.length); test(createFileManager(), createDir("a b/dir", entries), "p", entries.length); - for (boolean useJavaUtilZip: new boolean[] { false, true }) { - test(createFileManager(useJavaUtilZip), createJar("jar", entries), "p", entries.length); - test(createFileManager(useJavaUtilZip), createJar("jar jar", entries), "p", entries.length); + for (boolean useOptimizedZip: new boolean[] { false, true }) { + test(createFileManager(useOptimizedZip), createJar("jar", entries), "p", entries.length); + test(createFileManager(useOptimizedZip), createJar("jar jar", entries), "p", entries.length); for (boolean useSymbolFile: new boolean[] { false, true }) { - test(createFileManager(useJavaUtilZip, useSymbolFile), rt_jar, "java.lang.ref", -1); + test(createFileManager(useOptimizedZip, useSymbolFile), rt_jar, "java.lang.ref", -1); } } @@ -161,42 +161,20 @@ return createFileManager(false, false); } - JavacFileManager createFileManager(boolean useJavaUtilZip) { - return createFileManager(useJavaUtilZip, false); + JavacFileManager createFileManager(boolean useOptimizedZip) { + return createFileManager(useOptimizedZip, false); } - JavacFileManager createFileManager(boolean useJavaUtilZip, boolean useSymbolFile) { - // javac should really not be using system properties like this - // -- it should really be using (hidden) options -- but until then - // take care to leave system properties as we find them, so as not - // to adversely affect other tests that might follow. - String prev = System.getProperty("useJavaUtilZip"); - boolean resetProperties = false; - try { - if (useJavaUtilZip) { - System.setProperty("useJavaUtilZip", "true"); - resetProperties = true; - } else if (System.getProperty("useJavaUtilZip") != null) { - System.getProperties().remove("useJavaUtilZip"); - resetProperties = true; - } - - Context c = new Context(); - if (!useSymbolFile) { - Options options = Options.instance(c); - options.put("ignore.symbol.file", "true"); - } - - return new JavacFileManager(c, false, null); - } finally { - if (resetProperties) { - if (prev == null) { - System.getProperties().remove("useJavaUtilZip"); - } else { - System.setProperty("useJavaUtilZip", prev); - } - } + JavacFileManager createFileManager(boolean useOptimizedZip, boolean useSymbolFile) { + Context ctx = new Context(); + Options options = Options.instance(ctx); + if (useOptimizedZip) { + options.put("useOptimizedZip", "true"); } + if (!useSymbolFile) { + options.put("ignore.symbol.file", "true"); + } + return new JavacFileManager(ctx, false, null); } File createDir(String name, String... entries) throws Exception { diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/diags/examples/DiamondNonGeneric.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/examples/DiamondNonGeneric.java Thu Feb 24 18:05:10 2011 -0800 @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.misc.diamond.non.generic +// key: compiler.err.cant.apply.diamond.1 + +class DiamondNonGeneric { + String s = new String<>("foo"); +} diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/diags/examples/UnreportedExceptionImplicitClose.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/examples/UnreportedExceptionImplicitClose.java Thu Feb 24 18:05:10 2011 -0800 @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.err.unreported.exception.implicit.close + +class UnreportedExceptionImplicitClose { + static class MyCloseable implements AutoCloseable { + public void close() throws Exception { } + } + void test() { + try (MyCloseable x = new MyCloseable()) { } + } +} diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/file/T7018098.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/file/T7018098.java Thu Feb 24 18:05:10 2011 -0800 @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 7018098 + * @summary CacheFSInfo persists too long + * @library ../lib + * @build JavacTestingAbstractProcessor T7018098 + * @run main T7018098 + */ + +import java.io.*; +import java.util.*; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedOptions; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic; + +import com.sun.tools.javac.file.FSInfo; +import com.sun.tools.javac.processing.JavacProcessingEnvironment; +import com.sun.tools.javac.util.Context; + +@SupportedOptions("expect") +public class T7018098 extends JavacTestingAbstractProcessor { + public static void main(String... args) throws Exception { + new T7018098().run(); + } + + static File testDir = new File("T7018098.dir"); + + void run() throws Exception { + String myName = T7018098.class.getSimpleName(); + File testSrc = new File(System.getProperty("test.src")); + File file = new File(testSrc, myName + ".java"); + + _assert(!testDir.exists()); + + compile( + "-proc:only", + "-processor", myName, + "-Aexpect=false", + file.getPath()); + + testDir.mkdirs(); + _assert(testDir.exists()); + + compile( + "-proc:only", + "-processor", myName, + "-Aexpect=true", + file.getPath()); + } + + void _assert(boolean cond) { + if (!cond) + throw new AssertionError(); + } + + void compile(String... args) throws Exception { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + int rc = com.sun.tools.javac.Main.compile(args, pw); + pw.close(); + String out = sw.toString(); + if (!out.isEmpty()) + System.err.println(out); + if (rc != 0) + throw new Exception("compilation failed unexpectedly: rc=" + rc); + } + + //--------------- + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); + FSInfo fsInfo = context.get(FSInfo.class); + + round++; + if (round == 1) { + boolean expect = Boolean.valueOf(options.get("expect")); + checkEqual("cache result", fsInfo.isDirectory(testDir), expect); + initialFSInfo = fsInfo; + } else { + checkEqual("fsInfo", fsInfo, initialFSInfo); + } + + return true; + } + + void checkEqual(String label, T actual, T expected) { + if (actual != expected) + messager.printMessage(Diagnostic.Kind.ERROR, + "Unexpected value for " + label + + "; expected: " + expected + + "; found: " + actual); + } + + int round = 0; + FSInfo initialFSInfo; +} diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/generics/diamond/neg/Neg12.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/diamond/neg/Neg12.java Thu Feb 24 18:05:10 2011 -0800 @@ -0,0 +1,15 @@ +/* + * @test /nodynamiccopyright/ + * @bug 7020043 + * + * @summary Project Coin: diamond allowed on non-generic type + * @author Rémi Forax + * @compile/fail/ref=Neg12.out Neg12.java -XDrawDiagnostics + * + */ + +class DiamondRaw { + public static void main(String[] args) { + String s = new String<>("foo"); + } +} diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/generics/diamond/neg/Neg12.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/diamond/neg/Neg12.out Thu Feb 24 18:05:10 2011 -0800 @@ -0,0 +1,2 @@ +Neg12.java:13:27: compiler.err.cant.apply.diamond.1: java.lang.String, (compiler.misc.diamond.non.generic: java.lang.String) +1 error diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/nio/compileTest/CompileTest.java --- a/test/tools/javac/nio/compileTest/CompileTest.java Thu Feb 24 15:16:13 2011 -0800 +++ b/test/tools/javac/nio/compileTest/CompileTest.java Thu Feb 24 18:05:10 2011 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,7 +25,7 @@ * @test * @bug 6906175 6915476 6915497 7006564 * @summary Path-based JavaFileManager - * @compile -g HelloPathWorld.java + * @compile -g CompileTest.java HelloPathWorld.java * @run main CompileTest */ diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/processing/model/element/TestTypeParameter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/processing/model/element/TestTypeParameter.java Thu Feb 24 18:05:10 2011 -0800 @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6505047 + * @summary javax.lang.model.element.Element.getEnclosingElement() doesn't return null for type parameter + * @library ../../../lib + * @build JavacTestingAbstractProcessor TestTypeParameter + * @compile -processor TestTypeParameter -proc:only TestTypeParameter.java + */ + +import java.util.*; +import javax.annotation.processing.*; +import javax.lang.model.element.*; +import javax.lang.model.util.*; +import javax.tools.*; + +public class TestTypeParameter extends JavacTestingAbstractProcessor { + int round = 0; + + public boolean process(Set annotations, RoundEnvironment roundEnv) { + if (++round == 1) { + int found = (new Scanner()).scan(roundEnv.getRootElements(), null); + if (found == expect) { + note("generic elements found and verified: " + found); + } else { + error("unexpected number of results: expected " + expect + + ", found " + found); + } + + } + return true; + } + + class Scanner extends ElementScanner7 { + @Override + public Integer visitExecutable(ExecutableElement e, Void p) { + super.visitExecutable(e, p); + found += check(e, e.getTypeParameters()); + return found; + } + + @Override + public Integer visitType(TypeElement e, Void p) { + super.visitType(e, p); + found += check(e, e.getTypeParameters()); + return found; + } + + int found; + } + + /** + * Check if type parameters, if any, have expected owner. + * Return 1 if typarams not empty and all have expected owner, else return 0. + */ + int check(Element e, List typarams) { + note("checking " + e, e); + if (typarams.isEmpty()) { + note("no type parameters found", e); + return 0; + } + for (TypeParameterElement tpe: typarams) { + note("checking type parameter " + tpe, tpe); + if (tpe.getEnclosingElement() != e) { + error("unexpected owner; expected: " + e + + ", found " + tpe.getEnclosingElement(), + tpe); + return 0; + } + if (tpe.getEnclosingElement() != tpe.getGenericElement()) { + error("unexpected generic element; expected: " + tpe.getGenericElement() + + ", found " + tpe.getEnclosingElement(), + tpe); + return 0; + } + } + note("verified " + e, e); + return 1; + } + + void note(String msg) { + messager.printMessage(Diagnostic.Kind.NOTE, msg); + } + + void note(String msg, Element e) { + messager.printMessage(Diagnostic.Kind.NOTE, msg, e); + } + + void error(String msg, Element e) { + messager.printMessage(Diagnostic.Kind.ERROR, msg, e); + } + + void error(String msg) { + messager.printMessage(Diagnostic.Kind.ERROR, msg); + } + + // additional generic elements to test + X m(X x) { return x; } + + interface Intf { X m() ; } + + class Class { + Class() { } + } + + final int expect = 5; // top level class, plus preceding examples +} diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/scope/7017664/CompoundScopeTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/scope/7017664/CompoundScopeTest.java Thu Feb 24 18:05:10 2011 -0800 @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 7017664 + * @summary Basher for CompoundScopes + */ + +import java.util.Random; +import java.util.Map; +import java.util.HashMap; +import com.sun.tools.javac.util.*; +import com.sun.tools.javac.code.*; +import com.sun.tools.javac.code.Scope.*; +import com.sun.tools.javac.code.Symbol.*; +import com.sun.tools.javac.file.JavacFileManager; + +public class CompoundScopeTest { + public static void main(String... args) throws Exception { + new CompoundScopeTest().run(args); + } + + static final int MAX_SYMBOLS_COUNT = 20; + static final int PASSES = 10; + + void run(String... args) throws Exception { + int count = PASSES; + + for (int i = 0; i < args.length; i++) { + String arg = args[i]; + if (arg.equals("-seed") && (i + 1 < args.length)) + seed = Long.parseLong(args[++i]); + else if(arg.equals("-tests") && (i + 1 < args.length)) + count = Integer.parseInt(args[++i]); + else + throw new Exception("unknown arg: " + arg); + } + + rgen = new Random(seed); + + for (int i = 0; i < count; i++) { + Test t = new Test(); + t.run(); + } + + if (errors > 0) + throw new Exception(errors + " errors found"); + } + + /** + * Write a message to stderr. + */ + void log(String msg) { + System.err.println(msg); + } + + /** + * Write an error message to stderr. + */ + void error(String msg) { + System.err.println("Error: " + msg); + errors++; + } + + Random rgen; + long seed = 0; + + int errors; + + /** Class to encapsulate a test run. */ + class Test { + + List elems = List.nil(); + Map> shadowedMap = new HashMap>(); + + /** Run the test. */ + void run() throws Exception { + log ("starting test"); + setup(); + Scope[] scopes = { createScope(rgen.nextInt(MAX_SYMBOLS_COUNT)), + createScope(rgen.nextInt(MAX_SYMBOLS_COUNT)), + createScope(rgen.nextInt(MAX_SYMBOLS_COUNT)) }; + boolean[][] scopeNesting = { {false, true, false, true}, + {false, true, true, true}, + {false, false, true, true} }; + /** + * We want to generate (and check) the following compound scopes: + * C1 = C(S1, S2, S3) + * C2 = C((S1, S2), S3) + * C3 = C(S1, (S2, S3)) + * C3 = C(C(S1, S2, S3)) + */ + for (int i = 0 ; i < 4 ; i ++) { + CompoundScope root = new CompoundScope(symtab.noSymbol); + CompoundScope sub = new CompoundScope(symtab.noSymbol); + boolean subAdded = false; + for (int sc = 0 ; sc < 3 ; sc ++) { + if (scopeNesting[sc][i]) { + sub.addSubScope(scopes[sc]); + if (!subAdded) { + root.addSubScope(sub); + subAdded = true; + } + } else { + root.addSubScope(scopes[sc]); + } + } + log("testing scope: " + root); + checkElems(root); + checkShadowed(root); + } + } + + /** + * Create a scope containing a given number of synthetic symbols + */ + Scope createScope(int nelems) { + Scope s = new Scope(symtab.noSymbol); + for (int i = 0 ; i < nelems ; i++) { + Symbol sym = new TypeSymbol(0, names.fromString("s" + i), null, null); + s.enter(sym); + elems = elems.prepend(sym); + List shadowed = shadowedMap.get(sym.name); + if (shadowed == null) { + shadowed = List.nil(); + } + shadowedMap.put(sym.name, shadowed.prepend(sym)); + } + return s; + } + + /** + * Setup compiler context + */ + void setup() { + log ("setup"); + context = new Context(); + JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab + names = Names.instance(context); // Name.Table impls tied to an instance of Names + symtab = Symtab.instance(context); + } + + /** + * Check that CompoundScope.getElements() correctly visits all symbols + * in all subscopes (in the correct order) + */ + void checkElems(CompoundScope cs) { + List allSymbols = elems; + int count = 0; + for (Symbol s : cs.getElements()) { + checkSameSymbols(s, allSymbols.head); + allSymbols = allSymbols.tail; + count++; + } + if (count != elems.size()) { + error("CompoundScope.getElements() did not returned enough symbols"); + } + } + + /** + * Check that CompoundScope.getElements() correctly visits all symbols + * with a given name in all subscopes (in the correct order) + */ + void checkShadowed(CompoundScope cs) { + for (Map.Entry> shadowedEntry : shadowedMap.entrySet()) { + int count = 0; + List shadowed = shadowedEntry.getValue(); + Name name = shadowedEntry.getKey(); + for (Symbol s : cs.getElementsByName(name)) { + checkSameSymbols(s, shadowed.head); + shadowed = shadowed.tail; + count++; + } + if (count != shadowedEntry.getValue().size()) { + error("CompoundScope.lookup() did not returned enough symbols for name " + name); + } + } + } + + void checkSameSymbols(Symbol found, Symbol req) { + if (found != req) { + error("Symbol mismatch - found : " + found + ":" + found.hashCode() + "\n" + + " required : " + req + ":" + req.hashCode()); + } + } + + Context context; + Symtab symtab; + Names names; + } +} diff -r 80bbd1da4a72 -r e3d011d59a33 test/tools/javac/scope/7017664/ImplementationCacheTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/scope/7017664/ImplementationCacheTest.java Thu Feb 24 18:05:10 2011 -0800 @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 7017664 + * @summary Basher for CompoundScopes + */ + +import com.sun.source.util.JavacTask; +import com.sun.tools.javac.code.Symbol; +import com.sun.tools.javac.code.Types; +import com.sun.tools.javac.file.JavacFileManager; +import com.sun.tools.javac.util.Context; + +import com.sun.tools.javac.code.Symbol.*; + +import java.io.IOException; +import java.net.URI; +import java.util.Arrays; +import java.util.List; +import javax.lang.model.element.Element; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.ToolProvider; + +import static javax.tools.JavaFileObject.Kind; + +public class ImplementationCacheTest { + + static class SourceFile extends SimpleJavaFileObject { + + final String source = "interface I { void m(); }\n" + + "class A implements I { public void m() {} }\n" + + "class B extends A { }\n"; + + public SourceFile() { + super(URI.create("test.java"), Kind.SOURCE); + } + + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return source; + } + } + + public static void main(String[] args) throws IOException { + List files = Arrays.asList(new SourceFile()); + JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); + JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, files); + Context ctx = new Context(); + JavacFileManager.preRegister(ctx); + checkImplementationCache(ct.analyze(), Types.instance(ctx)); + } + + static void checkImplementationCache(Iterable elements, Types types) { + if (types == null) { + throw new AssertionError("problems initializing Types"); + } + + Symbol a = null; + Symbol b = null; + Symbol i = null; + + for (Element e : elements) { + if (e.getSimpleName().contentEquals("A")) { + a = (Symbol)e; + } else if (e.getSimpleName().contentEquals("B")) { + b = (Symbol)e; + } else if (e.getSimpleName().contentEquals("I")) { + i = (Symbol)e; + } + } + + if (a == null || b == null || i == null) { + throw new AssertionError("missing class"); + } + + MethodSymbol I_m = null; + + for (Symbol sym : i.members().getElements()) { + if (sym.name.contentEquals("m")) { + I_m = (MethodSymbol)sym; + } + } + + if (I_m == null) { + throw new AssertionError("missing method m() in scope of interface I"); + } + + Symbol impl = I_m.implementation((TypeSymbol)b, types, true); + + if (impl == null || impl.owner != a) { + throw new AssertionError("wrong implementation for m() in B"); + } + + b.members().enter(I_m.clone(b)); + + Symbol newImpl = I_m.implementation((TypeSymbol)b, types, true); + + if (newImpl == impl) { + throw new AssertionError("stale implementation for m() in B"); + } + + if (newImpl == null || newImpl.owner != b) { + throw new AssertionError("wrong implementation for m() in B"); + } + } +}