Thu, 11 Jun 2015 10:11:18 -0700
Merge
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Scope.java Wed Jun 10 14:22:04 2015 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Scope.java Thu Jun 11 10:11:18 2015 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -241,12 +241,16 @@ 1.11 listeners = listeners.prepend(sl); 1.12 } 1.13 1.14 - /** Remove symbol from this scope. Used when an inner class 1.15 - * attribute tells us that the class isn't a package member. 1.16 + /** Remove symbol from this scope. 1.17 */ 1.18 - public void remove(Symbol sym) { 1.19 + public void remove(final Symbol sym) { 1.20 Assert.check(shared == 0); 1.21 - Entry e = lookup(sym.name); 1.22 + Entry e = lookup(sym.name, new Filter<Symbol>() { 1.23 + @Override 1.24 + public boolean accepts(Symbol candidate) { 1.25 + return candidate == sym; 1.26 + } 1.27 + }); 1.28 if (e.scope == null) return; 1.29 1.30 // remove e from table and shadowed list;
2.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Wed Jun 10 14:22:04 2015 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Thu Jun 11 10:11:18 2015 -0700 2.3 @@ -2694,74 +2694,98 @@ 2.4 // </editor-fold> 2.5 2.6 // <editor-fold defaultstate="collapsed" desc="compute transitive closure of all members in given site"> 2.7 - class MembersClosureCache extends SimpleVisitor<CompoundScope, Boolean> { 2.8 - 2.9 - private WeakHashMap<TypeSymbol, Entry> _map = 2.10 - new WeakHashMap<TypeSymbol, Entry>(); 2.11 - 2.12 - class Entry { 2.13 - final boolean skipInterfaces; 2.14 - final CompoundScope compoundScope; 2.15 - 2.16 - public Entry(boolean skipInterfaces, CompoundScope compoundScope) { 2.17 - this.skipInterfaces = skipInterfaces; 2.18 - this.compoundScope = compoundScope; 2.19 + class MembersClosureCache extends SimpleVisitor<Scope.CompoundScope, Void> { 2.20 + 2.21 + private Map<TypeSymbol, CompoundScope> _map = new HashMap<>(); 2.22 + 2.23 + Set<TypeSymbol> seenTypes = new HashSet<>(); 2.24 + 2.25 + class MembersScope extends CompoundScope { 2.26 + 2.27 + CompoundScope scope; 2.28 + 2.29 + public MembersScope(CompoundScope scope) { 2.30 + super(scope.owner); 2.31 + this.scope = scope; 2.32 } 2.33 2.34 - boolean matches(boolean skipInterfaces) { 2.35 - return this.skipInterfaces == skipInterfaces; 2.36 + Filter<Symbol> combine(final Filter<Symbol> sf) { 2.37 + return new Filter<Symbol>() { 2.38 + @Override 2.39 + public boolean accepts(Symbol s) { 2.40 + return !s.owner.isInterface() && (sf == null || sf.accepts(s)); 2.41 + } 2.42 + }; 2.43 + } 2.44 + 2.45 + @Override 2.46 + public Iterable<Symbol> getElements(Filter<Symbol> sf) { 2.47 + return scope.getElements(combine(sf)); 2.48 + } 2.49 + 2.50 + @Override 2.51 + public Iterable<Symbol> getElementsByName(Name name, Filter<Symbol> sf) { 2.52 + return scope.getElementsByName(name, combine(sf)); 2.53 + } 2.54 + 2.55 + @Override 2.56 + public int getMark() { 2.57 + return scope.getMark(); 2.58 } 2.59 } 2.60 2.61 - List<TypeSymbol> seenTypes = List.nil(); 2.62 + CompoundScope nilScope; 2.63 2.64 /** members closure visitor methods **/ 2.65 2.66 - public CompoundScope visitType(Type t, Boolean skipInterface) { 2.67 - return null; 2.68 + public CompoundScope visitType(Type t, Void _unused) { 2.69 + if (nilScope == null) { 2.70 + nilScope = new CompoundScope(syms.noSymbol); 2.71 + } 2.72 + return nilScope; 2.73 } 2.74 2.75 @Override 2.76 - public CompoundScope visitClassType(ClassType t, Boolean skipInterface) { 2.77 - if (seenTypes.contains(t.tsym)) { 2.78 + public CompoundScope visitClassType(ClassType t, Void _unused) { 2.79 + if (!seenTypes.add(t.tsym)) { 2.80 //this is possible when an interface is implemented in multiple 2.81 - //superclasses, or when a classs hierarchy is circular - in such 2.82 + //superclasses, or when a class hierarchy is circular - in such 2.83 //cases we don't need to recurse (empty scope is returned) 2.84 return new CompoundScope(t.tsym); 2.85 } 2.86 try { 2.87 - seenTypes = seenTypes.prepend(t.tsym); 2.88 + seenTypes.add(t.tsym); 2.89 ClassSymbol csym = (ClassSymbol)t.tsym; 2.90 - Entry e = _map.get(csym); 2.91 - if (e == null || !e.matches(skipInterface)) { 2.92 - CompoundScope membersClosure = new CompoundScope(csym); 2.93 - if (!skipInterface) { 2.94 - for (Type i : interfaces(t)) { 2.95 - membersClosure.addSubScope(visit(i, skipInterface)); 2.96 - } 2.97 + CompoundScope membersClosure = _map.get(csym); 2.98 + if (membersClosure == null) { 2.99 + membersClosure = new CompoundScope(csym); 2.100 + for (Type i : interfaces(t)) { 2.101 + membersClosure.addSubScope(visit(i, null)); 2.102 } 2.103 - membersClosure.addSubScope(visit(supertype(t), skipInterface)); 2.104 + membersClosure.addSubScope(visit(supertype(t), null)); 2.105 membersClosure.addSubScope(csym.members()); 2.106 - e = new Entry(skipInterface, membersClosure); 2.107 - _map.put(csym, e); 2.108 + _map.put(csym, membersClosure); 2.109 } 2.110 - return e.compoundScope; 2.111 + return membersClosure; 2.112 } 2.113 finally { 2.114 - seenTypes = seenTypes.tail; 2.115 + seenTypes.remove(t.tsym); 2.116 } 2.117 } 2.118 2.119 @Override 2.120 - public CompoundScope visitTypeVar(TypeVar t, Boolean skipInterface) { 2.121 - return visit(t.getUpperBound(), skipInterface); 2.122 + public CompoundScope visitTypeVar(TypeVar t, Void _unused) { 2.123 + return visit(t.getUpperBound(), null); 2.124 } 2.125 } 2.126 2.127 private MembersClosureCache membersCache = new MembersClosureCache(); 2.128 2.129 public CompoundScope membersClosure(Type site, boolean skipInterface) { 2.130 - return membersCache.visit(site, skipInterface); 2.131 + CompoundScope cs = membersCache.visit(site, null); 2.132 + if (cs == null) 2.133 + Assert.error("type " + site); 2.134 + return skipInterface ? membersCache.new MembersScope(cs) : cs; 2.135 } 2.136 // </editor-fold> 2.137
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Jun 10 14:22:04 2015 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Jun 11 10:11:18 2015 -0700 3.3 @@ -825,9 +825,18 @@ 3.4 } 3.5 3.6 public void visitClassDef(JCClassDecl tree) { 3.7 - // Local classes have not been entered yet, so we need to do it now: 3.8 - if ((env.info.scope.owner.kind & (VAR | MTH)) != 0) 3.9 + // Local and anonymous classes have not been entered yet, so we need to 3.10 + // do it now. 3.11 + if ((env.info.scope.owner.kind & (VAR | MTH)) != 0) { 3.12 enter.classEnter(tree, env); 3.13 + } else { 3.14 + // If this class declaration is part of a class level annotation, 3.15 + // as in @MyAnno(new Object() {}) class MyClass {}, enter it in 3.16 + // order to simplify later steps and allow for sensible error 3.17 + // messages. 3.18 + if (env.tree.hasTag(NEWCLASS) && TreeInfo.isInAnnotation(env, tree)) 3.19 + enter.classEnter(tree, env); 3.20 + } 3.21 3.22 ClassSymbol c = tree.sym; 3.23 if (c == null) {
4.1 --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Wed Jun 10 14:22:04 2015 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Thu Jun 11 10:11:18 2015 -0700 4.3 @@ -1256,6 +1256,9 @@ 4.4 return isSimpleReceiver(((JCAnnotatedType)rec).underlyingType); 4.5 case APPLY: 4.6 return true; 4.7 + case NEWCLASS: 4.8 + JCNewClass nc = (JCNewClass) rec; 4.9 + return nc.encl == null && nc.def == null && !TreeInfo.isDiamond(nc); 4.10 default: 4.11 return false; 4.12 } 4.13 @@ -1310,17 +1313,24 @@ 4.14 Type site; 4.15 4.16 if (rec != null) { 4.17 - if (rec.hasTag(APPLY)) { 4.18 - Symbol recSym = quicklyResolveMethod(env, (JCMethodInvocation) rec); 4.19 - if (recSym == null) 4.20 - return null; 4.21 - Symbol resolvedReturnType = 4.22 - analyzeCandidateMethods(recSym, syms.errSymbol, returnSymbolAnalyzer); 4.23 - if (resolvedReturnType == null) 4.24 - return null; 4.25 - site = resolvedReturnType.type; 4.26 - } else { 4.27 - site = attribSpeculative(rec, env, attr.unknownTypeExprInfo).type; 4.28 + switch (rec.getTag()) { 4.29 + case APPLY: 4.30 + Symbol recSym = quicklyResolveMethod(env, (JCMethodInvocation) rec); 4.31 + if (recSym == null) 4.32 + return null; 4.33 + Symbol resolvedReturnType = 4.34 + analyzeCandidateMethods(recSym, syms.errSymbol, returnSymbolAnalyzer); 4.35 + if (resolvedReturnType == null) 4.36 + return null; 4.37 + site = resolvedReturnType.type; 4.38 + break; 4.39 + case NEWCLASS: 4.40 + JCNewClass nc = (JCNewClass) rec; 4.41 + site = attribSpeculative(nc.clazz, env, attr.unknownTypeExprInfo).type; 4.42 + break; 4.43 + default: 4.44 + site = attribSpeculative(rec, env, attr.unknownTypeExprInfo).type; 4.45 + break; 4.46 } 4.47 } else { 4.48 site = env.enclClass.sym.type;
5.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed Jun 10 14:22:04 2015 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java Thu Jun 11 10:11:18 2015 -0700 5.3 @@ -271,7 +271,7 @@ 5.4 * the one of its outer environment 5.5 */ 5.6 protected static boolean isStatic(Env<AttrContext> env) { 5.7 - return env.info.staticLevel > env.outer.info.staticLevel; 5.8 + return env.outer != null && env.info.staticLevel > env.outer.info.staticLevel; 5.9 } 5.10 5.11 /** An environment is an "initializer" if it is a constructor or
6.1 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Wed Jun 10 14:22:04 2015 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Thu Jun 11 10:11:18 2015 -0700 6.3 @@ -28,6 +28,7 @@ 6.4 6.5 6.6 import com.sun.source.tree.Tree; 6.7 +import com.sun.source.util.TreePath; 6.8 import com.sun.tools.javac.code.*; 6.9 import com.sun.tools.javac.comp.AttrContext; 6.10 import com.sun.tools.javac.comp.Env; 6.11 @@ -351,6 +352,18 @@ 6.12 return (lit.typetag == BOT); 6.13 } 6.14 6.15 + /** Return true iff this tree is a child of some annotation. */ 6.16 + public static boolean isInAnnotation(Env<?> env, JCTree tree) { 6.17 + TreePath tp = TreePath.getPath(env.toplevel, tree); 6.18 + if (tp != null) { 6.19 + for (Tree t : tp) { 6.20 + if (t.getKind() == Tree.Kind.ANNOTATION) 6.21 + return true; 6.22 + } 6.23 + } 6.24 + return false; 6.25 + } 6.26 + 6.27 public static String getCommentText(Env<?> env, JCTree tree) { 6.28 DocCommentTable docComments = (tree.hasTag(JCTree.Tag.TOPLEVEL)) 6.29 ? ((JCCompilationUnit) tree).docComments
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/tools/javac/annotations/neg/AnonSubclass.java Thu Jun 11 10:11:18 2015 -0700 7.3 @@ -0,0 +1,13 @@ 7.4 +/* 7.5 + * @test /nodynamiccopyright/ 7.6 + * @bug 8028389 7.7 + * @summary javac should output a proper error message when given something 7.8 + * like new Object(){} as annotation argument. 7.9 + * 7.10 + * @compile/fail/ref=AnonSubclass.out -XDrawDiagnostics AnonSubclass.java 7.11 + */ 7.12 + 7.13 +@AnonSubclass(new Object(){}) 7.14 +@interface AnonSubclass { 7.15 + String value(); 7.16 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/test/tools/javac/annotations/neg/AnonSubclass.out Thu Jun 11 10:11:18 2015 -0700 8.3 @@ -0,0 +1,2 @@ 8.4 +AnonSubclass.java:10:15: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.anonymous.class: java.lang.Object, java.lang.String) 8.5 +1 error
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/test/tools/javac/annotations/neg/pkg/AnonSubclassOnPkg.java Thu Jun 11 10:11:18 2015 -0700 9.3 @@ -0,0 +1,28 @@ 9.4 +/* 9.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.7 + * 9.8 + * This code is free software; you can redistribute it and/or modify it 9.9 + * under the terms of the GNU General Public License version 2 only, as 9.10 + * published by the Free Software Foundation. 9.11 + * 9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 9.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 9.15 + * version 2 for more details (a copy is included in the LICENSE file that 9.16 + * accompanied this code). 9.17 + * 9.18 + * You should have received a copy of the GNU General Public License version 9.19 + * 2 along with this work; if not, write to the Free Software Foundation, 9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 9.21 + * 9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 9.23 + * or visit www.oracle.com if you need additional information or have any 9.24 + * questions. 9.25 + */ 9.26 + 9.27 +package pkg; 9.28 + 9.29 +@interface AnonSubclassOnPkg { 9.30 + String value(); 9.31 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/test/tools/javac/annotations/neg/pkg/package-info.java Thu Jun 11 10:11:18 2015 -0700 10.3 @@ -0,0 +1,12 @@ 10.4 +/* 10.5 + * @test /nodynamiccopyright/ 10.6 + * @bug 8028389 10.7 + * @summary javac should output a proper error message when given something 10.8 + * like new Object(){} as annotation argument. 10.9 + * 10.10 + * @compile AnonSubclassOnPkg.java 10.11 + * @compile/fail/ref=package-info.out -XDrawDiagnostics package-info.java 10.12 + */ 10.13 + 10.14 +@AnonSubclassOnPkg(new Object(){}) 10.15 +package pkg;
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/tools/javac/annotations/neg/pkg/package-info.out Thu Jun 11 10:11:18 2015 -0700 11.3 @@ -0,0 +1,2 @@ 11.4 +package-info.java:11:20: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.anonymous.class: java.lang.Object, java.lang.String) 11.5 +1 error
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/tools/javac/expression/DeeplyChainedNonPolyExpressionTest.java Thu Jun 11 10:11:18 2015 -0700 12.3 @@ -0,0 +1,178 @@ 12.4 +/* 12.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 + * 12.8 + * This code is free software; you can redistribute it and/or modify it 12.9 + * under the terms of the GNU General Public License version 2 only, as 12.10 + * published by the Free Software Foundation. 12.11 + * 12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.15 + * version 2 for more details (a copy is included in the LICENSE file that 12.16 + * accompanied this code). 12.17 + * 12.18 + * You should have received a copy of the GNU General Public License version 12.19 + * 2 along with this work; if not, write to the Free Software Foundation, 12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.21 + * 12.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 12.23 + * or visit www.oracle.com if you need additional information or have any 12.24 + * questions. 12.25 + */ 12.26 + 12.27 +/* 12.28 + * @test 12.29 + * @bug 8079613 12.30 + * @summary Ensure that compiler ascertains a class of patently non-poly expressions as such 12.31 + * @run main/timeout=10 DeeplyChainedNonPolyExpressionTest 12.32 + */ 12.33 + 12.34 +public class DeeplyChainedNonPolyExpressionTest { 12.35 + static class JSO { 12.36 + 12.37 + JSO put(String s, Object y) { 12.38 + return null; 12.39 + } 12.40 + 12.41 + JSO put(java.lang.String x, java.util.Collection<String> y) { 12.42 + return null; 12.43 + } 12.44 + 12.45 + JSO put(java.lang.String x, int y) { 12.46 + return null; 12.47 + } 12.48 + 12.49 + JSO put(java.lang.String x, long y) { 12.50 + return null; 12.51 + } 12.52 + 12.53 + JSO put(java.lang.String x, double y) { 12.54 + return null; 12.55 + } 12.56 + 12.57 + JSO put(java.lang.String x, java.util.Map<String, String> y) { 12.58 + return null; 12.59 + } 12.60 + 12.61 + JSO put(java.lang.String x, boolean y) { 12.62 + return null; 12.63 + } 12.64 + } 12.65 + 12.66 + static class JSA { 12.67 + 12.68 + JSA put(Object o) { 12.69 + return null; 12.70 + } 12.71 + 12.72 + JSA put(int i, Object x) { 12.73 + return null; 12.74 + } 12.75 + 12.76 + JSA put(boolean x) { 12.77 + return null; 12.78 + } 12.79 + 12.80 + JSA put(int x) { 12.81 + return null; 12.82 + } 12.83 + 12.84 + JSA put(int i, int x) { 12.85 + return null; 12.86 + } 12.87 + 12.88 + JSA put(int x, boolean y) { 12.89 + return null; 12.90 + } 12.91 + 12.92 + JSA put(int i, long x) { 12.93 + return null; 12.94 + } 12.95 + 12.96 + JSA put(long x) { 12.97 + return null; 12.98 + } 12.99 + 12.100 + JSA put(java.util.Collection<String> x) { 12.101 + return null; 12.102 + } 12.103 + 12.104 + JSA put(int i, java.util.Collection<String> x) { 12.105 + return null; 12.106 + } 12.107 + 12.108 + JSA put(int i, java.util.Map<String, String> x) { 12.109 + return null; 12.110 + } 12.111 + 12.112 + JSA put(java.util.Map<String, String> x) { 12.113 + return null; 12.114 + } 12.115 + 12.116 + JSA put(int i, double x) { 12.117 + return null; 12.118 + } 12.119 + 12.120 + JSA put(double x) { 12.121 + return null; 12.122 + } 12.123 + } 12.124 + 12.125 + public static void main(String [] args) { 12.126 + } 12.127 + public static void foo() { 12.128 + new JSO() 12.129 + .put("s", new JSA()) 12.130 + .put("s", new JSA()) 12.131 + .put("s", new JSO() 12.132 + .put("s", new JSO() 12.133 + .put("s", new JSA().put("s")) 12.134 + .put("s", new JSA()) 12.135 + .put("s", new JSO() 12.136 + .put("s", new JSO() 12.137 + .put("s", new JSA().put("s").put("s")) 12.138 + .put("s", new JSA()) 12.139 + .put("s", new JSO() 12.140 + .put("s", new JSO() 12.141 + .put("s", new JSA().put("s").put("s").put("s") 12.142 + .put("s").put("s").put("s") 12.143 + .put("s").put("s")) 12.144 + .put("s", new JSA()) 12.145 + .put("s", new JSO() 12.146 + .put("s", new JSO() 12.147 + .put("s", new JSA().put("s")) 12.148 + .put("s", new JSA()) 12.149 + ) 12.150 + ) 12.151 + ) 12.152 + ) 12.153 + ) 12.154 + .put("s", new JSO() 12.155 + .put("s", new JSA().put("s")) 12.156 + .put("s", new JSA()) 12.157 + .put("s", new JSO() 12.158 + .put("s", new JSO() 12.159 + .put("s", new JSA().put("s").put("s")) 12.160 + .put("s", new JSA()) 12.161 + .put("s", new JSO() 12.162 + .put("s", new JSO() 12.163 + .put("s", new JSA().put("s").put("s").put("s") 12.164 + .put("s").put("s").put("s") 12.165 + .put("s").put("s")) 12.166 + .put("s", new JSA()) 12.167 + .put("s", new JSO() 12.168 + .put("s", new JSO() 12.169 + .put("s", new JSA().put("s")) 12.170 + .put("s", new JSA())) 12.171 + ) 12.172 + ) 12.173 + ) 12.174 + ) 12.175 + ) 12.176 + ) 12.177 + ) 12.178 + ) 12.179 + ); 12.180 + } 12.181 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/tools/javac/scope/RemoveSymbolTest.java Thu Jun 11 10:11:18 2015 -0700 13.3 @@ -0,0 +1,77 @@ 13.4 +/* 13.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.7 + * 13.8 + * This code is free software; you can redistribute it and/or modify it 13.9 + * under the terms of the GNU General Public License version 2 only, as 13.10 + * published by the Free Software Foundation. 13.11 + * 13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13.15 + * version 2 for more details (a copy is included in the LICENSE file that 13.16 + * accompanied this code). 13.17 + * 13.18 + * You should have received a copy of the GNU General Public License version 13.19 + * 2 along with this work; if not, write to the Free Software Foundation, 13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 13.21 + * 13.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 13.23 + * or visit www.oracle.com if you need additional information or have any 13.24 + * questions. 13.25 + */ 13.26 + 13.27 +/* 13.28 + * @test 13.29 + * @bug 8080842 13.30 + * @summary Ensure Scope impl can cope with remove() when a field and method share the name. 13.31 + * @run main RemoveSymbolTest 13.32 + */ 13.33 + 13.34 +import java.util.Iterator; 13.35 +import java.util.LinkedList; 13.36 + 13.37 +public class RemoveSymbolTest<W> implements Iterable<W> { 13.38 + static class Widget { 13.39 + private String name; 13.40 + Widget(String s) { name = s; } 13.41 + @Override public String toString() { return name; } 13.42 + } 13.43 + 13.44 + private LinkedList<W> data; 13.45 + // Instantiate an Iterable instance using a Lambda expression. 13.46 + // Causes ClassFormatError if a local variable of type Widget is named after one of the methods. 13.47 + private final Iterable<W> myIterator1 = () -> new Iterator<W>() { 13.48 + private W hasNext = null; 13.49 + private int index = 0; 13.50 + @Override public boolean hasNext() { return index < data.size(); } 13.51 + @Override public W next() { return data.get(index++); } 13.52 + }; 13.53 + 13.54 + // Instantiate an Iterable instance using an anonymous class. 13.55 + // Always works fine regardless of the name of the local variable. 13.56 + private final Iterable<W> myIterator2 = 13.57 + new Iterable<W>() { 13.58 + @Override 13.59 + public Iterator<W> iterator() { 13.60 + return new Iterator<W>() { 13.61 + private W hasNext = null; 13.62 + private int index = 0; 13.63 + @Override public boolean hasNext() { return index < data.size(); } 13.64 + @Override public W next() { return data.get(index++); } 13.65 + }; 13.66 + } 13.67 + }; 13.68 + public RemoveSymbolTest() { data = new LinkedList<>(); } 13.69 + public void add(W e) { data.add(e); } 13.70 + @Override public String toString() { return data.toString(); } 13.71 + @Override public Iterator<W> iterator() { return myIterator1.iterator(); } 13.72 + public static void main(String[] args) { 13.73 + RemoveSymbolTest<Widget> widgets = new RemoveSymbolTest<>(); 13.74 + widgets.add(new Widget("W1")); 13.75 + widgets.add(new Widget("W2")); 13.76 + widgets.add(new Widget("W3")); 13.77 + System.out.println(".foreach() call: "); 13.78 + widgets.forEach(w -> System.out.println(w + " ")); 13.79 + } 13.80 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/tools/javac/scope/RemoveSymbolUnitTest.java Thu Jun 11 10:11:18 2015 -0700 14.3 @@ -0,0 +1,95 @@ 14.4 +/* 14.5 + * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. 14.11 + * 14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.15 + * version 2 for more details (a copy is included in the LICENSE file that 14.16 + * accompanied this code). 14.17 + * 14.18 + * You should have received a copy of the GNU General Public License version 14.19 + * 2 along with this work; if not, write to the Free Software Foundation, 14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.21 + * 14.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.23 + * or visit www.oracle.com if you need additional information or have any 14.24 + * questions. 14.25 + */ 14.26 + 14.27 +/* 14.28 + * @test 14.29 + * @bug 8080842 14.30 + * @summary Ensure Scope impl can cope with remove() when a field and method share the name. 14.31 + */ 14.32 + 14.33 +import com.sun.tools.javac.util.*; 14.34 +import com.sun.tools.javac.code.*; 14.35 +import com.sun.tools.javac.code.Scope.*; 14.36 +import com.sun.tools.javac.code.Symbol.*; 14.37 +import com.sun.tools.javac.file.JavacFileManager; 14.38 + 14.39 +public class RemoveSymbolUnitTest { 14.40 + 14.41 + Context context; 14.42 + Names names; 14.43 + Symtab symtab; 14.44 + 14.45 + public static void main(String... args) throws Exception { 14.46 + new RemoveSymbolUnitTest().run(); 14.47 + } 14.48 + 14.49 + public void run() { 14.50 + context = new Context(); 14.51 + JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab 14.52 + names = Names.instance(context); 14.53 + symtab = Symtab.instance(context); 14.54 + 14.55 + Name hasNext = names.fromString("hasNext"); 14.56 + ClassSymbol clazz = new ClassSymbol(0, 14.57 + names.fromString("X"), 14.58 + Type.noType, 14.59 + symtab.unnamedPackage); 14.60 + 14.61 + VarSymbol v = new VarSymbol(0, hasNext, Type.noType, clazz); 14.62 + MethodSymbol m = new MethodSymbol(0, hasNext, Type.noType, clazz); 14.63 + 14.64 + // Try enter and remove in different shuffled combinations. 14.65 + // working with fresh scope each time. 14.66 + Scope cs = new Scope(clazz); 14.67 + cs.enter(v); 14.68 + cs.enter(m); 14.69 + cs.remove(v); 14.70 + Symbol s = cs.lookup(hasNext).sym; 14.71 + if (s != m) 14.72 + throw new AssertionError("Wrong symbol"); 14.73 + 14.74 + cs = new Scope(clazz); 14.75 + cs.enter(m); 14.76 + cs.enter(v); 14.77 + cs.remove(v); 14.78 + s = cs.lookup(hasNext).sym; 14.79 + if (s != m) 14.80 + throw new AssertionError("Wrong symbol"); 14.81 + 14.82 + cs = new Scope(clazz); 14.83 + cs.enter(v); 14.84 + cs.enter(m); 14.85 + cs.remove(m); 14.86 + s = cs.lookup(hasNext).sym; 14.87 + if (s != v) 14.88 + throw new AssertionError("Wrong symbol"); 14.89 + 14.90 + cs = new Scope(clazz); 14.91 + cs.enter(m); 14.92 + cs.enter(v); 14.93 + cs.remove(m); 14.94 + s = cs.lookup(hasNext).sym; 14.95 + if (s != v) 14.96 + throw new AssertionError("Wrong symbol"); 14.97 + } 14.98 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/tools/javac/types/ScopeListenerTest.java Thu Jun 11 10:11:18 2015 -0700 15.3 @@ -0,0 +1,82 @@ 15.4 +/* 15.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.7 + * 15.8 + * This code is free software; you can redistribute it and/or modify it 15.9 + * under the terms of the GNU General Public License version 2 only, as 15.10 + * published by the Free Software Foundation. 15.11 + * 15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15.15 + * version 2 for more details (a copy is included in the LICENSE file that 15.16 + * accompanied this code). 15.17 + * 15.18 + * You should have received a copy of the GNU General Public License version 15.19 + * 2 along with this work; if not, write to the Free Software Foundation, 15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 15.21 + * 15.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 15.23 + * or visit www.oracle.com if you need additional information or have any 15.24 + * questions. 15.25 + */ 15.26 + 15.27 +/* 15.28 + * @test 15.29 + * @bug 8039262 15.30 + * @summary Ensure that using Types.membersClosure does not increase the number of listeners on the 15.31 + * class's members Scope. 15.32 + */ 15.33 + 15.34 +import com.sun.tools.javac.code.Scope; 15.35 +import com.sun.tools.javac.code.Symbol; 15.36 +import com.sun.tools.javac.code.Symtab; 15.37 +import com.sun.tools.javac.code.Types; 15.38 +import com.sun.tools.javac.file.JavacFileManager; 15.39 +import com.sun.tools.javac.util.Context; 15.40 +import com.sun.tools.javac.util.Names; 15.41 +import java.lang.reflect.Field; 15.42 +import java.util.Collection; 15.43 + 15.44 +public class ScopeListenerTest { 15.45 + 15.46 + public static void main(String[] args) throws Exception { 15.47 + new ScopeListenerTest().run(); 15.48 + } 15.49 + 15.50 + void run() throws Exception { 15.51 + Context context = new Context(); 15.52 + JavacFileManager.preRegister(context); 15.53 + Types types = Types.instance(context); 15.54 + Symtab syms = Symtab.instance(context); 15.55 + Names names = Names.instance(context); 15.56 + types.membersClosure(syms.stringType, true); 15.57 + types.membersClosure(syms.stringType, false); 15.58 + 15.59 + Field listenersField = Scope.class.getDeclaredField("listeners"); 15.60 + 15.61 + listenersField.setAccessible(true); 15.62 + 15.63 + int listenerCount = 15.64 + ((Collection) listenersField.get(syms.stringType.tsym.members())).size(); 15.65 + 15.66 + for (int i = 0; i < 100; i++) { 15.67 + types.membersClosure(syms.stringType, true); 15.68 + types.membersClosure(syms.stringType, false); 15.69 + } 15.70 + 15.71 + int newListenerCount 15.72 + = ((Collection) listenersField.get(syms.stringType.tsym.members())).size(); 15.73 + 15.74 + if (listenerCount != newListenerCount) { 15.75 + throw new AssertionError("Orig listener count: " + listenerCount + 15.76 + "; new listener count: " + newListenerCount); 15.77 + } 15.78 + 15.79 + for (Symbol s : types.membersClosure(syms.stringType, true).getElements()) 15.80 + ; 15.81 + for (Symbol s : types.membersClosure(syms.stringType, false).getElementsByName(names.fromString("substring"))) 15.82 + ; 15.83 + } 15.84 + 15.85 +}