Thu, 24 Feb 2011 18:05:10 -0800
Merge
1.1 --- a/make/build.xml Thu Feb 24 15:16:13 2011 -0800 1.2 +++ b/make/build.xml Thu Feb 24 18:05:10 2011 -0800 1.3 @@ -868,8 +868,10 @@ 1.4 executable="${boot.java.home}/bin/javac" 1.5 srcdir="${make.tools.dir}/GenStubs" 1.6 destdir="${build.toolclasses.dir}/" 1.7 - classpath="${build.bootstrap.dir}/classes:${ant.core.lib}" 1.8 - includeantruntime="false"/> 1.9 + classpath="${ant.core.lib}" 1.10 + includeantruntime="false"> 1.11 + <compilerarg value="-Xbootclasspath/p:${build.bootstrap.dir}/classes"/> 1.12 + </javac> 1.13 <taskdef name="genstubs" 1.14 classname="GenStubs$$Ant" 1.15 classpath="${build.toolclasses.dir}/"/>
2.1 --- a/src/share/bin/launcher.sh-template Thu Feb 24 15:16:13 2011 -0800 2.2 +++ b/src/share/bin/launcher.sh-template Thu Feb 24 18:05:10 2011 -0800 2.3 @@ -31,8 +31,7 @@ 2.4 mydir=`cygpath -m $mydir` 2.5 ;; 2.6 esac 2.7 - 2.8 -mylib="`dirname $mydir`"/lib 2.9 +mylib="$mydir/../lib" 2.10 2.11 # By default, put the jar file and its dependencies on the bootclasspath. 2.12 # This is always required on a Mac, because the system langtools classes 2.13 @@ -73,4 +72,4 @@ 2.14 unset DUALCASE 2.15 2.16 IFS=$nl 2.17 -"#TARGET_JAVA#" "${bcp:+-Xbootclasspath/p:"$bcp"}" ${ea} ${javaOpts} -jar "${mydir}"/../lib/#PROGRAM#.jar ${toolOpts} 2.18 +"#TARGET_JAVA#" "${bcp:+-Xbootclasspath/p:"$bcp"}" ${ea} ${javaOpts} -jar "${mylib}/#PROGRAM#.jar" ${toolOpts}
3.1 --- a/src/share/classes/com/sun/tools/javac/code/Scope.java Thu Feb 24 15:16:13 2011 -0800 3.2 +++ b/src/share/classes/com/sun/tools/javac/code/Scope.java Thu Feb 24 18:05:10 2011 -0800 3.3 @@ -74,7 +74,7 @@ 3.4 3.5 /** A list of scopes to be notified if items are to be removed from this scope. 3.6 */ 3.7 - List<Scope> listeners = List.nil(); 3.8 + List<ScopeListener> listeners = List.nil(); 3.9 3.10 /** Use as a "not-found" result for lookup. 3.11 * Also used to mark deleted entries in the table. 3.12 @@ -219,12 +219,27 @@ 3.13 Entry e = makeEntry(sym, old, elems, s, origin); 3.14 table[hash] = e; 3.15 elems = e; 3.16 + 3.17 + //notify listeners 3.18 + for (List<ScopeListener> l = listeners; l.nonEmpty(); l = l.tail) { 3.19 + l.head.symbolAdded(sym, this); 3.20 + } 3.21 } 3.22 3.23 Entry makeEntry(Symbol sym, Entry shadowed, Entry sibling, Scope scope, Scope origin) { 3.24 return new Entry(sym, shadowed, sibling, scope); 3.25 } 3.26 3.27 + 3.28 + public interface ScopeListener { 3.29 + public void symbolAdded(Symbol sym, Scope s); 3.30 + public void symbolRemoved(Symbol sym, Scope s); 3.31 + } 3.32 + 3.33 + public void addScopeListener(ScopeListener sl) { 3.34 + listeners = listeners.prepend(sl); 3.35 + } 3.36 + 3.37 /** Remove symbol from this scope. Used when an inner class 3.38 * attribute tells us that the class isn't a package member. 3.39 */ 3.40 @@ -258,9 +273,9 @@ 3.41 te = te.sibling; 3.42 } 3.43 3.44 - // remove items from scopes that have done importAll 3.45 - for (List<Scope> l = listeners; l.nonEmpty(); l = l.tail) { 3.46 - l.head.remove(sym); 3.47 + //notify listeners 3.48 + for (List<ScopeListener> l = listeners; l.nonEmpty(); l = l.tail) { 3.49 + l.head.symbolRemoved(sym, this); 3.50 } 3.51 } 3.52 3.53 @@ -393,7 +408,32 @@ 3.54 }; 3.55 } 3.56 }; 3.57 + } 3.58 3.59 + public Iterable<Symbol> getElementsByName(Name name) { 3.60 + return getElementsByName(name, noFilter); 3.61 + } 3.62 + 3.63 + public Iterable<Symbol> getElementsByName(final Name name, final Filter<Symbol> sf) { 3.64 + return new Iterable<Symbol>() { 3.65 + public Iterator<Symbol> iterator() { 3.66 + return new Iterator<Symbol>() { 3.67 + Scope.Entry currentEntry = lookup(name, sf); 3.68 + 3.69 + public boolean hasNext() { 3.70 + return currentEntry.scope != null; 3.71 + } 3.72 + public Symbol next() { 3.73 + Scope.Entry prevEntry = currentEntry; 3.74 + currentEntry = currentEntry.next(sf); 3.75 + return prevEntry.sym; 3.76 + } 3.77 + public void remove() { 3.78 + throw new UnsupportedOperationException(); 3.79 + } 3.80 + }; 3.81 + } 3.82 + }; 3.83 } 3.84 3.85 public String toString() { 3.86 @@ -488,7 +528,7 @@ 3.87 } 3.88 } 3.89 3.90 - public static class StarImportScope extends ImportScope { 3.91 + public static class StarImportScope extends ImportScope implements ScopeListener { 3.92 3.93 public StarImportScope(Symbol owner) { 3.94 super(owner); 3.95 @@ -500,8 +540,13 @@ 3.96 enter(e.sym, fromScope); 3.97 } 3.98 // Register to be notified when imported items are removed 3.99 - fromScope.listeners = fromScope.listeners.prepend(this); 3.100 + fromScope.addScopeListener(this); 3.101 } 3.102 + 3.103 + public void symbolRemoved(Symbol sym, Scope s) { 3.104 + remove(sym); 3.105 + } 3.106 + public void symbolAdded(Symbol sym, Scope s) { } 3.107 } 3.108 3.109 /** An empty scope, into which you can't place anything. Used for 3.110 @@ -538,6 +583,151 @@ 3.111 } 3.112 } 3.113 3.114 + /** A class scope adds capabilities to keep track of changes in related 3.115 + * class scopes - this allows client to realize whether a class scope 3.116 + * has changed, either directly (because a new member has been added/removed 3.117 + * to this scope) or indirectly (i.e. because a new member has been 3.118 + * added/removed into a supertype scope) 3.119 + */ 3.120 + public static class CompoundScope extends Scope implements ScopeListener { 3.121 + 3.122 + public static final Entry[] emptyTable = new Entry[0]; 3.123 + 3.124 + private List<Scope> subScopes = List.nil(); 3.125 + private int mark = 0; 3.126 + 3.127 + public CompoundScope(Symbol owner) { 3.128 + super(null, owner, emptyTable); 3.129 + } 3.130 + 3.131 + public void addSubScope(Scope that) { 3.132 + if (that != null) { 3.133 + subScopes = subScopes.prepend(that); 3.134 + that.addScopeListener(this); 3.135 + mark++; 3.136 + for (ScopeListener sl : listeners) { 3.137 + sl.symbolAdded(null, this); //propagate upwards in case of nested CompoundScopes 3.138 + } 3.139 + } 3.140 + } 3.141 + 3.142 + public void symbolAdded(Symbol sym, Scope s) { 3.143 + mark++; 3.144 + for (ScopeListener sl : listeners) { 3.145 + sl.symbolAdded(sym, s); 3.146 + } 3.147 + } 3.148 + 3.149 + public void symbolRemoved(Symbol sym, Scope s) { 3.150 + mark++; 3.151 + for (ScopeListener sl : listeners) { 3.152 + sl.symbolRemoved(sym, s); 3.153 + } 3.154 + } 3.155 + 3.156 + public int getMark() { 3.157 + return mark; 3.158 + } 3.159 + 3.160 + @Override 3.161 + public String toString() { 3.162 + StringBuilder buf = new StringBuilder(); 3.163 + buf.append("CompoundScope{"); 3.164 + String sep = ""; 3.165 + for (Scope s : subScopes) { 3.166 + buf.append(sep); 3.167 + buf.append(s); 3.168 + sep = ","; 3.169 + } 3.170 + buf.append("}"); 3.171 + return buf.toString(); 3.172 + } 3.173 + 3.174 + @Override 3.175 + public Iterable<Symbol> getElements(final Filter<Symbol> sf) { 3.176 + return new Iterable<Symbol>() { 3.177 + public Iterator<Symbol> iterator() { 3.178 + return new CompoundScopeIterator(subScopes) { 3.179 + Iterator<Symbol> nextIterator(Scope s) { 3.180 + return s.getElements().iterator(); 3.181 + } 3.182 + }; 3.183 + } 3.184 + }; 3.185 + } 3.186 + 3.187 + @Override 3.188 + public Iterable<Symbol> getElementsByName(final Name name, final Filter<Symbol> sf) { 3.189 + return new Iterable<Symbol>() { 3.190 + public Iterator<Symbol> iterator() { 3.191 + return new CompoundScopeIterator(subScopes) { 3.192 + Iterator<Symbol> nextIterator(Scope s) { 3.193 + return s.getElementsByName(name, sf).iterator(); 3.194 + } 3.195 + }; 3.196 + } 3.197 + }; 3.198 + } 3.199 + 3.200 + abstract class CompoundScopeIterator implements Iterator<Symbol> { 3.201 + 3.202 + private Iterator<Symbol> currentIterator; 3.203 + private List<Scope> scopesToScan; 3.204 + 3.205 + public CompoundScopeIterator(List<Scope> scopesToScan) { 3.206 + this.scopesToScan = scopesToScan; 3.207 + update(); 3.208 + } 3.209 + 3.210 + abstract Iterator<Symbol> nextIterator(Scope s); 3.211 + 3.212 + public boolean hasNext() { 3.213 + return currentIterator != null; 3.214 + } 3.215 + 3.216 + public Symbol next() { 3.217 + Symbol sym = currentIterator.next(); 3.218 + if (!currentIterator.hasNext()) { 3.219 + update(); 3.220 + } 3.221 + return sym; 3.222 + } 3.223 + 3.224 + public void remove() { 3.225 + throw new UnsupportedOperationException(); 3.226 + } 3.227 + 3.228 + private void update() { 3.229 + while (scopesToScan.nonEmpty()) { 3.230 + currentIterator = nextIterator(scopesToScan.head); 3.231 + scopesToScan = scopesToScan.tail; 3.232 + if (currentIterator.hasNext()) return; 3.233 + } 3.234 + currentIterator = null; 3.235 + } 3.236 + } 3.237 + 3.238 + @Override 3.239 + public Entry lookup(Name name, Filter<Symbol> sf) { 3.240 + throw new UnsupportedOperationException(); 3.241 + } 3.242 + 3.243 + @Override 3.244 + public Scope dup(Symbol newOwner) { 3.245 + throw new UnsupportedOperationException(); 3.246 + } 3.247 + 3.248 + @Override 3.249 + public void enter(Symbol sym, Scope s, Scope origin) { 3.250 + throw new UnsupportedOperationException(); 3.251 + } 3.252 + 3.253 + @Override 3.254 + public void remove(Symbol sym) { 3.255 + throw new UnsupportedOperationException(); 3.256 + } 3.257 + } 3.258 + 3.259 /** An error scope, for which the owner should be an error symbol. */ 3.260 public static class ErrorScope extends Scope { 3.261 ErrorScope(Scope next, Symbol errSymbol, Entry[] table) {
4.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Thu Feb 24 15:16:13 2011 -0800 4.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Thu Feb 24 18:05:10 2011 -0800 4.3 @@ -731,7 +731,7 @@ 4.4 4.5 /** members closure cache (set by Types.membersClosure) 4.6 */ 4.7 - Scope membersClosure; 4.8 + Scope.CompoundScope membersClosure; 4.9 4.10 public ClassSymbol(long flags, Name name, Type type, Symbol owner) { 4.11 super(flags, name, type, owner);
5.1 --- a/src/share/classes/com/sun/tools/javac/code/Type.java Thu Feb 24 15:16:13 2011 -0800 5.2 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Thu Feb 24 18:05:10 2011 -0800 5.3 @@ -270,10 +270,6 @@ 5.4 public Type getUpperBound() { return null; } 5.5 public Type getLowerBound() { return null; } 5.6 5.7 - public void setThrown(List<Type> ts) { 5.8 - throw new AssertionError(); 5.9 - } 5.10 - 5.11 /** Navigation methods, these will work for classes, type variables, 5.12 * foralls, but will return null for arrays and methods. 5.13 */ 5.14 @@ -388,14 +384,6 @@ 5.15 */ 5.16 public void complete() {} 5.17 5.18 - public Object clone() { 5.19 - try { 5.20 - return super.clone(); 5.21 - } catch (CloneNotSupportedException e) { 5.22 - throw new AssertionError(e); 5.23 - } 5.24 - } 5.25 - 5.26 public TypeSymbol asElement() { 5.27 return tsym; 5.28 } 5.29 @@ -817,8 +805,7 @@ 5.30 } 5.31 } 5.32 5.33 - public static class MethodType extends Type 5.34 - implements Cloneable, ExecutableType { 5.35 + public static class MethodType extends Type implements ExecutableType { 5.36 5.37 public List<Type> argtypes; 5.38 public Type restype; 5.39 @@ -880,10 +867,6 @@ 5.40 public Type getReturnType() { return restype; } 5.41 public List<Type> getThrownTypes() { return thrown; } 5.42 5.43 - public void setThrown(List<Type> t) { 5.44 - thrown = t; 5.45 - } 5.46 - 5.47 public boolean isErroneous() { 5.48 return 5.49 isErroneous(argtypes) || 5.50 @@ -1068,12 +1051,10 @@ 5.51 public List<Type> getThrownTypes() { return qtype.getThrownTypes(); } 5.52 public List<Type> allparams() { return qtype.allparams(); } 5.53 public Type getUpperBound() { return qtype.getUpperBound(); } 5.54 - public Object clone() { DelegatedType t = (DelegatedType)super.clone(); t.qtype = (Type)qtype.clone(); return t; } 5.55 public boolean isErroneous() { return qtype.isErroneous(); } 5.56 } 5.57 5.58 - public static class ForAll extends DelegatedType 5.59 - implements Cloneable, ExecutableType { 5.60 + public static class ForAll extends DelegatedType implements ExecutableType { 5.61 public List<Type> tvars; 5.62 5.63 public ForAll(List<Type> tvars, Type qtype) { 5.64 @@ -1092,16 +1073,6 @@ 5.65 5.66 public List<Type> getTypeArguments() { return tvars; } 5.67 5.68 - public void setThrown(List<Type> t) { 5.69 - qtype.setThrown(t); 5.70 - } 5.71 - 5.72 - public Object clone() { 5.73 - ForAll result = (ForAll)super.clone(); 5.74 - result.qtype = (Type)result.qtype.clone(); 5.75 - return result; 5.76 - } 5.77 - 5.78 public boolean isErroneous() { 5.79 return qtype.isErroneous(); 5.80 }
6.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Thu Feb 24 15:16:13 2011 -0800 6.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Thu Feb 24 18:05:10 2011 -0800 6.3 @@ -2023,18 +2023,22 @@ 6.4 final MethodSymbol cachedImpl; 6.5 final Filter<Symbol> implFilter; 6.6 final boolean checkResult; 6.7 + final int prevMark; 6.8 6.9 public Entry(MethodSymbol cachedImpl, 6.10 Filter<Symbol> scopeFilter, 6.11 - boolean checkResult) { 6.12 + boolean checkResult, 6.13 + int prevMark) { 6.14 this.cachedImpl = cachedImpl; 6.15 this.implFilter = scopeFilter; 6.16 this.checkResult = checkResult; 6.17 + this.prevMark = prevMark; 6.18 } 6.19 6.20 - boolean matches(Filter<Symbol> scopeFilter, boolean checkResult) { 6.21 + boolean matches(Filter<Symbol> scopeFilter, boolean checkResult, int mark) { 6.22 return this.implFilter == scopeFilter && 6.23 - this.checkResult == checkResult; 6.24 + this.checkResult == checkResult && 6.25 + this.prevMark == mark; 6.26 } 6.27 } 6.28 6.29 @@ -2046,10 +2050,11 @@ 6.30 _map.put(ms, new SoftReference<Map<TypeSymbol, Entry>>(cache)); 6.31 } 6.32 Entry e = cache.get(origin); 6.33 + CompoundScope members = membersClosure(origin.type); 6.34 if (e == null || 6.35 - !e.matches(implFilter, checkResult)) { 6.36 - MethodSymbol impl = implementationInternal(ms, origin, Types.this, checkResult, implFilter); 6.37 - cache.put(origin, new Entry(impl, implFilter, checkResult)); 6.38 + !e.matches(implFilter, checkResult, members.getMark())) { 6.39 + MethodSymbol impl = implementationInternal(ms, origin, checkResult, implFilter); 6.40 + cache.put(origin, new Entry(impl, implFilter, checkResult, members.getMark())); 6.41 return impl; 6.42 } 6.43 else { 6.44 @@ -2057,8 +2062,8 @@ 6.45 } 6.46 } 6.47 6.48 - private MethodSymbol implementationInternal(MethodSymbol ms, TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) { 6.49 - for (Type t = origin.type; t.tag == CLASS || t.tag == TYPEVAR; t = types.supertype(t)) { 6.50 + private MethodSymbol implementationInternal(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter<Symbol> implFilter) { 6.51 + for (Type t = origin.type; t.tag == CLASS || t.tag == TYPEVAR; t = supertype(t)) { 6.52 while (t.tag == TYPEVAR) 6.53 t = t.getUpperBound(); 6.54 TypeSymbol c = t.tsym; 6.55 @@ -2066,7 +2071,7 @@ 6.56 e.scope != null; 6.57 e = e.next(implFilter)) { 6.58 if (e.sym != null && 6.59 - e.sym.overrides(ms, origin, types, checkResult)) 6.60 + e.sym.overrides(ms, origin, Types.this, checkResult)) 6.61 return (MethodSymbol)e.sym; 6.62 } 6.63 } 6.64 @@ -2082,46 +2087,35 @@ 6.65 // </editor-fold> 6.66 6.67 // <editor-fold defaultstate="collapsed" desc="compute transitive closure of all members in given site"> 6.68 - public Scope membersClosure(Type site) { 6.69 + public CompoundScope membersClosure(Type site) { 6.70 return membersClosure.visit(site); 6.71 } 6.72 6.73 - UnaryVisitor<Scope> membersClosure = new UnaryVisitor<Scope>() { 6.74 - 6.75 - public Scope visitType(Type t, Void s) { 6.76 + UnaryVisitor<CompoundScope> membersClosure = new UnaryVisitor<CompoundScope>() { 6.77 + 6.78 + public CompoundScope visitType(Type t, Void s) { 6.79 return null; 6.80 } 6.81 6.82 @Override 6.83 - public Scope visitClassType(ClassType t, Void s) { 6.84 + public CompoundScope visitClassType(ClassType t, Void s) { 6.85 ClassSymbol csym = (ClassSymbol)t.tsym; 6.86 if (csym.membersClosure == null) { 6.87 - Scope membersClosure = new Scope(csym); 6.88 + CompoundScope membersClosure = new CompoundScope(csym); 6.89 for (Type i : interfaces(t)) { 6.90 - enterAll(visit(i), membersClosure); 6.91 + membersClosure.addSubScope(visit(i)); 6.92 } 6.93 - enterAll(visit(supertype(t)), membersClosure); 6.94 - enterAll(csym.members(), membersClosure); 6.95 + membersClosure.addSubScope(visit(supertype(t))); 6.96 + membersClosure.addSubScope(csym.members()); 6.97 csym.membersClosure = membersClosure; 6.98 } 6.99 return csym.membersClosure; 6.100 } 6.101 6.102 @Override 6.103 - public Scope visitTypeVar(TypeVar t, Void s) { 6.104 + public CompoundScope visitTypeVar(TypeVar t, Void s) { 6.105 return visit(t.getUpperBound()); 6.106 } 6.107 - 6.108 - public void enterAll(Scope s, Scope to) { 6.109 - if (s == null) return; 6.110 - List<Symbol> syms = List.nil(); 6.111 - for (Scope.Entry e = s.elems ; e != null ; e = e.sibling) { 6.112 - syms = syms.prepend(e.sym); 6.113 - } 6.114 - for (Symbol sym : syms) { 6.115 - to.enter(sym); 6.116 - } 6.117 - } 6.118 }; 6.119 // </editor-fold> 6.120 6.121 @@ -2413,6 +2407,38 @@ 6.122 }; 6.123 // </editor-fold> 6.124 6.125 + public Type createMethodTypeWithParameters(Type original, List<Type> newParams) { 6.126 + return original.accept(methodWithParameters, newParams); 6.127 + } 6.128 + // where 6.129 + private final MapVisitor<List<Type>> methodWithParameters = new MapVisitor<List<Type>>() { 6.130 + public Type visitType(Type t, List<Type> newParams) { 6.131 + throw new IllegalArgumentException("Not a method type: " + t); 6.132 + } 6.133 + public Type visitMethodType(MethodType t, List<Type> newParams) { 6.134 + return new MethodType(newParams, t.restype, t.thrown, t.tsym); 6.135 + } 6.136 + public Type visitForAll(ForAll t, List<Type> newParams) { 6.137 + return new ForAll(t.tvars, t.qtype.accept(this, newParams)); 6.138 + } 6.139 + }; 6.140 + 6.141 + public Type createMethodTypeWithThrown(Type original, List<Type> newThrown) { 6.142 + return original.accept(methodWithThrown, newThrown); 6.143 + } 6.144 + // where 6.145 + private final MapVisitor<List<Type>> methodWithThrown = new MapVisitor<List<Type>>() { 6.146 + public Type visitType(Type t, List<Type> newThrown) { 6.147 + throw new IllegalArgumentException("Not a method type: " + t); 6.148 + } 6.149 + public Type visitMethodType(MethodType t, List<Type> newThrown) { 6.150 + return new MethodType(t.argtypes, t.restype, newThrown, t.tsym); 6.151 + } 6.152 + public Type visitForAll(ForAll t, List<Type> newThrown) { 6.153 + return new ForAll(t.tvars, t.qtype.accept(this, newThrown)); 6.154 + } 6.155 + }; 6.156 + 6.157 // <editor-fold defaultstate="collapsed" desc="createErrorType"> 6.158 public Type createErrorType(Type originalType) { 6.159 return new ErrorType(originalType, syms.errSymbol);
7.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Feb 24 15:16:13 2011 -0800 7.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Feb 24 18:05:10 2011 -0800 7.3 @@ -1584,6 +1584,11 @@ 7.4 if (!TreeInfo.isDiamond(tree)) { 7.5 clazztype = chk.checkClassType( 7.6 tree.clazz.pos(), clazztype, true); 7.7 + } else if (!clazztype.isErroneous() && 7.8 + !clazztype.tsym.type.isParameterized()) { 7.9 + log.error(tree.clazz.pos(), 7.10 + "cant.apply.diamond.1", 7.11 + clazztype, diags.fragment("diamond.non.generic", clazztype)); 7.12 } 7.13 chk.validate(clazz, localEnv); 7.14 if (tree.encl != null) { 7.15 @@ -1609,7 +1614,7 @@ 7.16 List<Type> argtypes = attribArgs(tree.args, localEnv); 7.17 List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv); 7.18 7.19 - if (TreeInfo.isDiamond(tree)) { 7.20 + if (TreeInfo.isDiamond(tree) && clazztype.tsym.type.isParameterized()) { 7.21 clazztype = attribDiamond(localEnv, tree, clazztype, mapping, argtypes, typeargtypes); 7.22 clazz.type = clazztype; 7.23 } else if (allowDiamondFinder &&
8.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Feb 24 15:16:13 2011 -0800 8.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Feb 24 18:05:10 2011 -0800 8.3 @@ -2106,32 +2106,32 @@ 8.4 void checkOverrideClashes(DiagnosticPosition pos, Type site, MethodSymbol sym) { 8.5 ClashFilter cf = new ClashFilter(site); 8.6 //for each method m1 that is a member of 'site'... 8.7 - for (Scope.Entry e1 = types.membersClosure(site).lookup(sym.name, cf) ; 8.8 - e1.scope != null ; e1 = e1.next(cf)) { 8.9 + for (Symbol s1 : types.membersClosure(site).getElementsByName(sym.name, cf)) { 8.10 //...find another method m2 that is overridden (directly or indirectly) 8.11 //by method 'sym' in 'site' 8.12 - for (Scope.Entry e2 = types.membersClosure(site).lookup(sym.name, cf) ; 8.13 - e2.scope != null ; e2 = e2.next(cf)) { 8.14 - if (e1.sym == e2.sym || !sym.overrides(e2.sym, site.tsym, types, false)) continue; 8.15 + for (Symbol s2 : types.membersClosure(site).getElementsByName(sym.name, cf)) { 8.16 + if (s1 == s2 || !sym.overrides(s2, site.tsym, types, false)) continue; 8.17 //if (i) the signature of 'sym' is not a subsignature of m1 (seen as 8.18 //a member of 'site') and (ii) m1 has the same erasure as m2, issue an error 8.19 - if (!types.isSubSignature(sym.type, types.memberType(site, e1.sym)) && 8.20 - types.hasSameArgs(e1.sym.erasure(types), e2.sym.erasure(types))) { 8.21 + if (!types.isSubSignature(sym.type, types.memberType(site, s1)) && 8.22 + types.hasSameArgs(s1.erasure(types), s2.erasure(types))) { 8.23 sym.flags_field |= CLASH; 8.24 - String key = e2.sym == sym ? 8.25 + String key = s2 == sym ? 8.26 "name.clash.same.erasure.no.override" : 8.27 "name.clash.same.erasure.no.override.1"; 8.28 log.error(pos, 8.29 key, 8.30 sym, sym.location(), 8.31 - e1.sym, e1.sym.location(), 8.32 - e2.sym, e2.sym.location()); 8.33 + s1, s1.location(), 8.34 + s2, s2.location()); 8.35 return; 8.36 } 8.37 } 8.38 } 8.39 } 8.40 8.41 + 8.42 + 8.43 /** Check that all static methods accessible from 'site' are 8.44 * mutually compatible (JLS 8.4.8). 8.45 * 8.46 @@ -2142,16 +2142,15 @@ 8.47 void checkHideClashes(DiagnosticPosition pos, Type site, MethodSymbol sym) { 8.48 ClashFilter cf = new ClashFilter(site); 8.49 //for each method m1 that is a member of 'site'... 8.50 - for (Scope.Entry e = types.membersClosure(site).lookup(sym.name, cf) ; 8.51 - e.scope != null ; e = e.next(cf)) { 8.52 + for (Symbol s : types.membersClosure(site).getElementsByName(sym.name, cf)) { 8.53 //if (i) the signature of 'sym' is not a subsignature of m1 (seen as 8.54 //a member of 'site') and (ii) 'sym' has the same erasure as m1, issue an error 8.55 - if (!types.isSubSignature(sym.type, types.memberType(site, e.sym)) && 8.56 - types.hasSameArgs(e.sym.erasure(types), sym.erasure(types))) { 8.57 + if (!types.isSubSignature(sym.type, types.memberType(site, s)) && 8.58 + types.hasSameArgs(s.erasure(types), sym.erasure(types))) { 8.59 log.error(pos, 8.60 "name.clash.same.erasure.no.hide", 8.61 sym, sym.location(), 8.62 - e.sym, e.sym.location()); 8.63 + s, s.location()); 8.64 return; 8.65 } 8.66 }
9.1 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java Thu Feb 24 15:16:13 2011 -0800 9.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java Thu Feb 24 18:05:10 2011 -0800 9.3 @@ -314,13 +314,22 @@ 9.4 for (PendingExit exit = pendingExits.next(); 9.5 exit != null; 9.6 exit = pendingExits.next()) { 9.7 - boolean synthetic = classDef != null && 9.8 - classDef.pos == exit.tree.pos; 9.9 - log.error(exit.tree.pos(), 9.10 - synthetic 9.11 - ? "unreported.exception.default.constructor" 9.12 - : "unreported.exception.need.to.catch.or.throw", 9.13 - exit.thrown); 9.14 + if (classDef != null && 9.15 + classDef.pos == exit.tree.pos) { 9.16 + log.error(exit.tree.pos(), 9.17 + "unreported.exception.default.constructor", 9.18 + exit.thrown); 9.19 + } else if (exit.tree.getTag() == JCTree.VARDEF && 9.20 + ((JCVariableDecl)exit.tree).sym.isResourceVariable()) { 9.21 + log.error(exit.tree.pos(), 9.22 + "unreported.exception.implicit.close", 9.23 + exit.thrown, 9.24 + ((JCVariableDecl)exit.tree).sym.name); 9.25 + } else { 9.26 + log.error(exit.tree.pos(), 9.27 + "unreported.exception.need.to.catch.or.throw", 9.28 + exit.thrown); 9.29 + } 9.30 } 9.31 } 9.32 9.33 @@ -664,12 +673,15 @@ 9.34 // in an anonymous class, add the set of thrown exceptions to 9.35 // the throws clause of the synthetic constructor and propagate 9.36 // outwards. 9.37 + // Changing the throws clause on the fly is okay here because 9.38 + // the anonymous constructor can't be invoked anywhere else, 9.39 + // and its type hasn't been cached. 9.40 if (tree.name == names.empty) { 9.41 for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { 9.42 if (TreeInfo.isInitialConstructor(l.head)) { 9.43 JCMethodDecl mdef = (JCMethodDecl)l.head; 9.44 mdef.thrown = make.Types(thrown); 9.45 - mdef.sym.type.setThrown(thrown); 9.46 + mdef.sym.type = types.createMethodTypeWithThrown(mdef.sym.type, thrown); 9.47 } 9.48 } 9.49 thrownPrev = chk.union(thrown, thrownPrev); 9.50 @@ -1021,7 +1033,7 @@ 9.51 List.<Type>nil()); 9.52 if (closeMethod.kind == MTH) { 9.53 for (Type t : ((MethodSymbol)closeMethod).getThrownTypes()) { 9.54 - markThrown(tree.body, t); 9.55 + markThrown(resource, t); 9.56 } 9.57 } 9.58 }
10.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Feb 24 15:16:13 2011 -0800 10.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Feb 24 18:05:10 2011 -0800 10.3 @@ -1425,25 +1425,55 @@ 10.4 } 10.5 } 10.6 10.7 - /** Optionally replace a try statement with an automatic resource 10.8 - * management (ARM) block. 10.9 + /** 10.10 + * Optionally replace a try statement with the desugaring of a 10.11 + * try-with-resources statement. The canonical desugaring of 10.12 + * 10.13 + * try ResourceSpecification 10.14 + * Block 10.15 + * 10.16 + * is 10.17 + * 10.18 + * { 10.19 + * final VariableModifiers_minus_final R #resource = Expression; 10.20 + * Throwable #primaryException = null; 10.21 + * 10.22 + * try ResourceSpecificationtail 10.23 + * Block 10.24 + * catch (Throwable #t) { 10.25 + * #primaryException = t; 10.26 + * throw #t; 10.27 + * } finally { 10.28 + * if (#resource != null) { 10.29 + * if (#primaryException != null) { 10.30 + * try { 10.31 + * #resource.close(); 10.32 + * } catch(Throwable #suppressedException) { 10.33 + * #primaryException.addSuppressed(#suppressedException); 10.34 + * } 10.35 + * } else { 10.36 + * #resource.close(); 10.37 + * } 10.38 + * } 10.39 + * } 10.40 + * 10.41 * @param tree The try statement to inspect. 10.42 - * @return An ARM block, or the original try block if there are no 10.43 - * resources to manage. 10.44 + * @return A a desugared try-with-resources tree, or the original 10.45 + * try block if there are no resources to manage. 10.46 */ 10.47 - JCTree makeArmTry(JCTry tree) { 10.48 + JCTree makeTwrTry(JCTry tree) { 10.49 make_at(tree.pos()); 10.50 twrVars = twrVars.dup(); 10.51 - JCBlock armBlock = makeArmBlock(tree.resources, tree.body, 0); 10.52 + JCBlock twrBlock = makeTwrBlock(tree.resources, tree.body, 0); 10.53 if (tree.catchers.isEmpty() && tree.finalizer == null) 10.54 - result = translate(armBlock); 10.55 + result = translate(twrBlock); 10.56 else 10.57 - result = translate(make.Try(armBlock, tree.catchers, tree.finalizer)); 10.58 + result = translate(make.Try(twrBlock, tree.catchers, tree.finalizer)); 10.59 twrVars = twrVars.leave(); 10.60 return result; 10.61 } 10.62 10.63 - private JCBlock makeArmBlock(List<JCTree> resources, JCBlock block, int depth) { 10.64 + private JCBlock makeTwrBlock(List<JCTree> resources, JCBlock block, int depth) { 10.65 if (resources.isEmpty()) 10.66 return block; 10.67 10.68 @@ -1497,16 +1527,16 @@ 10.69 10.70 int oldPos = make.pos; 10.71 make.at(TreeInfo.endPos(block)); 10.72 - JCBlock finallyClause = makeArmFinallyClause(primaryException, expr); 10.73 + JCBlock finallyClause = makeTwrFinallyClause(primaryException, expr); 10.74 make.at(oldPos); 10.75 - JCTry outerTry = make.Try(makeArmBlock(resources.tail, block, depth + 1), 10.76 + JCTry outerTry = make.Try(makeTwrBlock(resources.tail, block, depth + 1), 10.77 List.<JCCatch>of(catchClause), 10.78 finallyClause); 10.79 stats.add(outerTry); 10.80 return make.Block(0L, stats.toList()); 10.81 } 10.82 10.83 - private JCBlock makeArmFinallyClause(Symbol primaryException, JCExpression resource) { 10.84 + private JCBlock makeTwrFinallyClause(Symbol primaryException, JCExpression resource) { 10.85 // primaryException.addSuppressed(catchException); 10.86 VarSymbol catchException = 10.87 new VarSymbol(0, make.paramName(2), 10.88 @@ -1525,22 +1555,30 @@ 10.89 List<JCCatch> catchClauses = List.<JCCatch>of(make.Catch(catchExceptionDecl, catchBlock)); 10.90 JCTry tryTree = make.Try(tryBlock, catchClauses, null); 10.91 10.92 - // if (resource != null) resourceClose; 10.93 - JCExpression nullCheck = makeBinary(JCTree.NE, 10.94 - make.Ident(primaryException), 10.95 - makeNull()); 10.96 - JCIf closeIfStatement = make.If(nullCheck, 10.97 + // if (primaryException != null) {try...} else resourceClose; 10.98 + JCIf closeIfStatement = make.If(makeNonNullCheck(make.Ident(primaryException)), 10.99 tryTree, 10.100 makeResourceCloseInvocation(resource)); 10.101 - return make.Block(0L, List.<JCStatement>of(closeIfStatement)); 10.102 + 10.103 + // if (#resource != null) { if (primaryException ... } 10.104 + return make.Block(0L, 10.105 + List.<JCStatement>of(make.If(makeNonNullCheck(resource), 10.106 + closeIfStatement, 10.107 + null))); 10.108 } 10.109 10.110 private JCStatement makeResourceCloseInvocation(JCExpression resource) { 10.111 // create resource.close() method invocation 10.112 - JCExpression resourceClose = makeCall(resource, names.close, List.<JCExpression>nil()); 10.113 + JCExpression resourceClose = makeCall(resource, 10.114 + names.close, 10.115 + List.<JCExpression>nil()); 10.116 return make.Exec(resourceClose); 10.117 } 10.118 10.119 + private JCExpression makeNonNullCheck(JCExpression expression) { 10.120 + return makeBinary(JCTree.NE, expression, makeNull()); 10.121 + } 10.122 + 10.123 /** Construct a tree that represents the outer instance 10.124 * <C.this>. Never pick the current `this'. 10.125 * @param pos The source code position to be used for the tree. 10.126 @@ -3573,7 +3611,7 @@ 10.127 if (tree.resources.isEmpty()) { 10.128 super.visitTry(tree); 10.129 } else { 10.130 - result = makeArmTry(tree); 10.131 + result = makeTwrTry(tree); 10.132 } 10.133 } 10.134
11.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Feb 24 15:16:13 2011 -0800 11.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Feb 24 18:05:10 2011 -0800 11.3 @@ -776,10 +776,12 @@ 11.4 // due to error recovery or mixing incompatible class files 11.5 return ambiguityError(m1, m2); 11.6 } 11.7 + List<Type> allThrown = chk.intersect(mt1.getThrownTypes(), mt2.getThrownTypes()); 11.8 + Type newSig = types.createMethodTypeWithThrown(mostSpecific.type, allThrown); 11.9 MethodSymbol result = new MethodSymbol( 11.10 mostSpecific.flags(), 11.11 mostSpecific.name, 11.12 - null, 11.13 + newSig, 11.14 mostSpecific.owner) { 11.15 @Override 11.16 public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) { 11.17 @@ -789,9 +791,6 @@ 11.18 return super.implementation(origin, types, checkResult); 11.19 } 11.20 }; 11.21 - result.type = (Type)mostSpecific.type.clone(); 11.22 - result.type.setThrown(chk.intersect(mt1.getThrownTypes(), 11.23 - mt2.getThrownTypes())); 11.24 return result; 11.25 } 11.26 if (m1SignatureMoreSpecific) return m1; 11.27 @@ -852,13 +851,8 @@ 11.28 } 11.29 //append varargs element type as last synthetic formal 11.30 args.append(types.elemtype(varargsTypeTo)); 11.31 - MethodSymbol msym = new MethodSymbol(to.flags_field, 11.32 - to.name, 11.33 - (Type)to.type.clone(), //see: 6990136 11.34 - to.owner); 11.35 - MethodType mtype = msym.type.asMethodType(); 11.36 - mtype.argtypes = args.toList(); 11.37 - return msym; 11.38 + Type mtype = types.createMethodTypeWithParameters(to.type, args.toList()); 11.39 + return new MethodSymbol(to.flags_field, to.name, mtype, to.owner); 11.40 } else { 11.41 return to; 11.42 }
12.1 --- a/src/share/classes/com/sun/tools/javac/file/CacheFSInfo.java Thu Feb 24 15:16:13 2011 -0800 12.2 +++ b/src/share/classes/com/sun/tools/javac/file/CacheFSInfo.java Thu Feb 24 18:05:10 2011 -0800 12.3 @@ -49,16 +49,13 @@ 12.4 public static void preRegister(final Context context) { 12.5 context.put(FSInfo.class, new Context.Factory<FSInfo>() { 12.6 public FSInfo make() { 12.7 - if (singleton == null) 12.8 - singleton = new CacheFSInfo(); 12.9 - context.put(FSInfo.class, singleton); 12.10 - return singleton; 12.11 + FSInfo instance = new CacheFSInfo(); 12.12 + context.put(FSInfo.class, instance); 12.13 + return instance; 12.14 } 12.15 }); 12.16 } 12.17 12.18 - static CacheFSInfo singleton; 12.19 - 12.20 public void clearCache() { 12.21 cache.clear(); 12.22 }
13.1 --- a/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Thu Feb 24 15:16:13 2011 -0800 13.2 +++ b/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Thu Feb 24 18:05:10 2011 -0800 13.3 @@ -164,9 +164,7 @@ 13.4 13.5 fsInfo = FSInfo.instance(context); 13.6 13.7 - // retain check for system property for compatibility 13.8 - useZipFileIndex = options.isUnset("useJavaUtilZip") 13.9 - && System.getProperty("useJavaUtilZip") == null; 13.10 + useZipFileIndex = options.isSet("useOptimizedZip"); 13.11 if (useZipFileIndex) 13.12 zipFileIndexCache = ZipFileIndexCache.getSharedInstance(); 13.13 13.14 @@ -499,8 +497,7 @@ 13.15 13.16 if (!useZipFileIndex) { 13.17 zdir = new ZipFile(zipFileName); 13.18 - } 13.19 - else { 13.20 + } else { 13.21 usePreindexedCache = options.isSet("usezipindex"); 13.22 preindexCacheLocation = options.get("java.io.tmpdir"); 13.23 String optCacheLoc = options.get("cachezipindexdir");
14.1 --- a/src/share/classes/com/sun/tools/javac/file/Paths.java Thu Feb 24 15:16:13 2011 -0800 14.2 +++ b/src/share/classes/com/sun/tools/javac/file/Paths.java Thu Feb 24 18:05:10 2011 -0800 14.3 @@ -247,10 +247,16 @@ 14.4 public Path() { super(); } 14.5 14.6 public Path addDirectories(String dirs, boolean warn) { 14.7 - if (dirs != null) 14.8 - for (File dir : getPathEntries(dirs)) 14.9 - addDirectory(dir, warn); 14.10 - return this; 14.11 + boolean prev = expandJarClassPaths; 14.12 + expandJarClassPaths = true; 14.13 + try { 14.14 + if (dirs != null) 14.15 + for (File dir : getPathEntries(dirs)) 14.16 + addDirectory(dir, warn); 14.17 + return this; 14.18 + } finally { 14.19 + expandJarClassPaths = prev; 14.20 + } 14.21 } 14.22 14.23 public Path addDirectories(String dirs) {
15.1 --- a/src/share/classes/com/sun/tools/javac/parser/Scanner.java Thu Feb 24 15:16:13 2011 -0800 15.2 +++ b/src/share/classes/com/sun/tools/javac/parser/Scanner.java Thu Feb 24 18:05:10 2011 -0800 15.3 @@ -282,12 +282,6 @@ 15.4 sbuf[sp++] = ch; 15.5 } 15.6 15.7 - /** For debugging purposes: print character. 15.8 - */ 15.9 - private void dch() { 15.10 - System.err.print(ch); System.out.flush(); 15.11 - } 15.12 - 15.13 /** Read next character in character or string literal and copy into sbuf. 15.14 */ 15.15 private void scanLitChar() {
16.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Feb 24 15:16:13 2011 -0800 16.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Feb 24 18:05:10 2011 -0800 16.3 @@ -55,6 +55,7 @@ 16.4 import com.sun.tools.javac.api.JavacTrees; 16.5 import com.sun.tools.javac.code.*; 16.6 import com.sun.tools.javac.code.Symbol.*; 16.7 +import com.sun.tools.javac.file.FSInfo; 16.8 import com.sun.tools.javac.file.JavacFileManager; 16.9 import com.sun.tools.javac.jvm.*; 16.10 import com.sun.tools.javac.main.JavaCompiler; 16.11 @@ -1069,6 +1070,10 @@ 16.12 if (tl != null) 16.13 next.put(TaskListener.class, tl); 16.14 16.15 + FSInfo fsInfo = context.get(FSInfo.class); 16.16 + if (fsInfo != null) 16.17 + next.put(FSInfo.class, fsInfo); 16.18 + 16.19 JavaFileManager jfm = context.get(JavaFileManager.class); 16.20 Assert.checkNonNull(jfm); 16.21 next.put(JavaFileManager.class, jfm);
17.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Feb 24 15:16:13 2011 -0800 17.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Feb 24 18:05:10 2011 -0800 17.3 @@ -800,6 +800,11 @@ 17.4 compiler.err.unreported.exception.default.constructor=\ 17.5 unreported exception {0} in default constructor 17.6 17.7 +# 0: type, 1: name 17.8 +compiler.err.unreported.exception.implicit.close=\ 17.9 + unreported exception {0}; must be caught or declared to be thrown\n\ 17.10 + exception thrown from implicit call to close() on resource variable ''{1}'' 17.11 + 17.12 compiler.err.unsupported.cross.fp.lit=\ 17.13 hexadecimal floating-point literals are not supported on this VM 17.14 17.15 @@ -1579,6 +1584,10 @@ 17.16 compiler.misc.diamond=\ 17.17 {0}<> 17.18 17.19 +# 0: type 17.20 +compiler.misc.diamond.non.generic=\ 17.21 + cannot use ''<>'' with non-generic class {0} 17.22 + 17.23 # 0: list of type, 1: message segment 17.24 compiler.misc.diamond.invalid.arg=\ 17.25 type argument {0} inferred for {1} is not allowed in this context
18.1 --- a/test/tools/javac/4241573/T4241573.java Thu Feb 24 15:16:13 2011 -0800 18.2 +++ b/test/tools/javac/4241573/T4241573.java Thu Feb 24 18:05:10 2011 -0800 18.3 @@ -1,5 +1,5 @@ 18.4 /* 18.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 18.6 + * Copyright (c) 2009, 2011 Oracle and/or its affiliates. All rights reserved. 18.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 18.8 * 18.9 * This code is free software; you can redistribute it and/or modify it 18.10 @@ -123,7 +123,7 @@ 18.11 if (!dir.mkdirs()) 18.12 throw new Exception("cannot create directories " + dir); 18.13 for (String e: entries) { 18.14 - writeFile(new File(dir, getPathForEntry(e)), getBodyForEntry(e)); 18.15 + writeFile(new File(dir, getPathForDirEntry(e)), getBodyForEntry(e)); 18.16 } 18.17 return dir; 18.18 } 18.19 @@ -134,7 +134,7 @@ 18.20 try { 18.21 JarOutputStream jos = new JarOutputStream(out); 18.22 for (String e: entries) { 18.23 - jos.putNextEntry(new JarEntry(getPathForEntry(e))); 18.24 + jos.putNextEntry(new JarEntry(getPathForZipEntry(e))); 18.25 jos.write(getBodyForEntry(e).getBytes()); 18.26 } 18.27 jos.close(); 18.28 @@ -144,11 +144,16 @@ 18.29 return jar; 18.30 } 18.31 18.32 - /** Return the path for an entry given to createDir or createJar. */ 18.33 - String getPathForEntry(String e) { 18.34 + /** Return the path for an entry given to createDir */ 18.35 + String getPathForDirEntry(String e) { 18.36 return e.replace(".", File.separator) + ".java"; 18.37 } 18.38 18.39 + /** Return the path for an entry given to createJar. */ 18.40 + String getPathForZipEntry(String e) { 18.41 + return e.replace(".", "/") + ".java"; 18.42 + } 18.43 + 18.44 /** Return the body text for an entry given to createDir or createJar. */ 18.45 String getBodyForEntry(String e) { 18.46 int sep = e.lastIndexOf(".");
19.1 --- a/test/tools/javac/4917091/Test255.java Thu Feb 24 15:16:13 2011 -0800 19.2 +++ b/test/tools/javac/4917091/Test255.java Thu Feb 24 18:05:10 2011 -0800 19.3 @@ -1,5 +1,5 @@ 19.4 /* 19.5 - * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. 19.6 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 19.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 19.8 * 19.9 * This code is free software; you can redistribute it and/or modify it 19.10 @@ -16,9 +16,9 @@ 19.11 * 2 along with this work; if not, write to the Free Software Foundation, 19.12 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19.13 * 19.14 - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 19.15 - * CA 95054 USA or visit www.sun.com if you need additional information or 19.16 - * have any questions. 19.17 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19.18 + * or visit www.oracle.com if you need additional information or have any 19.19 + * questions. 19.20 */ 19.21 19.22 /*
20.1 --- a/test/tools/javac/4917091/Test256a.java Thu Feb 24 15:16:13 2011 -0800 20.2 +++ b/test/tools/javac/4917091/Test256a.java Thu Feb 24 18:05:10 2011 -0800 20.3 @@ -1,5 +1,5 @@ 20.4 /* 20.5 - * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. 20.6 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 20.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.8 * 20.9 * This code is free software; you can redistribute it and/or modify it 20.10 @@ -16,9 +16,9 @@ 20.11 * 2 along with this work; if not, write to the Free Software Foundation, 20.12 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20.13 * 20.14 - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 20.15 - * CA 95054 USA or visit www.sun.com if you need additional information or 20.16 - * have any questions. 20.17 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20.18 + * or visit www.oracle.com if you need additional information or have any 20.19 + * questions. 20.20 */ 20.21 20.22 /*
21.1 --- a/test/tools/javac/4917091/Test256b.java Thu Feb 24 15:16:13 2011 -0800 21.2 +++ b/test/tools/javac/4917091/Test256b.java Thu Feb 24 18:05:10 2011 -0800 21.3 @@ -1,5 +1,5 @@ 21.4 /* 21.5 - * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. 21.6 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 21.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 21.8 * 21.9 * This code is free software; you can redistribute it and/or modify it 21.10 @@ -16,9 +16,9 @@ 21.11 * 2 along with this work; if not, write to the Free Software Foundation, 21.12 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21.13 * 21.14 - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 21.15 - * CA 95054 USA or visit www.sun.com if you need additional information or 21.16 - * have any questions. 21.17 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21.18 + * or visit www.oracle.com if you need additional information or have any 21.19 + * questions. 21.20 */ 21.21 21.22 /*
22.1 --- a/test/tools/javac/6508981/TestInferBinaryName.java Thu Feb 24 15:16:13 2011 -0800 22.2 +++ b/test/tools/javac/6508981/TestInferBinaryName.java Thu Feb 24 18:05:10 2011 -0800 22.3 @@ -1,5 +1,5 @@ 22.4 /* 22.5 - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. 22.6 + * Copyright (c) 2008, 2011 Oracle and/or its affiliates. All rights reserved. 22.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 22.8 * 22.9 * This code is free software; you can redistribute it and/or modify it 22.10 @@ -138,12 +138,11 @@ 22.11 boolean zipFileIndexKind) 22.12 throws IOException { 22.13 Context ctx = new Context(); 22.14 + Options options = Options.instance(ctx); 22.15 // uugh, ugly back door, should be cleaned up, someday 22.16 if (zipFileIndexKind == USE_ZIP_FILE_INDEX) 22.17 - System.clearProperty("useJavaUtilZip"); 22.18 - else 22.19 - System.setProperty("useJavaUtilZip", "true"); 22.20 - Options options = Options.instance(ctx); 22.21 + options.put("useOptimizedZip", "true"); 22.22 + 22.23 if (symFileKind == IGNORE_SYMBOL_FILE) 22.24 options.put("ignore.symbol.file", "true"); 22.25 JavacFileManager fm = new JavacFileManager(ctx, false, null);
23.1 --- a/test/tools/javac/Paths/Class-Path.sh Thu Feb 24 15:16:13 2011 -0800 23.2 +++ b/test/tools/javac/Paths/Class-Path.sh Thu Feb 24 18:05:10 2011 -0800 23.3 @@ -1,7 +1,7 @@ 23.4 #!/bin/sh 23.5 23.6 # 23.7 -# Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. 23.8 +# Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. 23.9 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 23.10 # 23.11 # This code is free software; you can redistribute it and/or modify it 23.12 @@ -24,7 +24,7 @@ 23.13 # 23.14 23.15 23.16 -# @test @(#)Class-Path.sh 1.3 03/10/31 23.17 +# @test 23.18 # @bug 4212732 23.19 # @summary Test handling of the Class-Path attribute in jar file manifests 23.20 # @author Martin Buchholz 23.21 @@ -184,8 +184,8 @@ 23.22 # 23.23 Success "$jar" cfe "Hello.jar" "Hello" Bye.class 23.24 23.25 -# Jar creation and update when there is no manifest and inputfiles 23.26 -specified 23.27 +# Jar creation and update when there is no manifest and inputfiles 23.28 +# specified 23.29 Failure "$jar" cvf "A.jar" 23.30 Failure "$jar" uvf "A.jar" 23.31
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/test/tools/javac/Paths/Class-Path2.sh Thu Feb 24 18:05:10 2011 -0800 24.3 @@ -0,0 +1,111 @@ 24.4 +#!/bin/sh 24.5 +# 24.6 +# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 24.7 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 24.8 +# 24.9 +# This code is free software; you can redistribute it and/or modify it 24.10 +# under the terms of the GNU General Public License version 2 only, as 24.11 +# published by the Free Software Foundation. 24.12 +# 24.13 +# This code is distributed in the hope that it will be useful, but WITHOUT 24.14 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24.15 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 24.16 +# version 2 for more details (a copy is included in the LICENSE file that 24.17 +# accompanied this code). 24.18 +# 24.19 +# You should have received a copy of the GNU General Public License version 24.20 +# 2 along with this work; if not, write to the Free Software Foundation, 24.21 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24.22 +# 24.23 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 24.24 +# or visit www.oracle.com if you need additional information or have any 24.25 +# questions. 24.26 +# 24.27 + 24.28 +# @test 24.29 +# @bug 4212732 6485027 24.30 +# @summary Test handling of the Class-Path attribute in jar file manifests 24.31 +# @author Martin Buchholz 24.32 +# 24.33 +# @run shell Class-Path2.sh 24.34 + 24.35 +# To run this test manually, simply do ./Class-Path2.sh 24.36 + 24.37 +. ${TESTSRC-.}/Util.sh 24.38 + 24.39 +set -u 24.40 + 24.41 +Cleanup() { 24.42 + Sys rm -rf pkg Main.java Main.class Main.jar jars 24.43 + Sys rm -rf MANIFEST.MF A.jar B.zip 24.44 +} 24.45 + 24.46 +Cleanup 24.47 +Sys mkdir pkg 24.48 + 24.49 +#---------------------------------------------------------------- 24.50 +# Create mutually referential jar files 24.51 +#---------------------------------------------------------------- 24.52 +cat >pkg/A.java <<EOF 24.53 +package pkg; 24.54 +import pkg.B; 24.55 +public class A { 24.56 + public static int f() { return B.g(); } 24.57 + public static int g() { return 0; } 24.58 +} 24.59 +EOF 24.60 + 24.61 +cat >pkg/B.java <<EOF 24.62 +package pkg; 24.63 +import pkg.A; 24.64 +public class B { 24.65 + public static int f() { return A.g(); } 24.66 + public static int g() { return 0; } 24.67 +} 24.68 +EOF 24.69 + 24.70 +Sys "$javac" pkg/A.java pkg/B.java 24.71 + 24.72 +MkManifestWithClassPath "./sub/B.zip" 24.73 +Sys "$jar" cmf MANIFEST.MF A.jar pkg/A.class 24.74 + 24.75 +MkManifestWithClassPath "../A.jar" 24.76 +Sys "$jar" cmf MANIFEST.MF B.zip pkg/B.class 24.77 + 24.78 +cat >Main.java <<EOF 24.79 +import pkg.*; 24.80 +public class Main { 24.81 + public static void main(String []a) { System.exit(A.f() + B.f()); } 24.82 +} 24.83 +EOF 24.84 + 24.85 +Sys rm -rf pkg 24.86 + 24.87 +Sys mkdir jars 24.88 +Sys mkdir jars/sub/ 24.89 +Sys mv A.jar jars/. 24.90 +Sys mv B.zip jars/sub/. 24.91 + 24.92 +# 24.93 +# Test 1: Compiling 24.94 +# 24.95 + 24.96 +Success "$javac" ${TESTTOOLVMOPTS} -cp "jars/A.jar" Main.java 24.97 +Success "$java" ${TESTVMOPTS} -cp "jars/A.jar${PS}." Main 24.98 + 24.99 +Success "$javac" ${TESTTOOLVMOPTS} -cp "jars/sub/B.zip" Main.java 24.100 +Success "$java" ${TESTVMOPTS} -cp "jars/sub/B.zip${PS}." Main 24.101 + 24.102 +# 24.103 +# Test 2: Use of extension directories is incorrect 24.104 +# 24.105 + 24.106 +Success "$javac" ${TESTTOOLVMOPTS} -extdirs jars -cp None Main.java 24.107 +Success "$java" ${TESTVMOPTS} -Djava.ext.dirs="jars" -cp . Main 24.108 + 24.109 +Success "$javac" ${TESTTOOLVMOPTS} -extdirs jars/sub -cp None Main.java 24.110 +Success "$java" ${TESTVMOPTS} -Djava.ext.dirs="jars/sub" -cp . Main 24.111 + 24.112 +Cleanup 24.113 + 24.114 +Bottom Line
25.1 --- a/test/tools/javac/Paths/Diagnostics.sh Thu Feb 24 15:16:13 2011 -0800 25.2 +++ b/test/tools/javac/Paths/Diagnostics.sh Thu Feb 24 18:05:10 2011 -0800 25.3 @@ -1,7 +1,7 @@ 25.4 #!/bin/sh 25.5 25.6 # 25.7 -# Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved. 25.8 +# Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. 25.9 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 25.10 # 25.11 # This code is free software; you can redistribute it and/or modify it 25.12 @@ -182,12 +182,12 @@ 25.13 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -Xbootclasspath/p:classesRefRef.jar Main.java 25.14 25.15 #---------------------------------------------------------------- 25.16 -# Class-Path attribute ignored in extdirs or endorseddirs 25.17 +# Class-Path attribute followed in extdirs or endorseddirs 25.18 #---------------------------------------------------------------- 25.19 Sys mkdir jars 25.20 Sys cp -p classesRefRef.jar jars/. 25.21 -No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -extdirs jars Main.java 25.22 -No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -endorseddirs jars Main.java 25.23 + Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -extdirs jars Main.java 25.24 + Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -endorseddirs jars Main.java 25.25 25.26 #---------------------------------------------------------------- 25.27 # Bad Jar file in extdirs and endorseddirs should not be ignored
26.1 --- a/test/tools/javac/TryWithResources/ResourceInterface.out Thu Feb 24 15:16:13 2011 -0800 26.2 +++ b/test/tools/javac/TryWithResources/ResourceInterface.out Thu Feb 24 18:05:10 2011 -0800 26.3 @@ -1,2 +1,2 @@ 26.4 -ResourceInterface.java:38:34: compiler.err.unreported.exception.need.to.catch.or.throw: ResourceInterface.E1 26.5 +ResourceInterface.java:38:13: compiler.err.unreported.exception.implicit.close: ResourceInterface.E1, r2 26.6 1 error
27.1 --- a/test/tools/javac/TryWithResources/TwrFlow.out Thu Feb 24 15:16:13 2011 -0800 27.2 +++ b/test/tools/javac/TryWithResources/TwrFlow.out Thu Feb 24 18:05:10 2011 -0800 27.3 @@ -1,3 +1,3 @@ 27.4 TwrFlow.java:14:11: compiler.err.except.never.thrown.in.try: java.io.IOException 27.5 -TwrFlow.java:12:46: compiler.err.unreported.exception.need.to.catch.or.throw: CustomCloseException 27.6 +TwrFlow.java:12:13: compiler.err.unreported.exception.implicit.close: CustomCloseException, twrFlow 27.7 2 errors
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 28.2 +++ b/test/tools/javac/TryWithResources/TwrNullTests.java Thu Feb 24 18:05:10 2011 -0800 28.3 @@ -0,0 +1,72 @@ 28.4 +/* 28.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 28.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 28.7 + * 28.8 + * This code is free software; you can redistribute it and/or modify it 28.9 + * under the terms of the GNU General Public License version 2 only, as 28.10 + * published by the Free Software Foundation. 28.11 + * 28.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 28.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 28.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28.15 + * version 2 for more details (a copy is included in the LICENSE file that 28.16 + * accompanied this code). 28.17 + * 28.18 + * You should have received a copy of the GNU General Public License version 28.19 + * 2 along with this work; if not, write to the Free Software Foundation, 28.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 28.21 + * 28.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 28.23 + * or visit www.oracle.com if you need additional information or have any 28.24 + * questions. 28.25 + */ 28.26 + 28.27 +/* 28.28 + * @test 28.29 + * @bug 7020047 28.30 + * @summary Test null handling of try-with-resources statement 28.31 + */ 28.32 + 28.33 +public class TwrNullTests { 28.34 + /* 28.35 + * Each try-with-resources statement generates two calls to the 28.36 + * close method for each resource: one for when there is a primary 28.37 + * exception present and the second for when a primary exception 28.38 + * is absent. The null handling of both cases needs to be 28.39 + * checked. 28.40 + */ 28.41 + public static void main(String... args) { 28.42 + testNormalCompletion(); 28.43 + testNoSuppression(); 28.44 + } 28.45 + 28.46 + /* 28.47 + * Verify empty try-with-resources on a null resource completes 28.48 + * normally; no NPE from the generated close call. 28.49 + */ 28.50 + private static void testNormalCompletion() { 28.51 + try(AutoCloseable resource = null) { 28.52 + return; // Nothing to see here, move along. 28.53 + } catch (Exception e) { 28.54 + throw new AssertionError("Should not be reached", e); 28.55 + } 28.56 + } 28.57 + 28.58 + /* 28.59 + * Verify that a NPE on a null resource is <em>not</em> added as a 28.60 + * suppressed exception to an exception from try block. 28.61 + */ 28.62 + private static void testNoSuppression() { 28.63 + try(AutoCloseable resource = null) { 28.64 + throw new java.io.IOException(); 28.65 + } catch(java.io.IOException ioe) { 28.66 + Throwable[] suppressed = ioe.getSuppressed(); 28.67 + if (suppressed.length != 0) { 28.68 + throw new AssertionError("Non-empty suppressed exceptions", 28.69 + ioe); 28.70 + } 28.71 + } catch (Exception e) { 28.72 + throw new AssertionError("Should not be reached", e); 28.73 + } 28.74 + } 28.75 +}
29.1 --- a/test/tools/javac/api/6411310/Test.java Thu Feb 24 15:16:13 2011 -0800 29.2 +++ b/test/tools/javac/api/6411310/Test.java Thu Feb 24 18:05:10 2011 -0800 29.3 @@ -1,5 +1,5 @@ 29.4 /* 29.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 29.6 + * Copyright (c) 2009, 2011 Oracle and/or its affiliates. All rights reserved. 29.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 29.8 * 29.9 * This code is free software; you can redistribute it and/or modify it 29.10 @@ -59,12 +59,12 @@ 29.11 test(createFileManager(), createDir("dir", entries), "p", entries); 29.12 test(createFileManager(), createDir("a b/dir", entries), "p", entries); 29.13 29.14 - for (boolean useJavaUtilZip: new boolean[] { false, true }) { 29.15 - test(createFileManager(useJavaUtilZip), createJar("jar", entries), "p", entries); 29.16 - test(createFileManager(useJavaUtilZip), createJar("jar jar", entries), "p", entries); 29.17 + for (boolean useOptimizedZip: new boolean[] { false, true }) { 29.18 + test(createFileManager(useOptimizedZip), createJar("jar", entries), "p", entries); 29.19 + test(createFileManager(useOptimizedZip), createJar("jar jar", entries), "p", entries); 29.20 29.21 for (boolean useSymbolFile: new boolean[] { false, true }) { 29.22 - test(createFileManager(useJavaUtilZip, useSymbolFile), rt_jar, "java.lang.ref", null); 29.23 + test(createFileManager(useOptimizedZip, useSymbolFile), rt_jar, "java.lang.ref", null); 29.24 } 29.25 } 29.26 29.27 @@ -145,42 +145,22 @@ 29.28 return createFileManager(false, false); 29.29 } 29.30 29.31 - JavacFileManager createFileManager(boolean useJavaUtilZip) { 29.32 - return createFileManager(useJavaUtilZip, false); 29.33 + JavacFileManager createFileManager(boolean useOptimizedZip) { 29.34 + return createFileManager(useOptimizedZip, false); 29.35 } 29.36 29.37 - JavacFileManager createFileManager(boolean useJavaUtilZip, boolean useSymbolFile) { 29.38 - // javac should really not be using system properties like this 29.39 - // -- it should really be using (hidden) options -- but until then 29.40 - // take care to leave system properties as we find them, so as not 29.41 - // to adversely affect other tests that might follow. 29.42 - String prev = System.getProperty("useJavaUtilZip"); 29.43 - boolean resetProperties = false; 29.44 - try { 29.45 - if (useJavaUtilZip) { 29.46 - System.setProperty("useJavaUtilZip", "true"); 29.47 - resetProperties = true; 29.48 - } else if (System.getProperty("useJavaUtilZip") != null) { 29.49 - System.getProperties().remove("useJavaUtilZip"); 29.50 - resetProperties = true; 29.51 + JavacFileManager createFileManager(boolean useOptimizedZip, boolean useSymbolFile) { 29.52 + Context c = new Context(); 29.53 + Options options = Options.instance(c); 29.54 + 29.55 + if (useOptimizedZip) { 29.56 + options.put("useOptimizedZip", "true"); 29.57 } 29.58 29.59 - Context c = new Context(); 29.60 if (!useSymbolFile) { 29.61 - Options options = Options.instance(c); 29.62 options.put("ignore.symbol.file", "true"); 29.63 } 29.64 - 29.65 return new JavacFileManager(c, false, null); 29.66 - } finally { 29.67 - if (resetProperties) { 29.68 - if (prev == null) { 29.69 - System.getProperties().remove("useJavaUtilZip"); 29.70 - } else { 29.71 - System.setProperty("useJavaUtilZip", prev); 29.72 - } 29.73 - } 29.74 - } 29.75 } 29.76 29.77 File createDir(String name, String... entries) throws Exception {
30.1 --- a/test/tools/javac/api/T6838467.java Thu Feb 24 15:16:13 2011 -0800 30.2 +++ b/test/tools/javac/api/T6838467.java Thu Feb 24 18:05:10 2011 -0800 30.3 @@ -1,5 +1,5 @@ 30.4 /* 30.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 30.6 + * Copyright (c) 2009, 2011 Oracle and/or its affiliates. All rights reserved. 30.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 30.8 * 30.9 * This code is free software; you can redistribute it and/or modify it 30.10 @@ -32,7 +32,9 @@ 30.11 import java.util.zip.*; 30.12 import javax.tools.*; 30.13 import com.sun.tools.javac.file.JavacFileManager; 30.14 +import com.sun.tools.javac.main.OptionName; 30.15 import com.sun.tools.javac.util.Context; 30.16 +import com.sun.tools.javac.util.Options; 30.17 30.18 public class T6838467 { 30.19 boolean fileSystemIsCaseSignificant = !new File("a").equals(new File("A")); 30.20 @@ -176,33 +178,13 @@ 30.21 return fm; 30.22 } 30.23 30.24 - JavacFileManager createFileManager(boolean useJavaUtilZip) { 30.25 - // javac should really not be using system properties like this 30.26 - // -- it should really be using (hidden) options -- but until then 30.27 - // take care to leave system properties as we find them, so as not 30.28 - // to adversely affect other tests that might follow. 30.29 - String prev = System.getProperty("useJavaUtilZip"); 30.30 - boolean resetProperties = false; 30.31 - try { 30.32 - if (useJavaUtilZip) { 30.33 - System.setProperty("useJavaUtilZip", "true"); 30.34 - resetProperties = true; 30.35 - } else if (System.getProperty("useJavaUtilZip") != null) { 30.36 - System.getProperties().remove("useJavaUtilZip"); 30.37 - resetProperties = true; 30.38 - } 30.39 - 30.40 - Context c = new Context(); 30.41 - return new JavacFileManager(c, false, null); 30.42 - } finally { 30.43 - if (resetProperties) { 30.44 - if (prev == null) { 30.45 - System.getProperties().remove("useJavaUtilZip"); 30.46 - } else { 30.47 - System.setProperty("useJavaUtilZip", prev); 30.48 - } 30.49 - } 30.50 + JavacFileManager createFileManager(boolean useOptimedZipIndex) { 30.51 + Context ctx = new Context(); 30.52 + if (useOptimedZipIndex) { 30.53 + Options options = Options.instance(ctx); 30.54 + options.put("useOptimizedZip", "true"); 30.55 } 30.56 + return new JavacFileManager(ctx, false, null); 30.57 } 30.58 30.59 // create a directory containing a given set of paths
31.1 --- a/test/tools/javac/api/T6877206.java Thu Feb 24 15:16:13 2011 -0800 31.2 +++ b/test/tools/javac/api/T6877206.java Thu Feb 24 18:05:10 2011 -0800 31.3 @@ -1,5 +1,5 @@ 31.4 /* 31.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. 31.6 + * Copyright (c) 2009, 2011 Oracle and/or its affiliates. All rights reserved. 31.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 31.8 * 31.9 * This code is free software; you can redistribute it and/or modify it 31.10 @@ -63,12 +63,12 @@ 31.11 test(createFileManager(), createDir("dir", entries), "p", entries.length); 31.12 test(createFileManager(), createDir("a b/dir", entries), "p", entries.length); 31.13 31.14 - for (boolean useJavaUtilZip: new boolean[] { false, true }) { 31.15 - test(createFileManager(useJavaUtilZip), createJar("jar", entries), "p", entries.length); 31.16 - test(createFileManager(useJavaUtilZip), createJar("jar jar", entries), "p", entries.length); 31.17 + for (boolean useOptimizedZip: new boolean[] { false, true }) { 31.18 + test(createFileManager(useOptimizedZip), createJar("jar", entries), "p", entries.length); 31.19 + test(createFileManager(useOptimizedZip), createJar("jar jar", entries), "p", entries.length); 31.20 31.21 for (boolean useSymbolFile: new boolean[] { false, true }) { 31.22 - test(createFileManager(useJavaUtilZip, useSymbolFile), rt_jar, "java.lang.ref", -1); 31.23 + test(createFileManager(useOptimizedZip, useSymbolFile), rt_jar, "java.lang.ref", -1); 31.24 } 31.25 } 31.26 31.27 @@ -161,42 +161,20 @@ 31.28 return createFileManager(false, false); 31.29 } 31.30 31.31 - JavacFileManager createFileManager(boolean useJavaUtilZip) { 31.32 - return createFileManager(useJavaUtilZip, false); 31.33 + JavacFileManager createFileManager(boolean useOptimizedZip) { 31.34 + return createFileManager(useOptimizedZip, false); 31.35 } 31.36 31.37 - JavacFileManager createFileManager(boolean useJavaUtilZip, boolean useSymbolFile) { 31.38 - // javac should really not be using system properties like this 31.39 - // -- it should really be using (hidden) options -- but until then 31.40 - // take care to leave system properties as we find them, so as not 31.41 - // to adversely affect other tests that might follow. 31.42 - String prev = System.getProperty("useJavaUtilZip"); 31.43 - boolean resetProperties = false; 31.44 - try { 31.45 - if (useJavaUtilZip) { 31.46 - System.setProperty("useJavaUtilZip", "true"); 31.47 - resetProperties = true; 31.48 - } else if (System.getProperty("useJavaUtilZip") != null) { 31.49 - System.getProperties().remove("useJavaUtilZip"); 31.50 - resetProperties = true; 31.51 - } 31.52 - 31.53 - Context c = new Context(); 31.54 - if (!useSymbolFile) { 31.55 - Options options = Options.instance(c); 31.56 - options.put("ignore.symbol.file", "true"); 31.57 - } 31.58 - 31.59 - return new JavacFileManager(c, false, null); 31.60 - } finally { 31.61 - if (resetProperties) { 31.62 - if (prev == null) { 31.63 - System.getProperties().remove("useJavaUtilZip"); 31.64 - } else { 31.65 - System.setProperty("useJavaUtilZip", prev); 31.66 - } 31.67 - } 31.68 + JavacFileManager createFileManager(boolean useOptimizedZip, boolean useSymbolFile) { 31.69 + Context ctx = new Context(); 31.70 + Options options = Options.instance(ctx); 31.71 + if (useOptimizedZip) { 31.72 + options.put("useOptimizedZip", "true"); 31.73 } 31.74 + if (!useSymbolFile) { 31.75 + options.put("ignore.symbol.file", "true"); 31.76 + } 31.77 + return new JavacFileManager(ctx, false, null); 31.78 } 31.79 31.80 File createDir(String name, String... entries) throws Exception {
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 32.2 +++ b/test/tools/javac/diags/examples/DiamondNonGeneric.java Thu Feb 24 18:05:10 2011 -0800 32.3 @@ -0,0 +1,29 @@ 32.4 +/* 32.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 32.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 32.7 + * 32.8 + * This code is free software; you can redistribute it and/or modify it 32.9 + * under the terms of the GNU General Public License version 2 only, as 32.10 + * published by the Free Software Foundation. 32.11 + * 32.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 32.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 32.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 32.15 + * version 2 for more details (a copy is included in the LICENSE file that 32.16 + * accompanied this code). 32.17 + * 32.18 + * You should have received a copy of the GNU General Public License version 32.19 + * 2 along with this work; if not, write to the Free Software Foundation, 32.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 32.21 + * 32.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 32.23 + * or visit www.oracle.com if you need additional information or have any 32.24 + * questions. 32.25 + */ 32.26 + 32.27 +// key: compiler.misc.diamond.non.generic 32.28 +// key: compiler.err.cant.apply.diamond.1 32.29 + 32.30 +class DiamondNonGeneric { 32.31 + String s = new String<>("foo"); 32.32 +}
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/test/tools/javac/diags/examples/UnreportedExceptionImplicitClose.java Thu Feb 24 18:05:10 2011 -0800 33.3 @@ -0,0 +1,33 @@ 33.4 +/* 33.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 33.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 33.7 + * 33.8 + * This code is free software; you can redistribute it and/or modify it 33.9 + * under the terms of the GNU General Public License version 2 only, as 33.10 + * published by the Free Software Foundation. 33.11 + * 33.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 33.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 33.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 33.15 + * version 2 for more details (a copy is included in the LICENSE file that 33.16 + * accompanied this code). 33.17 + * 33.18 + * You should have received a copy of the GNU General Public License version 33.19 + * 2 along with this work; if not, write to the Free Software Foundation, 33.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 33.21 + * 33.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 33.23 + * or visit www.oracle.com if you need additional information or have any 33.24 + * questions. 33.25 + */ 33.26 + 33.27 +// key: compiler.err.unreported.exception.implicit.close 33.28 + 33.29 +class UnreportedExceptionImplicitClose { 33.30 + static class MyCloseable implements AutoCloseable { 33.31 + public void close() throws Exception { } 33.32 + } 33.33 + void test() { 33.34 + try (MyCloseable x = new MyCloseable()) { } 33.35 + } 33.36 +}
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 34.2 +++ b/test/tools/javac/file/T7018098.java Thu Feb 24 18:05:10 2011 -0800 34.3 @@ -0,0 +1,121 @@ 34.4 +/* 34.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 34.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 34.7 + * 34.8 + * This code is free software; you can redistribute it and/or modify it 34.9 + * under the terms of the GNU General Public License version 2 only, as 34.10 + * published by the Free Software Foundation. 34.11 + * 34.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 34.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 34.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 34.15 + * version 2 for more details (a copy is included in the LICENSE file that 34.16 + * accompanied this code). 34.17 + * 34.18 + * You should have received a copy of the GNU General Public License version 34.19 + * 2 along with this work; if not, write to the Free Software Foundation, 34.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 34.21 + * 34.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 34.23 + * or visit www.oracle.com if you need additional information or have any 34.24 + * questions. 34.25 + */ 34.26 + 34.27 +/** 34.28 + * @test 34.29 + * @bug 7018098 34.30 + * @summary CacheFSInfo persists too long 34.31 + * @library ../lib 34.32 + * @build JavacTestingAbstractProcessor T7018098 34.33 + * @run main T7018098 34.34 + */ 34.35 + 34.36 +import java.io.*; 34.37 +import java.util.*; 34.38 +import javax.annotation.processing.RoundEnvironment; 34.39 +import javax.annotation.processing.SupportedOptions; 34.40 +import javax.lang.model.element.TypeElement; 34.41 +import javax.tools.Diagnostic; 34.42 + 34.43 +import com.sun.tools.javac.file.FSInfo; 34.44 +import com.sun.tools.javac.processing.JavacProcessingEnvironment; 34.45 +import com.sun.tools.javac.util.Context; 34.46 + 34.47 +@SupportedOptions("expect") 34.48 +public class T7018098 extends JavacTestingAbstractProcessor { 34.49 + public static void main(String... args) throws Exception { 34.50 + new T7018098().run(); 34.51 + } 34.52 + 34.53 + static File testDir = new File("T7018098.dir"); 34.54 + 34.55 + void run() throws Exception { 34.56 + String myName = T7018098.class.getSimpleName(); 34.57 + File testSrc = new File(System.getProperty("test.src")); 34.58 + File file = new File(testSrc, myName + ".java"); 34.59 + 34.60 + _assert(!testDir.exists()); 34.61 + 34.62 + compile( 34.63 + "-proc:only", 34.64 + "-processor", myName, 34.65 + "-Aexpect=false", 34.66 + file.getPath()); 34.67 + 34.68 + testDir.mkdirs(); 34.69 + _assert(testDir.exists()); 34.70 + 34.71 + compile( 34.72 + "-proc:only", 34.73 + "-processor", myName, 34.74 + "-Aexpect=true", 34.75 + file.getPath()); 34.76 + } 34.77 + 34.78 + void _assert(boolean cond) { 34.79 + if (!cond) 34.80 + throw new AssertionError(); 34.81 + } 34.82 + 34.83 + void compile(String... args) throws Exception { 34.84 + StringWriter sw = new StringWriter(); 34.85 + PrintWriter pw = new PrintWriter(sw); 34.86 + int rc = com.sun.tools.javac.Main.compile(args, pw); 34.87 + pw.close(); 34.88 + String out = sw.toString(); 34.89 + if (!out.isEmpty()) 34.90 + System.err.println(out); 34.91 + if (rc != 0) 34.92 + throw new Exception("compilation failed unexpectedly: rc=" + rc); 34.93 + } 34.94 + 34.95 + //--------------- 34.96 + 34.97 + @Override 34.98 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 34.99 + Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); 34.100 + FSInfo fsInfo = context.get(FSInfo.class); 34.101 + 34.102 + round++; 34.103 + if (round == 1) { 34.104 + boolean expect = Boolean.valueOf(options.get("expect")); 34.105 + checkEqual("cache result", fsInfo.isDirectory(testDir), expect); 34.106 + initialFSInfo = fsInfo; 34.107 + } else { 34.108 + checkEqual("fsInfo", fsInfo, initialFSInfo); 34.109 + } 34.110 + 34.111 + return true; 34.112 + } 34.113 + 34.114 + <T> void checkEqual(String label, T actual, T expected) { 34.115 + if (actual != expected) 34.116 + messager.printMessage(Diagnostic.Kind.ERROR, 34.117 + "Unexpected value for " + label 34.118 + + "; expected: " + expected 34.119 + + "; found: " + actual); 34.120 + } 34.121 + 34.122 + int round = 0; 34.123 + FSInfo initialFSInfo; 34.124 +}
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/test/tools/javac/generics/diamond/neg/Neg12.java Thu Feb 24 18:05:10 2011 -0800 35.3 @@ -0,0 +1,15 @@ 35.4 +/* 35.5 + * @test /nodynamiccopyright/ 35.6 + * @bug 7020043 35.7 + * 35.8 + * @summary Project Coin: diamond allowed on non-generic type 35.9 + * @author Rémi Forax 35.10 + * @compile/fail/ref=Neg12.out Neg12.java -XDrawDiagnostics 35.11 + * 35.12 + */ 35.13 + 35.14 +class DiamondRaw { 35.15 + public static void main(String[] args) { 35.16 + String s = new String<>("foo"); 35.17 + } 35.18 +}
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 36.2 +++ b/test/tools/javac/generics/diamond/neg/Neg12.out Thu Feb 24 18:05:10 2011 -0800 36.3 @@ -0,0 +1,2 @@ 36.4 +Neg12.java:13:27: compiler.err.cant.apply.diamond.1: java.lang.String, (compiler.misc.diamond.non.generic: java.lang.String) 36.5 +1 error
37.1 --- a/test/tools/javac/nio/compileTest/CompileTest.java Thu Feb 24 15:16:13 2011 -0800 37.2 +++ b/test/tools/javac/nio/compileTest/CompileTest.java Thu Feb 24 18:05:10 2011 -0800 37.3 @@ -1,5 +1,5 @@ 37.4 /* 37.5 - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 37.6 + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. 37.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 37.8 * 37.9 * This code is free software; you can redistribute it and/or modify it 37.10 @@ -25,7 +25,7 @@ 37.11 * @test 37.12 * @bug 6906175 6915476 6915497 7006564 37.13 * @summary Path-based JavaFileManager 37.14 - * @compile -g HelloPathWorld.java 37.15 + * @compile -g CompileTest.java HelloPathWorld.java 37.16 * @run main CompileTest 37.17 */ 37.18
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/test/tools/javac/processing/model/element/TestTypeParameter.java Thu Feb 24 18:05:10 2011 -0800 38.3 @@ -0,0 +1,129 @@ 38.4 +/* 38.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 38.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 38.7 + * 38.8 + * This code is free software; you can redistribute it and/or modify it 38.9 + * under the terms of the GNU General Public License version 2 only, as 38.10 + * published by the Free Software Foundation. 38.11 + * 38.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 38.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 38.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 38.15 + * version 2 for more details (a copy is included in the LICENSE file that 38.16 + * accompanied this code). 38.17 + * 38.18 + * You should have received a copy of the GNU General Public License version 38.19 + * 2 along with this work; if not, write to the Free Software Foundation, 38.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 38.21 + * 38.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 38.23 + * or visit www.oracle.com if you need additional information or have any 38.24 + * questions. 38.25 + */ 38.26 + 38.27 +/* 38.28 + * @test 38.29 + * @bug 6505047 38.30 + * @summary javax.lang.model.element.Element.getEnclosingElement() doesn't return null for type parameter 38.31 + * @library ../../../lib 38.32 + * @build JavacTestingAbstractProcessor TestTypeParameter 38.33 + * @compile -processor TestTypeParameter -proc:only TestTypeParameter.java 38.34 + */ 38.35 + 38.36 +import java.util.*; 38.37 +import javax.annotation.processing.*; 38.38 +import javax.lang.model.element.*; 38.39 +import javax.lang.model.util.*; 38.40 +import javax.tools.*; 38.41 + 38.42 +public class TestTypeParameter<T> extends JavacTestingAbstractProcessor { 38.43 + int round = 0; 38.44 + 38.45 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 38.46 + if (++round == 1) { 38.47 + int found = (new Scanner()).scan(roundEnv.getRootElements(), null); 38.48 + if (found == expect) { 38.49 + note("generic elements found and verified: " + found); 38.50 + } else { 38.51 + error("unexpected number of results: expected " + expect 38.52 + + ", found " + found); 38.53 + } 38.54 + 38.55 + } 38.56 + return true; 38.57 + } 38.58 + 38.59 + class Scanner extends ElementScanner7<Integer,Void> { 38.60 + @Override 38.61 + public Integer visitExecutable(ExecutableElement e, Void p) { 38.62 + super.visitExecutable(e, p); 38.63 + found += check(e, e.getTypeParameters()); 38.64 + return found; 38.65 + } 38.66 + 38.67 + @Override 38.68 + public Integer visitType(TypeElement e, Void p) { 38.69 + super.visitType(e, p); 38.70 + found += check(e, e.getTypeParameters()); 38.71 + return found; 38.72 + } 38.73 + 38.74 + int found; 38.75 + } 38.76 + 38.77 + /** 38.78 + * Check if type parameters, if any, have expected owner. 38.79 + * Return 1 if typarams not empty and all have expected owner, else return 0. 38.80 + */ 38.81 + int check(Element e, List<? extends TypeParameterElement> typarams) { 38.82 + note("checking " + e, e); 38.83 + if (typarams.isEmpty()) { 38.84 + note("no type parameters found", e); 38.85 + return 0; 38.86 + } 38.87 + for (TypeParameterElement tpe: typarams) { 38.88 + note("checking type parameter " + tpe, tpe); 38.89 + if (tpe.getEnclosingElement() != e) { 38.90 + error("unexpected owner; expected: " + e 38.91 + + ", found " + tpe.getEnclosingElement(), 38.92 + tpe); 38.93 + return 0; 38.94 + } 38.95 + if (tpe.getEnclosingElement() != tpe.getGenericElement()) { 38.96 + error("unexpected generic element; expected: " + tpe.getGenericElement() 38.97 + + ", found " + tpe.getEnclosingElement(), 38.98 + tpe); 38.99 + return 0; 38.100 + } 38.101 + } 38.102 + note("verified " + e, e); 38.103 + return 1; 38.104 + } 38.105 + 38.106 + void note(String msg) { 38.107 + messager.printMessage(Diagnostic.Kind.NOTE, msg); 38.108 + } 38.109 + 38.110 + void note(String msg, Element e) { 38.111 + messager.printMessage(Diagnostic.Kind.NOTE, msg, e); 38.112 + } 38.113 + 38.114 + void error(String msg, Element e) { 38.115 + messager.printMessage(Diagnostic.Kind.ERROR, msg, e); 38.116 + } 38.117 + 38.118 + void error(String msg) { 38.119 + messager.printMessage(Diagnostic.Kind.ERROR, msg); 38.120 + } 38.121 + 38.122 + // additional generic elements to test 38.123 + <X> X m(X x) { return x; } 38.124 + 38.125 + interface Intf<X> { X m() ; } 38.126 + 38.127 + class Class<X> { 38.128 + <Y> Class() { } 38.129 + } 38.130 + 38.131 + final int expect = 5; // top level class, plus preceding examples 38.132 +}
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/test/tools/javac/scope/7017664/CompoundScopeTest.java Thu Feb 24 18:05:10 2011 -0800 39.3 @@ -0,0 +1,212 @@ 39.4 +/* 39.5 + * Copyright (c) 2011, 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 + * @test 39.29 + * @bug 7017664 39.30 + * @summary Basher for CompoundScopes 39.31 + */ 39.32 + 39.33 +import java.util.Random; 39.34 +import java.util.Map; 39.35 +import java.util.HashMap; 39.36 +import com.sun.tools.javac.util.*; 39.37 +import com.sun.tools.javac.code.*; 39.38 +import com.sun.tools.javac.code.Scope.*; 39.39 +import com.sun.tools.javac.code.Symbol.*; 39.40 +import com.sun.tools.javac.file.JavacFileManager; 39.41 + 39.42 +public class CompoundScopeTest { 39.43 + public static void main(String... args) throws Exception { 39.44 + new CompoundScopeTest().run(args); 39.45 + } 39.46 + 39.47 + static final int MAX_SYMBOLS_COUNT = 20; 39.48 + static final int PASSES = 10; 39.49 + 39.50 + void run(String... args) throws Exception { 39.51 + int count = PASSES; 39.52 + 39.53 + for (int i = 0; i < args.length; i++) { 39.54 + String arg = args[i]; 39.55 + if (arg.equals("-seed") && (i + 1 < args.length)) 39.56 + seed = Long.parseLong(args[++i]); 39.57 + else if(arg.equals("-tests") && (i + 1 < args.length)) 39.58 + count = Integer.parseInt(args[++i]); 39.59 + else 39.60 + throw new Exception("unknown arg: " + arg); 39.61 + } 39.62 + 39.63 + rgen = new Random(seed); 39.64 + 39.65 + for (int i = 0; i < count; i++) { 39.66 + Test t = new Test(); 39.67 + t.run(); 39.68 + } 39.69 + 39.70 + if (errors > 0) 39.71 + throw new Exception(errors + " errors found"); 39.72 + } 39.73 + 39.74 + /** 39.75 + * Write a message to stderr. 39.76 + */ 39.77 + void log(String msg) { 39.78 + System.err.println(msg); 39.79 + } 39.80 + 39.81 + /** 39.82 + * Write an error message to stderr. 39.83 + */ 39.84 + void error(String msg) { 39.85 + System.err.println("Error: " + msg); 39.86 + errors++; 39.87 + } 39.88 + 39.89 + Random rgen; 39.90 + long seed = 0; 39.91 + 39.92 + int errors; 39.93 + 39.94 + /** Class to encapsulate a test run. */ 39.95 + class Test { 39.96 + 39.97 + List<Symbol> elems = List.nil(); 39.98 + Map<Name, List<Symbol>> shadowedMap = new HashMap<Name, List<Symbol>>(); 39.99 + 39.100 + /** Run the test. */ 39.101 + void run() throws Exception { 39.102 + log ("starting test"); 39.103 + setup(); 39.104 + Scope[] scopes = { createScope(rgen.nextInt(MAX_SYMBOLS_COUNT)), 39.105 + createScope(rgen.nextInt(MAX_SYMBOLS_COUNT)), 39.106 + createScope(rgen.nextInt(MAX_SYMBOLS_COUNT)) }; 39.107 + boolean[][] scopeNesting = { {false, true, false, true}, 39.108 + {false, true, true, true}, 39.109 + {false, false, true, true} }; 39.110 + /** 39.111 + * We want to generate (and check) the following compound scopes: 39.112 + * C1 = C(S1, S2, S3) 39.113 + * C2 = C((S1, S2), S3) 39.114 + * C3 = C(S1, (S2, S3)) 39.115 + * C3 = C(C(S1, S2, S3)) 39.116 + */ 39.117 + for (int i = 0 ; i < 4 ; i ++) { 39.118 + CompoundScope root = new CompoundScope(symtab.noSymbol); 39.119 + CompoundScope sub = new CompoundScope(symtab.noSymbol); 39.120 + boolean subAdded = false; 39.121 + for (int sc = 0 ; sc < 3 ; sc ++) { 39.122 + if (scopeNesting[sc][i]) { 39.123 + sub.addSubScope(scopes[sc]); 39.124 + if (!subAdded) { 39.125 + root.addSubScope(sub); 39.126 + subAdded = true; 39.127 + } 39.128 + } else { 39.129 + root.addSubScope(scopes[sc]); 39.130 + } 39.131 + } 39.132 + log("testing scope: " + root); 39.133 + checkElems(root); 39.134 + checkShadowed(root); 39.135 + } 39.136 + } 39.137 + 39.138 + /** 39.139 + * Create a scope containing a given number of synthetic symbols 39.140 + */ 39.141 + Scope createScope(int nelems) { 39.142 + Scope s = new Scope(symtab.noSymbol); 39.143 + for (int i = 0 ; i < nelems ; i++) { 39.144 + Symbol sym = new TypeSymbol(0, names.fromString("s" + i), null, null); 39.145 + s.enter(sym); 39.146 + elems = elems.prepend(sym); 39.147 + List<Symbol> shadowed = shadowedMap.get(sym.name); 39.148 + if (shadowed == null) { 39.149 + shadowed = List.nil(); 39.150 + } 39.151 + shadowedMap.put(sym.name, shadowed.prepend(sym)); 39.152 + } 39.153 + return s; 39.154 + } 39.155 + 39.156 + /** 39.157 + * Setup compiler context 39.158 + */ 39.159 + void setup() { 39.160 + log ("setup"); 39.161 + context = new Context(); 39.162 + JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab 39.163 + names = Names.instance(context); // Name.Table impls tied to an instance of Names 39.164 + symtab = Symtab.instance(context); 39.165 + } 39.166 + 39.167 + /** 39.168 + * Check that CompoundScope.getElements() correctly visits all symbols 39.169 + * in all subscopes (in the correct order) 39.170 + */ 39.171 + void checkElems(CompoundScope cs) { 39.172 + List<Symbol> allSymbols = elems; 39.173 + int count = 0; 39.174 + for (Symbol s : cs.getElements()) { 39.175 + checkSameSymbols(s, allSymbols.head); 39.176 + allSymbols = allSymbols.tail; 39.177 + count++; 39.178 + } 39.179 + if (count != elems.size()) { 39.180 + error("CompoundScope.getElements() did not returned enough symbols"); 39.181 + } 39.182 + } 39.183 + 39.184 + /** 39.185 + * Check that CompoundScope.getElements() correctly visits all symbols 39.186 + * with a given name in all subscopes (in the correct order) 39.187 + */ 39.188 + void checkShadowed(CompoundScope cs) { 39.189 + for (Map.Entry<Name, List<Symbol>> shadowedEntry : shadowedMap.entrySet()) { 39.190 + int count = 0; 39.191 + List<Symbol> shadowed = shadowedEntry.getValue(); 39.192 + Name name = shadowedEntry.getKey(); 39.193 + for (Symbol s : cs.getElementsByName(name)) { 39.194 + checkSameSymbols(s, shadowed.head); 39.195 + shadowed = shadowed.tail; 39.196 + count++; 39.197 + } 39.198 + if (count != shadowedEntry.getValue().size()) { 39.199 + error("CompoundScope.lookup() did not returned enough symbols for name " + name); 39.200 + } 39.201 + } 39.202 + } 39.203 + 39.204 + void checkSameSymbols(Symbol found, Symbol req) { 39.205 + if (found != req) { 39.206 + error("Symbol mismatch - found : " + found + ":" + found.hashCode() + "\n" + 39.207 + " required : " + req + ":" + req.hashCode()); 39.208 + } 39.209 + } 39.210 + 39.211 + Context context; 39.212 + Symtab symtab; 39.213 + Names names; 39.214 + } 39.215 +}
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 40.2 +++ b/test/tools/javac/scope/7017664/ImplementationCacheTest.java Thu Feb 24 18:05:10 2011 -0800 40.3 @@ -0,0 +1,129 @@ 40.4 +/* 40.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 40.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 40.7 + * 40.8 + * This code is free software; you can redistribute it and/or modify it 40.9 + * under the terms of the GNU General Public License version 2 only, as 40.10 + * published by the Free Software Foundation. 40.11 + * 40.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 40.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 40.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 40.15 + * version 2 for more details (a copy is included in the LICENSE file that 40.16 + * accompanied this code). 40.17 + * 40.18 + * You should have received a copy of the GNU General Public License version 40.19 + * 2 along with this work; if not, write to the Free Software Foundation, 40.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 40.21 + * 40.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 40.23 + * or visit www.oracle.com if you need additional information or have any 40.24 + * questions. 40.25 + */ 40.26 + 40.27 +/* 40.28 + * @test 40.29 + * @bug 7017664 40.30 + * @summary Basher for CompoundScopes 40.31 + */ 40.32 + 40.33 +import com.sun.source.util.JavacTask; 40.34 +import com.sun.tools.javac.code.Symbol; 40.35 +import com.sun.tools.javac.code.Types; 40.36 +import com.sun.tools.javac.file.JavacFileManager; 40.37 +import com.sun.tools.javac.util.Context; 40.38 + 40.39 +import com.sun.tools.javac.code.Symbol.*; 40.40 + 40.41 +import java.io.IOException; 40.42 +import java.net.URI; 40.43 +import java.util.Arrays; 40.44 +import java.util.List; 40.45 +import javax.lang.model.element.Element; 40.46 +import javax.tools.JavaCompiler; 40.47 +import javax.tools.JavaFileObject; 40.48 +import javax.tools.SimpleJavaFileObject; 40.49 +import javax.tools.ToolProvider; 40.50 + 40.51 +import static javax.tools.JavaFileObject.Kind; 40.52 + 40.53 +public class ImplementationCacheTest { 40.54 + 40.55 + static class SourceFile extends SimpleJavaFileObject { 40.56 + 40.57 + final String source = "interface I { void m(); }\n" + 40.58 + "class A implements I { public void m() {} }\n" + 40.59 + "class B extends A { }\n"; 40.60 + 40.61 + public SourceFile() { 40.62 + super(URI.create("test.java"), Kind.SOURCE); 40.63 + } 40.64 + 40.65 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 40.66 + return source; 40.67 + } 40.68 + } 40.69 + 40.70 + public static void main(String[] args) throws IOException { 40.71 + List<? extends JavaFileObject> files = Arrays.asList(new SourceFile()); 40.72 + JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); 40.73 + JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, files); 40.74 + Context ctx = new Context(); 40.75 + JavacFileManager.preRegister(ctx); 40.76 + checkImplementationCache(ct.analyze(), Types.instance(ctx)); 40.77 + } 40.78 + 40.79 + static void checkImplementationCache(Iterable<? extends Element> elements, Types types) { 40.80 + if (types == null) { 40.81 + throw new AssertionError("problems initializing Types"); 40.82 + } 40.83 + 40.84 + Symbol a = null; 40.85 + Symbol b = null; 40.86 + Symbol i = null; 40.87 + 40.88 + for (Element e : elements) { 40.89 + if (e.getSimpleName().contentEquals("A")) { 40.90 + a = (Symbol)e; 40.91 + } else if (e.getSimpleName().contentEquals("B")) { 40.92 + b = (Symbol)e; 40.93 + } else if (e.getSimpleName().contentEquals("I")) { 40.94 + i = (Symbol)e; 40.95 + } 40.96 + } 40.97 + 40.98 + if (a == null || b == null || i == null) { 40.99 + throw new AssertionError("missing class"); 40.100 + } 40.101 + 40.102 + MethodSymbol I_m = null; 40.103 + 40.104 + for (Symbol sym : i.members().getElements()) { 40.105 + if (sym.name.contentEquals("m")) { 40.106 + I_m = (MethodSymbol)sym; 40.107 + } 40.108 + } 40.109 + 40.110 + if (I_m == null) { 40.111 + throw new AssertionError("missing method m() in scope of interface I"); 40.112 + } 40.113 + 40.114 + Symbol impl = I_m.implementation((TypeSymbol)b, types, true); 40.115 + 40.116 + if (impl == null || impl.owner != a) { 40.117 + throw new AssertionError("wrong implementation for m() in B"); 40.118 + } 40.119 + 40.120 + b.members().enter(I_m.clone(b)); 40.121 + 40.122 + Symbol newImpl = I_m.implementation((TypeSymbol)b, types, true); 40.123 + 40.124 + if (newImpl == impl) { 40.125 + throw new AssertionError("stale implementation for m() in B"); 40.126 + } 40.127 + 40.128 + if (newImpl == null || newImpl.owner != b) { 40.129 + throw new AssertionError("wrong implementation for m() in B"); 40.130 + } 40.131 + } 40.132 +}