Mon, 03 Oct 2011 18:26:59 -0700
Merge
src/share/classes/com/sun/tools/javac/Launcher.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/javac/Launcher.java Thu Sep 29 18:54:01 2011 -0700 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,73 +0,0 @@ 1.4 -/* 1.5 - * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 - * 1.8 - * This code is free software; you can redistribute it and/or modify it 1.9 - * under the terms of the GNU General Public License version 2 only, as 1.10 - * published by the Free Software Foundation. Oracle designates this 1.11 - * particular file as subject to the "Classpath" exception as provided 1.12 - * by Oracle in the LICENSE file that accompanied this code. 1.13 - * 1.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 - * version 2 for more details (a copy is included in the LICENSE file that 1.18 - * accompanied this code). 1.19 - * 1.20 - * You should have received a copy of the GNU General Public License version 1.21 - * 2 along with this work; if not, write to the Free Software Foundation, 1.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 - * 1.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 - * or visit www.oracle.com if you need additional information or have any 1.26 - * questions. 1.27 - */ 1.28 - 1.29 -package com.sun.tools.javac; 1.30 - 1.31 -import java.io.File; 1.32 -import java.util.prefs.Preferences; 1.33 -import javax.swing.JFileChooser; 1.34 -import javax.tools.JavaCompiler; 1.35 -import javax.tools.ToolProvider; 1.36 - 1.37 - 1.38 -/** 1.39 - * <b>Unsupported</b> entry point for starting javac from an IDE. 1.40 - * 1.41 - * <p><b>Note:</b> this class is not available in the JDK. It is not 1.42 - * compiled by default and will not be in tools.jar. It is designed 1.43 - * to be useful when editing the compiler sources in an IDE (as part 1.44 - * of a <em>project</em>). Simply ensure that this class is added to 1.45 - * the project and make it the main class of the project.</p> 1.46 - * 1.47 - * <p><b>This is NOT part of any supported API. 1.48 - * If you write code that depends on this, you do so at your own 1.49 - * risk. This code and its internal interfaces are subject to change 1.50 - * or deletion without notice.</b></p> 1.51 - * 1.52 - * @author Peter von der Ahé 1.53 - * @since 1.6 1.54 - */ 1.55 -class Launcher { 1.56 - public static void main(String... args) { 1.57 - JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); 1.58 - JFileChooser fileChooser; 1.59 - Preferences prefs = Preferences.userNodeForPackage(Launcher.class); 1.60 - if (args.length > 0) 1.61 - fileChooser = new JFileChooser(args[0]); 1.62 - else { 1.63 - String fileName = prefs.get("recent.file", null); 1.64 - fileChooser = new JFileChooser(); 1.65 - if (fileName != null) { 1.66 - fileChooser = new JFileChooser(); 1.67 - fileChooser.setSelectedFile(new File(fileName)); 1.68 - } 1.69 - } 1.70 - if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { 1.71 - String fileName = fileChooser.getSelectedFile().getPath(); 1.72 - prefs.put("recent.file", fileName); 1.73 - javac.run(System.in, null, null, "-d", "/tmp", fileName); 1.74 - } 1.75 - } 1.76 -}
2.1 --- a/src/share/classes/com/sun/tools/javac/Main.java Thu Sep 29 18:54:01 2011 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/Main.java Mon Oct 03 18:26:59 2011 -0700 2.3 @@ -73,7 +73,7 @@ 2.4 public static int compile(String[] args) { 2.5 com.sun.tools.javac.main.Main compiler = 2.6 new com.sun.tools.javac.main.Main("javac"); 2.7 - return compiler.compile(args); 2.8 + return compiler.compile(args).exitCode; 2.9 } 2.10 2.11 2.12 @@ -91,6 +91,6 @@ 2.13 public static int compile(String[] args, PrintWriter out) { 2.14 com.sun.tools.javac.main.Main compiler = 2.15 new com.sun.tools.javac.main.Main("javac", out); 2.16 - return compiler.compile(args); 2.17 + return compiler.compile(args).exitCode; 2.18 } 2.19 }
3.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Thu Sep 29 18:54:01 2011 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Mon Oct 03 18:26:59 2011 -0700 3.3 @@ -78,7 +78,7 @@ 3.4 private AtomicBoolean used = new AtomicBoolean(); 3.5 private Iterable<? extends Processor> processors; 3.6 3.7 - private Integer result = null; 3.8 + private Main.Result result = null; 3.9 3.10 JavacTaskImpl(Main compilerMain, 3.11 String[] args, 3.12 @@ -131,7 +131,7 @@ 3.13 compilerMain.setAPIMode(true); 3.14 result = compilerMain.compile(args, context, fileObjects, processors); 3.15 cleanup(); 3.16 - return result == 0; 3.17 + return result.isOK(); 3.18 } else { 3.19 throw new IllegalStateException("multiple calls to method 'call'"); 3.20 } 3.21 @@ -274,6 +274,9 @@ 3.22 public Iterable<? extends TypeElement> enter(Iterable<? extends CompilationUnitTree> trees) 3.23 throws IOException 3.24 { 3.25 + if (trees == null && notYetEntered != null && notYetEntered.isEmpty()) 3.26 + return List.nil(); 3.27 + 3.28 prepareCompiler(); 3.29 3.30 ListBuffer<JCCompilationUnit> roots = null;
4.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Thu Sep 29 18:54:01 2011 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Mon Oct 03 18:26:59 2011 -0700 4.3 @@ -65,6 +65,7 @@ 4.4 import com.sun.tools.javac.tree.TreeCopier; 4.5 import com.sun.tools.javac.tree.TreeInfo; 4.6 import com.sun.tools.javac.tree.TreeMaker; 4.7 +import com.sun.tools.javac.util.Assert; 4.8 import com.sun.tools.javac.util.Context; 4.9 import com.sun.tools.javac.util.JCDiagnostic; 4.10 import com.sun.tools.javac.util.List; 4.11 @@ -263,9 +264,10 @@ 4.12 if (!(path.getLeaf() instanceof JCTree)) // implicit null-check 4.13 throw new IllegalArgumentException(); 4.14 4.15 - // if we're being invoked via from a JSR199 client, we need to make sure 4.16 - // all the classes have been entered; if we're being invoked from JSR269, 4.17 - // then the classes will already have been entered. 4.18 + // if we're being invoked from a Tree API client via parse/enter/analyze, 4.19 + // we need to make sure all the classes have been entered; 4.20 + // if we're being invoked from JSR 199 or JSR 269, then the classes 4.21 + // will already have been entered. 4.22 if (javacTaskImpl != null) { 4.23 try { 4.24 javacTaskImpl.enter(null); 4.25 @@ -313,10 +315,19 @@ 4.26 break; 4.27 case BLOCK: { 4.28 // System.err.println("BLOCK: "); 4.29 - if (method != null) 4.30 - env = memberEnter.getMethodEnv(method, env); 4.31 - JCTree body = copier.copy((JCTree)tree, (JCTree) path.getLeaf()); 4.32 - env = attribStatToTree(body, env, copier.leafCopy); 4.33 + if (method != null) { 4.34 + try { 4.35 + Assert.check(method.body == tree); 4.36 + method.body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf()); 4.37 + env = memberEnter.getMethodEnv(method, env); 4.38 + env = attribStatToTree(method.body, env, copier.leafCopy); 4.39 + } finally { 4.40 + method.body = (JCBlock) tree; 4.41 + } 4.42 + } else { 4.43 + JCBlock body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf()); 4.44 + env = attribStatToTree(body, env, copier.leafCopy); 4.45 + } 4.46 return env; 4.47 } 4.48 default: 4.49 @@ -329,7 +340,7 @@ 4.50 } 4.51 } 4.52 } 4.53 - return field != null ? memberEnter.getInitEnv(field, env) : env; 4.54 + return (field != null) ? memberEnter.getInitEnv(field, env) : env; 4.55 } 4.56 4.57 private Env<AttrContext> attribStatToTree(JCTree stat, Env<AttrContext>env, JCTree tree) {
5.1 --- a/src/share/classes/com/sun/tools/javac/code/Kinds.java Thu Sep 29 18:54:01 2011 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/code/Kinds.java Mon Oct 03 18:26:59 2011 -0700 5.3 @@ -103,6 +103,8 @@ 5.4 VAL("kindname.value"), 5.5 METHOD("kindname.method"), 5.6 CLASS("kindname.class"), 5.7 + STATIC_INIT("kindname.static.init"), 5.8 + INSTANCE_INIT("kindname.instance.init"), 5.9 PACKAGE("kindname.package"); 5.10 5.11 private String name; 5.12 @@ -170,9 +172,11 @@ 5.13 return KindName.CONSTRUCTOR; 5.14 5.15 case METHOD: 5.16 + return KindName.METHOD; 5.17 case STATIC_INIT: 5.18 + return KindName.STATIC_INIT; 5.19 case INSTANCE_INIT: 5.20 - return KindName.METHOD; 5.21 + return KindName.INSTANCE_INIT; 5.22 5.23 default: 5.24 if (sym.kind == VAL)
6.1 --- a/src/share/classes/com/sun/tools/javac/code/Printer.java Thu Sep 29 18:54:01 2011 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/code/Printer.java Mon Oct 03 18:26:59 2011 -0700 6.3 @@ -311,7 +311,7 @@ 6.4 6.5 @Override 6.6 public String visitMethodSymbol(MethodSymbol s, Locale locale) { 6.7 - if ((s.flags() & BLOCK) != 0) { 6.8 + if (s.isStaticOrInstanceInit()) { 6.9 return s.owner.name.toString(); 6.10 } else { 6.11 String ms = (s.name == s.name.table.names.init)
7.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Thu Sep 29 18:54:01 2011 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Mon Oct 03 18:26:59 2011 -0700 7.3 @@ -149,7 +149,8 @@ 7.4 * the default package; otherwise, the owner symbol is returned 7.5 */ 7.6 public Symbol location() { 7.7 - if (owner.name == null || (owner.name.isEmpty() && owner.kind != PCK && owner.kind != TYP)) { 7.8 + if (owner.name == null || (owner.name.isEmpty() && 7.9 + (owner.flags() & BLOCK) == 0 && owner.kind != PCK && owner.kind != TYP)) { 7.10 return null; 7.11 } 7.12 return owner; 7.13 @@ -725,6 +726,11 @@ 7.14 */ 7.15 public JavaFileObject classfile; 7.16 7.17 + /** the list of translated local classes (used for generating 7.18 + * InnerClasses attribute) 7.19 + */ 7.20 + public List<ClassSymbol> trans_local; 7.21 + 7.22 /** the constant pool of the class 7.23 */ 7.24 public Pool pool; 7.25 @@ -1299,10 +1305,17 @@ 7.26 return ElementKind.CONSTRUCTOR; 7.27 else if (name == name.table.names.clinit) 7.28 return ElementKind.STATIC_INIT; 7.29 + else if ((flags() & BLOCK) != 0) 7.30 + return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT; 7.31 else 7.32 return ElementKind.METHOD; 7.33 } 7.34 7.35 + public boolean isStaticOrInstanceInit() { 7.36 + return getKind() == ElementKind.STATIC_INIT || 7.37 + getKind() == ElementKind.INSTANCE_INIT; 7.38 + } 7.39 + 7.40 public Attribute getDefaultValue() { 7.41 return defaultValue; 7.42 }
8.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Thu Sep 29 18:54:01 2011 -0700 8.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Mon Oct 03 18:26:59 2011 -0700 8.3 @@ -508,8 +508,13 @@ 8.4 @Override 8.5 public Boolean visitUndetVar(UndetVar t, Type s) { 8.6 //todo: test against origin needed? or replace with substitution? 8.7 - if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN) 8.8 + if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN) { 8.9 return true; 8.10 + } else if (s.tag == BOT) { 8.11 + //if 's' is 'null' there's no instantiated type U for which 8.12 + //U <: s (but 'null' itself, which is not a valid type) 8.13 + return false; 8.14 + } 8.15 8.16 if (t.inst != null) 8.17 return isSubtypeNoCapture(t.inst, s); // TODO: ", warn"?
9.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Sep 29 18:54:01 2011 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Mon Oct 03 18:26:59 2011 -0700 9.3 @@ -306,7 +306,16 @@ 9.4 */ 9.5 void duplicateError(DiagnosticPosition pos, Symbol sym) { 9.6 if (!sym.type.isErroneous()) { 9.7 - log.error(pos, "already.defined", sym, sym.location()); 9.8 + Symbol location = sym.location(); 9.9 + if (location.kind == MTH && 9.10 + ((MethodSymbol)location).isStaticOrInstanceInit()) { 9.11 + log.error(pos, "already.defined.in.clinit", kindName(sym), sym, 9.12 + kindName(sym.location()), kindName(sym.location().enclClass()), 9.13 + sym.location().enclClass()); 9.14 + } else { 9.15 + log.error(pos, "already.defined", kindName(sym), sym, 9.16 + kindName(sym.location()), sym.location()); 9.17 + } 9.18 } 9.19 } 9.20
10.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Thu Sep 29 18:54:01 2011 -0700 10.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Mon Oct 03 18:26:59 2011 -0700 10.3 @@ -269,21 +269,18 @@ 10.4 // VGJ: sort of inlined maximizeInst() below. Adding 10.5 // bounds can cause lobounds that are above hibounds. 10.6 List<Type> hibounds = Type.filter(that.hibounds, errorFilter); 10.7 + Type hb = null; 10.8 if (hibounds.isEmpty()) 10.9 - return; 10.10 - Type hb = null; 10.11 - if (hibounds.tail.isEmpty()) 10.12 + hb = syms.objectType; 10.13 + else if (hibounds.tail.isEmpty()) 10.14 hb = hibounds.head; 10.15 - else for (List<Type> bs = hibounds; 10.16 - bs.nonEmpty() && hb == null; 10.17 - bs = bs.tail) { 10.18 - if (isSubClass(bs.head, hibounds)) 10.19 - hb = types.fromUnknownFun.apply(bs.head); 10.20 - } 10.21 + else 10.22 + hb = types.glb(hibounds); 10.23 if (hb == null || 10.24 - !types.isSubtypeUnchecked(hb, hibounds, warn) || 10.25 - !types.isSubtypeUnchecked(that.inst, hb, warn)) 10.26 - throw ambiguousNoInstanceException; 10.27 + hb.isErroneous()) 10.28 + throw ambiguousNoInstanceException 10.29 + .setMessage("incompatible.upper.bounds", 10.30 + that.qtype, hibounds); 10.31 } 10.32 } 10.33
11.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Sep 29 18:54:01 2011 -0700 11.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Mon Oct 03 18:26:59 2011 -0700 11.3 @@ -2271,6 +2271,14 @@ 11.4 tree.extending = translate(tree.extending); 11.5 tree.implementing = translate(tree.implementing); 11.6 11.7 + if (currentClass.isLocal()) { 11.8 + ClassSymbol encl = currentClass.owner.enclClass(); 11.9 + if (encl.trans_local == null) { 11.10 + encl.trans_local = List.nil(); 11.11 + } 11.12 + encl.trans_local = encl.trans_local.prepend(currentClass); 11.13 + } 11.14 + 11.15 // Recursively translate members, taking into account that new members 11.16 // might be created during the translation and prepended to the member 11.17 // list `tree.defs'.
12.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Thu Sep 29 18:54:01 2011 -0700 12.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Mon Oct 03 18:26:59 2011 -0700 12.3 @@ -863,10 +863,10 @@ 12.4 } 12.5 if (c.type.tag != CLASS) return; // arrays 12.6 if (pool != null && // pool might be null if called from xClassName 12.7 - c.owner.kind != PCK && 12.8 + c.owner.enclClass() != null && 12.9 (innerClasses == null || !innerClasses.contains(c))) { 12.10 // log.errWriter.println("enter inner " + c);//DEBUG 12.11 - if (c.owner.kind == TYP) enterInner((ClassSymbol)c.owner); 12.12 + enterInner(c.owner.enclClass()); 12.13 pool.put(c); 12.14 pool.put(c.name); 12.15 if (innerClasses == null) { 12.16 @@ -1505,6 +1505,13 @@ 12.17 default : Assert.error(); 12.18 } 12.19 } 12.20 + 12.21 + if (c.trans_local != null) { 12.22 + for (ClassSymbol local : c.trans_local) { 12.23 + enterInner(local); 12.24 + } 12.25 + } 12.26 + 12.27 databuf.appendChar(fieldsCount); 12.28 writeFields(c.members().elems); 12.29 databuf.appendChar(methodsCount);
13.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Thu Sep 29 18:54:01 2011 -0700 13.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Mon Oct 03 18:26:59 2011 -0700 13.3 @@ -488,6 +488,10 @@ 13.4 */ 13.5 public Todo todo; 13.6 13.7 + /** A list of items to be closed when the compilation is complete. 13.8 + */ 13.9 + public List<Closeable> closeables = List.nil(); 13.10 + 13.11 /** Ordered list of compiler phases for each compilation unit. */ 13.12 public enum CompileState { 13.13 PARSE(1), 13.14 @@ -1581,6 +1585,19 @@ 13.15 if (names != null && disposeNames) 13.16 names.dispose(); 13.17 names = null; 13.18 + 13.19 + for (Closeable c: closeables) { 13.20 + try { 13.21 + c.close(); 13.22 + } catch (IOException e) { 13.23 + // When javac uses JDK 7 as a baseline, this code would be 13.24 + // better written to set any/all exceptions from all the 13.25 + // Closeables as suppressed exceptions on the FatalError 13.26 + // that is thrown. 13.27 + JCDiagnostic msg = diagFactory.fragment("fatal.err.cant.close"); 13.28 + throw new FatalError(msg, e); 13.29 + } 13.30 + } 13.31 } 13.32 } 13.33 13.34 @@ -1615,6 +1632,8 @@ 13.35 keepComments = prev.keepComments; 13.36 start_msec = prev.start_msec; 13.37 hasBeenUsed = true; 13.38 + closeables = prev.closeables; 13.39 + prev.closeables = List.nil(); 13.40 } 13.41 13.42 public static void enableLogging() {
14.1 --- a/src/share/classes/com/sun/tools/javac/main/Main.java Thu Sep 29 18:54:01 2011 -0700 14.2 +++ b/src/share/classes/com/sun/tools/javac/main/Main.java Mon Oct 03 18:26:59 2011 -0700 14.3 @@ -76,12 +76,23 @@ 14.4 14.5 /** Result codes. 14.6 */ 14.7 - static final int 14.8 - EXIT_OK = 0, // Compilation completed with no errors. 14.9 - EXIT_ERROR = 1, // Completed but reported errors. 14.10 - EXIT_CMDERR = 2, // Bad command-line arguments 14.11 - EXIT_SYSERR = 3, // System error or resource exhaustion. 14.12 - EXIT_ABNORMAL = 4; // Compiler terminated abnormally 14.13 + public enum Result { 14.14 + OK(0), // Compilation completed with no errors. 14.15 + ERROR(1), // Completed but reported errors. 14.16 + CMDERR(2), // Bad command-line arguments 14.17 + SYSERR(3), // System error or resource exhaustion. 14.18 + ABNORMAL(4); // Compiler terminated abnormally 14.19 + 14.20 + Result(int exitCode) { 14.21 + this.exitCode = exitCode; 14.22 + } 14.23 + 14.24 + public boolean isOK() { 14.25 + return (exitCode == 0); 14.26 + } 14.27 + 14.28 + public final int exitCode; 14.29 + } 14.30 14.31 private Option[] recognizedOptions = RecognizedOptions.getJavaCompilerOptions(new OptionHelper() { 14.32 14.33 @@ -318,10 +329,10 @@ 14.34 /** Programmatic interface for main function. 14.35 * @param args The command line parameters. 14.36 */ 14.37 - public int compile(String[] args) { 14.38 + public Result compile(String[] args) { 14.39 Context context = new Context(); 14.40 JavacFileManager.preRegister(context); // can't create it until Log has been set up 14.41 - int result = compile(args, context); 14.42 + Result result = compile(args, context); 14.43 if (fileManager instanceof JavacFileManager) { 14.44 // A fresh context was created above, so jfm must be a JavacFileManager 14.45 ((JavacFileManager)fileManager).close(); 14.46 @@ -329,14 +340,14 @@ 14.47 return result; 14.48 } 14.49 14.50 - public int compile(String[] args, Context context) { 14.51 + public Result compile(String[] args, Context context) { 14.52 return compile(args, context, List.<JavaFileObject>nil(), null); 14.53 } 14.54 14.55 /** Programmatic interface for main function. 14.56 * @param args The command line parameters. 14.57 */ 14.58 - public int compile(String[] args, 14.59 + public Result compile(String[] args, 14.60 Context context, 14.61 List<JavaFileObject> fileObjects, 14.62 Iterable<? extends Processor> processors) 14.63 @@ -355,7 +366,7 @@ 14.64 try { 14.65 if (args.length == 0 && fileObjects.isEmpty()) { 14.66 help(); 14.67 - return EXIT_CMDERR; 14.68 + return Result.CMDERR; 14.69 } 14.70 14.71 Collection<File> files; 14.72 @@ -363,26 +374,26 @@ 14.73 files = processArgs(CommandLine.parse(args)); 14.74 if (files == null) { 14.75 // null signals an error in options, abort 14.76 - return EXIT_CMDERR; 14.77 + return Result.CMDERR; 14.78 } else if (files.isEmpty() && fileObjects.isEmpty() && classnames.isEmpty()) { 14.79 // it is allowed to compile nothing if just asking for help or version info 14.80 if (options.isSet(HELP) 14.81 || options.isSet(X) 14.82 || options.isSet(VERSION) 14.83 || options.isSet(FULLVERSION)) 14.84 - return EXIT_OK; 14.85 + return Result.OK; 14.86 if (JavaCompiler.explicitAnnotationProcessingRequested(options)) { 14.87 error("err.no.source.files.classes"); 14.88 } else { 14.89 error("err.no.source.files"); 14.90 } 14.91 - return EXIT_CMDERR; 14.92 + return Result.CMDERR; 14.93 } 14.94 } catch (java.io.FileNotFoundException e) { 14.95 Log.printLines(out, ownName + ": " + 14.96 getLocalizedString("err.file.not.found", 14.97 e.getMessage())); 14.98 - return EXIT_SYSERR; 14.99 + return Result.SYSERR; 14.100 } 14.101 14.102 boolean forceStdOut = options.isSet("stdout"); 14.103 @@ -402,7 +413,7 @@ 14.104 fileManager = context.get(JavaFileManager.class); 14.105 14.106 comp = JavaCompiler.instance(context); 14.107 - if (comp == null) return EXIT_SYSERR; 14.108 + if (comp == null) return Result.SYSERR; 14.109 14.110 Log log = Log.instance(context); 14.111 14.112 @@ -423,32 +434,32 @@ 14.113 if (log.expectDiagKeys != null) { 14.114 if (log.expectDiagKeys.isEmpty()) { 14.115 Log.printLines(log.noticeWriter, "all expected diagnostics found"); 14.116 - return EXIT_OK; 14.117 + return Result.OK; 14.118 } else { 14.119 Log.printLines(log.noticeWriter, "expected diagnostic keys not found: " + log.expectDiagKeys); 14.120 - return EXIT_ERROR; 14.121 + return Result.ERROR; 14.122 } 14.123 } 14.124 14.125 if (comp.errorCount() != 0) 14.126 - return EXIT_ERROR; 14.127 + return Result.ERROR; 14.128 } catch (IOException ex) { 14.129 ioMessage(ex); 14.130 - return EXIT_SYSERR; 14.131 + return Result.SYSERR; 14.132 } catch (OutOfMemoryError ex) { 14.133 resourceMessage(ex); 14.134 - return EXIT_SYSERR; 14.135 + return Result.SYSERR; 14.136 } catch (StackOverflowError ex) { 14.137 resourceMessage(ex); 14.138 - return EXIT_SYSERR; 14.139 + return Result.SYSERR; 14.140 } catch (FatalError ex) { 14.141 feMessage(ex); 14.142 - return EXIT_SYSERR; 14.143 + return Result.SYSERR; 14.144 } catch (AnnotationProcessingError ex) { 14.145 if (apiMode) 14.146 throw new RuntimeException(ex.getCause()); 14.147 apMessage(ex); 14.148 - return EXIT_SYSERR; 14.149 + return Result.SYSERR; 14.150 } catch (ClientCodeException ex) { 14.151 // as specified by javax.tools.JavaCompiler#getTask 14.152 // and javax.tools.JavaCompiler.CompilationTask#call 14.153 @@ -462,7 +473,7 @@ 14.154 if (comp == null || comp.errorCount() == 0 || 14.155 options == null || options.isSet("dev")) 14.156 bugMessage(ex); 14.157 - return EXIT_ABNORMAL; 14.158 + return Result.ABNORMAL; 14.159 } finally { 14.160 if (comp != null) { 14.161 try { 14.162 @@ -474,7 +485,7 @@ 14.163 filenames = null; 14.164 options = null; 14.165 } 14.166 - return EXIT_OK; 14.167 + return Result.OK; 14.168 } 14.169 14.170 /** Print a message reporting an internal error.
15.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacFiler.java Thu Sep 29 18:54:01 2011 -0700 15.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacFiler.java Mon Oct 03 18:26:59 2011 -0700 15.3 @@ -1,5 +1,5 @@ 15.4 /* 15.5 - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 15.6 + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. 15.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.8 * 15.9 * This code is free software; you can redistribute it and/or modify it 15.10 @@ -455,9 +455,24 @@ 15.11 // TODO: Only support reading resources in selected output 15.12 // locations? Only allow reading of non-source, non-class 15.13 // files from the supported input locations? 15.14 - FileObject fileObject = fileManager.getFileForInput(location, 15.15 + 15.16 + // In the following, getFileForInput is the "obvious" method 15.17 + // to use, but it does not have the "obvious" semantics for 15.18 + // SOURCE_OUTPUT and CLASS_OUTPUT. Conversely, getFileForOutput 15.19 + // does not have the correct semantics for any "path" location 15.20 + // with more than one component. So, for now, we use a hybrid 15.21 + // invocation. 15.22 + FileObject fileObject; 15.23 + if (location.isOutputLocation()) { 15.24 + fileObject = fileManager.getFileForOutput(location, 15.25 + pkg.toString(), 15.26 + relativeName.toString(), 15.27 + null); 15.28 + } else { 15.29 + fileObject = fileManager.getFileForInput(location, 15.30 pkg.toString(), 15.31 relativeName.toString()); 15.32 + } 15.33 if (fileObject == null) { 15.34 String name = (pkg.length() == 0) 15.35 ? relativeName.toString() : (pkg + "/" + relativeName);
16.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Sep 29 18:54:01 2011 -0700 16.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Mon Oct 03 18:26:59 2011 -0700 16.3 @@ -225,6 +225,11 @@ 16.4 ? fileManager.getClassLoader(ANNOTATION_PROCESSOR_PATH) 16.5 : fileManager.getClassLoader(CLASS_PATH); 16.6 16.7 + if (processorClassLoader != null && processorClassLoader instanceof Closeable) { 16.8 + JavaCompiler compiler = JavaCompiler.instance(context); 16.9 + compiler.closeables = compiler.closeables.prepend((Closeable) processorClassLoader); 16.10 + } 16.11 + 16.12 /* 16.13 * If the "-processor" option is used, search the appropriate 16.14 * path for the named class. Otherwise, use a service 16.15 @@ -1211,14 +1216,6 @@ 16.16 if (discoveredProcs != null) // Make calling close idempotent 16.17 discoveredProcs.close(); 16.18 discoveredProcs = null; 16.19 - if (processorClassLoader != null && processorClassLoader instanceof Closeable) { 16.20 - try { 16.21 - ((Closeable) processorClassLoader).close(); 16.22 - } catch (IOException e) { 16.23 - JCDiagnostic msg = diags.fragment("fatal.err.cant.close.loader"); 16.24 - throw new FatalError(msg, e); 16.25 - } 16.26 - } 16.27 } 16.28 16.29 private List<ClassSymbol> getTopLevelClasses(List<? extends JCCompilationUnit> units) {
17.1 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Sep 29 18:54:01 2011 -0700 17.2 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Mon Oct 03 18:26:59 2011 -0700 17.3 @@ -68,9 +68,13 @@ 17.4 compiler.err.already.annotated=\ 17.5 {0} {1} has already been annotated 17.6 17.7 -# 0: symbol, 1: symbol 17.8 +# 0: symbol kind, 1: symbol, 2: symbol kind, 3: symbol 17.9 compiler.err.already.defined=\ 17.10 - {0} is already defined in {1} 17.11 + {0} {1} is already defined in {2} {3} 17.12 + 17.13 +# 0: symbol kind, 1: symbol, 2: symbol kind, 3: symbol kind, 4: symbol 17.14 +compiler.err.already.defined.in.clinit=\ 17.15 + {0} {1} is already defined in {2} of {3} {4} 17.16 17.17 # 0: string 17.18 compiler.err.already.defined.single.import=\ 17.19 @@ -891,8 +895,8 @@ 17.20 compiler.misc.fatal.err.cant.locate.ctor=\ 17.21 Fatal Error: Unable to find constructor for {0} 17.22 17.23 -compiler.misc.fatal.err.cant.close.loader=\ 17.24 - Fatal Error: Cannot close class loader for annotation processors 17.25 +compiler.misc.fatal.err.cant.close=\ 17.26 + Fatal Error: Cannot close compiler resources 17.27 17.28 ##### 17.29 17.30 @@ -1598,6 +1602,10 @@ 17.31 compiler.misc.no.unique.minimal.instance.exists=\ 17.32 no unique minimal instance exists for type variable {0} with lower bounds {1} 17.33 17.34 +# 0: type, 1: list of type 17.35 +compiler.misc.incompatible.upper.bounds=\ 17.36 + inference variable {0} has incompatible upper bounds {1} 17.37 + 17.38 # 0: list of type, 1: type, 2: type 17.39 compiler.misc.infer.no.conforming.instance.exists=\ 17.40 no instance(s) of type variable(s) {0} exist so that {1} conforms to {2} 17.41 @@ -1753,6 +1761,12 @@ 17.42 compiler.misc.kindname.package=\ 17.43 package 17.44 17.45 +compiler.misc.kindname.static.init=\ 17.46 + static initializer 17.47 + 17.48 +compiler.misc.kindname.instance.init=\ 17.49 + instance initializer 17.50 + 17.51 ##### 17.52 17.53 compiler.misc.no.args=\
18.1 --- a/src/share/classes/com/sun/tools/javac/tree/JCTree.java Thu Sep 29 18:54:01 2011 -0700 18.2 +++ b/src/share/classes/com/sun/tools/javac/tree/JCTree.java Mon Oct 03 18:26:59 2011 -0700 18.3 @@ -436,7 +436,6 @@ 18.4 public PackageSymbol packge; 18.5 public ImportScope namedImportScope; 18.6 public StarImportScope starImportScope; 18.7 - public long flags; 18.8 public Position.LineMap lineMap = null; 18.9 public Map<JCTree, String> docComments = null; 18.10 public Map<JCTree, Integer> endPositions = null; 18.11 @@ -1176,6 +1175,21 @@ 18.12 public int getTag() { 18.13 return EXEC; 18.14 } 18.15 + 18.16 + /** Convert a expression-statement tree to a pretty-printed string. */ 18.17 + @Override 18.18 + public String toString() { 18.19 + StringWriter s = new StringWriter(); 18.20 + try { 18.21 + new Pretty(s, false).printStat(this); 18.22 + } 18.23 + catch (IOException e) { 18.24 + // should never happen, because StringWriter is defined 18.25 + // never to throw any IOExceptions 18.26 + throw new AssertionError(e); 18.27 + } 18.28 + return s.toString(); 18.29 + } 18.30 } 18.31 18.32 /**
19.1 --- a/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Thu Sep 29 18:54:01 2011 -0700 19.2 +++ b/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Mon Oct 03 18:26:59 2011 -0700 19.3 @@ -412,7 +412,7 @@ 19.4 @Override 19.5 public String visitMethodSymbol(MethodSymbol s, Locale locale) { 19.6 String ownerName = visit(s.owner, locale); 19.7 - if ((s.flags() & BLOCK) != 0) { 19.8 + if (s.isStaticOrInstanceInit()) { 19.9 return ownerName; 19.10 } else { 19.11 String ms = (s.name == s.name.table.names.init)
20.1 --- a/src/share/classes/com/sun/tools/javadoc/JavadocTool.java Thu Sep 29 18:54:01 2011 -0700 20.2 +++ b/src/share/classes/com/sun/tools/javadoc/JavadocTool.java Mon Oct 03 18:26:59 2011 -0700 20.3 @@ -1,5 +1,5 @@ 20.4 /* 20.5 - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. 20.6 + * Copyright (c) 2001, 2011, 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 @@ -257,24 +257,15 @@ 20.11 for (String p: excludedPackages) 20.12 includedPackages.put(p, false); 20.13 20.14 - if (docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)) { 20.15 - searchSubPackages(subPackages, 20.16 - includedPackages, 20.17 - packages, packageFiles, 20.18 - StandardLocation.SOURCE_PATH, 20.19 - EnumSet.of(JavaFileObject.Kind.SOURCE)); 20.20 - searchSubPackages(subPackages, 20.21 - includedPackages, 20.22 - packages, packageFiles, 20.23 - StandardLocation.CLASS_PATH, 20.24 - EnumSet.of(JavaFileObject.Kind.CLASS)); 20.25 - } else { 20.26 - searchSubPackages(subPackages, 20.27 - includedPackages, 20.28 - packages, packageFiles, 20.29 - StandardLocation.CLASS_PATH, 20.30 - EnumSet.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS)); 20.31 - } 20.32 + StandardLocation path = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH) 20.33 + ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH; 20.34 + 20.35 + searchSubPackages(subPackages, 20.36 + includedPackages, 20.37 + packages, packageFiles, 20.38 + path, 20.39 + EnumSet.of(JavaFileObject.Kind.SOURCE)); 20.40 + 20.41 return packageFiles; 20.42 } 20.43
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/test/tools/javac/7003595/T7003595.java Mon Oct 03 18:26:59 2011 -0700 21.3 @@ -0,0 +1,233 @@ 21.4 +/* 21.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 21.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 21.7 + * 21.8 + * This code is free software; you can redistribute it and/or modify it 21.9 + * under the terms of the GNU General Public License version 2 only, as 21.10 + * published by the Free Software Foundation. 21.11 + * 21.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 21.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 21.15 + * version 2 for more details (a copy is included in the LICENSE file that 21.16 + * accompanied this code). 21.17 + * 21.18 + * You should have received a copy of the GNU General Public License version 21.19 + * 2 along with this work; if not, write to the Free Software Foundation, 21.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21.21 + * 21.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21.23 + * or visit www.oracle.com if you need additional information or have any 21.24 + * questions. 21.25 + */ 21.26 + 21.27 +/* 21.28 + * @test 21.29 + * @bug 7003595 21.30 + * @summary IncompatibleClassChangeError with unreferenced local class with subclass 21.31 + */ 21.32 + 21.33 +import com.sun.source.util.JavacTask; 21.34 +import com.sun.tools.classfile.Attribute; 21.35 +import com.sun.tools.classfile.ClassFile; 21.36 +import com.sun.tools.classfile.InnerClasses_attribute; 21.37 +import com.sun.tools.classfile.ConstantPool.*; 21.38 +import com.sun.tools.javac.api.JavacTool; 21.39 + 21.40 +import java.io.File; 21.41 +import java.net.URI; 21.42 +import java.util.Arrays; 21.43 +import java.util.ArrayList; 21.44 +import javax.tools.JavaCompiler; 21.45 +import javax.tools.JavaFileObject; 21.46 +import javax.tools.SimpleJavaFileObject; 21.47 +import javax.tools.StandardJavaFileManager; 21.48 +import javax.tools.ToolProvider; 21.49 + 21.50 + 21.51 +public class T7003595 { 21.52 + 21.53 + /** global decls ***/ 21.54 + 21.55 + // Create a single file manager and reuse it for each compile to save time. 21.56 + static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null); 21.57 + 21.58 + //statistics 21.59 + static int checkCount = 0; 21.60 + 21.61 + enum ClassKind { 21.62 + NESTED("static class #N { #B }", "$", true), 21.63 + INNER("class #N { #B }", "$", false), 21.64 + LOCAL_REF("void test() { class #N { #B }; new #N(); }", "$1", false), 21.65 + LOCAL_NOREF("void test() { class #N { #B }; }", "$1", false), 21.66 + ANON("void test() { new Object() { #B }; }", "$1", false), 21.67 + NONE("", "", false); 21.68 + 21.69 + String memberInnerStr; 21.70 + String sep; 21.71 + boolean staticAllowed; 21.72 + 21.73 + private ClassKind(String memberInnerStr, String sep, boolean staticAllowed) { 21.74 + this.memberInnerStr = memberInnerStr; 21.75 + this.sep = sep; 21.76 + this.staticAllowed = staticAllowed; 21.77 + } 21.78 + 21.79 + String getSource(String className, String outerName, String nested) { 21.80 + return memberInnerStr.replaceAll("#O", outerName). 21.81 + replaceAll("#N", className).replaceAll("#B", nested); 21.82 + } 21.83 + 21.84 + static String getClassfileName(String[] names, ClassKind[] outerKinds, int pos) { 21.85 + System.out.println(" pos = " + pos + " kind = " + outerKinds[pos] + " sep = " + outerKinds[pos].sep); 21.86 + String name = outerKinds[pos] != ANON ? 21.87 + names[pos] : ""; 21.88 + if (pos == 0) { 21.89 + return "Test" + outerKinds[pos].sep + name; 21.90 + } else { 21.91 + String outerStr = getClassfileName(names, outerKinds, pos - 1); 21.92 + return outerStr + outerKinds[pos].sep + name; 21.93 + } 21.94 + } 21.95 + 21.96 + boolean isAllowed(ClassKind nestedKind) { 21.97 + return nestedKind != NESTED || 21.98 + staticAllowed; 21.99 + } 21.100 + } 21.101 + 21.102 + enum LocalInnerClass { 21.103 + LOCAL_REF("class L {}; new L();", "Test$1L"), 21.104 + LOCAL_NOREF("class L {};", "Test$1L"), 21.105 + ANON("new Object() {};", "Test$1"), 21.106 + NONE("", ""); 21.107 + 21.108 + String localInnerStr; 21.109 + String canonicalInnerStr; 21.110 + 21.111 + private LocalInnerClass(String localInnerStr, String canonicalInnerStr) { 21.112 + this.localInnerStr = localInnerStr; 21.113 + this.canonicalInnerStr = canonicalInnerStr; 21.114 + } 21.115 + } 21.116 + 21.117 + public static void main(String... args) throws Exception { 21.118 + for (ClassKind ck1 : ClassKind.values()) { 21.119 + String cname1 = "C1"; 21.120 + for (ClassKind ck2 : ClassKind.values()) { 21.121 + if (!ck1.isAllowed(ck2)) continue; 21.122 + String cname2 = "C2"; 21.123 + for (ClassKind ck3 : ClassKind.values()) { 21.124 + if (!ck2.isAllowed(ck3)) continue; 21.125 + String cname3 = "C3"; 21.126 + new T7003595(new ClassKind[] {ck1, ck2, ck3}, new String[] { cname1, cname2, cname3 }).compileAndCheck(); 21.127 + } 21.128 + } 21.129 + } 21.130 + 21.131 + System.out.println("Total checks made: " + checkCount); 21.132 + } 21.133 + 21.134 + /** instance decls **/ 21.135 + 21.136 + ClassKind[] cks; 21.137 + String[] cnames; 21.138 + 21.139 + T7003595(ClassKind[] cks, String[] cnames) { 21.140 + this.cks = cks; 21.141 + this.cnames = cnames; 21.142 + } 21.143 + 21.144 + void compileAndCheck() throws Exception { 21.145 + final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); 21.146 + JavaSource source = new JavaSource(); 21.147 + JavacTask ct = (JavacTask)tool.getTask(null, fm, null, 21.148 + null, null, Arrays.asList(source)); 21.149 + ct.call(); 21.150 + verifyBytecode(source); 21.151 + } 21.152 + 21.153 + void verifyBytecode(JavaSource source) { 21.154 + for (int i = 0; i < 3 ; i ++) { 21.155 + if (cks[i] == ClassKind.NONE) break; 21.156 + checkCount++; 21.157 + String filename = cks[i].getClassfileName(cnames, cks, i); 21.158 + File compiledTest = new File(filename + ".class"); 21.159 + try { 21.160 + ClassFile cf = ClassFile.read(compiledTest); 21.161 + if (cf == null) { 21.162 + throw new Error("Classfile not found: " + filename); 21.163 + } 21.164 + 21.165 + InnerClasses_attribute innerClasses = (InnerClasses_attribute)cf.getAttribute(Attribute.InnerClasses); 21.166 + 21.167 + ArrayList<String> foundInnerSig = new ArrayList<>(); 21.168 + if (innerClasses != null) { 21.169 + for (InnerClasses_attribute.Info info : innerClasses.classes) { 21.170 + String foundSig = info.getInnerClassInfo(cf.constant_pool).getName(); 21.171 + foundInnerSig.add(foundSig); 21.172 + } 21.173 + } 21.174 + 21.175 + ArrayList<String> expectedInnerSig = new ArrayList<>(); 21.176 + //add inner class (if any) 21.177 + if (i < 2 && cks[i + 1] != ClassKind.NONE) { 21.178 + expectedInnerSig.add(cks[i + 1].getClassfileName(cnames, cks, i + 1)); 21.179 + } 21.180 + //add inner classes 21.181 + for (int j = 0 ; j != i + 1 && j < 3; j++) { 21.182 + expectedInnerSig.add(cks[j].getClassfileName(cnames, cks, j)); 21.183 + } 21.184 + 21.185 + if (expectedInnerSig.size() != foundInnerSig.size()) { 21.186 + throw new Error("InnerClasses attribute for " + cnames[i] + " has wrong size\n" + 21.187 + "expected " + expectedInnerSig.size() + "\n" + 21.188 + "found " + innerClasses.number_of_classes + "\n" + 21.189 + source); 21.190 + } 21.191 + 21.192 + for (String foundSig : foundInnerSig) { 21.193 + if (!expectedInnerSig.contains(foundSig)) { 21.194 + throw new Error("InnerClasses attribute for " + cnames[i] + " has unexpected signature: " + 21.195 + foundSig + "\n" + source + "\n" + expectedInnerSig); 21.196 + } 21.197 + } 21.198 + 21.199 + for (String expectedSig : expectedInnerSig) { 21.200 + if (!foundInnerSig.contains(expectedSig)) { 21.201 + throw new Error("InnerClasses attribute for " + cnames[i] + " does not contain expected signature: " + 21.202 + expectedSig + "\n" + source); 21.203 + } 21.204 + } 21.205 + } catch (Exception e) { 21.206 + e.printStackTrace(); 21.207 + throw new Error("error reading " + compiledTest +": " + e); 21.208 + } 21.209 + } 21.210 + } 21.211 + 21.212 + class JavaSource extends SimpleJavaFileObject { 21.213 + 21.214 + static final String source_template = "class Test { #C }"; 21.215 + 21.216 + String source; 21.217 + 21.218 + public JavaSource() { 21.219 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 21.220 + String c3 = cks[2].getSource(cnames[2], cnames[1], ""); 21.221 + String c2 = cks[1].getSource(cnames[1], cnames[0], c3); 21.222 + String c1 = cks[0].getSource(cnames[0], "Test", c2); 21.223 + source = source_template.replace("#C", c1); 21.224 + } 21.225 + 21.226 + @Override 21.227 + public String toString() { 21.228 + return source; 21.229 + } 21.230 + 21.231 + @Override 21.232 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 21.233 + return source; 21.234 + } 21.235 + } 21.236 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/test/tools/javac/7003595/T7003595b.java Mon Oct 03 18:26:59 2011 -0700 22.3 @@ -0,0 +1,36 @@ 22.4 +/* 22.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 22.7 + * 22.8 + * This code is free software; you can redistribute it and/or modify it 22.9 + * under the terms of the GNU General Public License version 2 only, as 22.10 + * published by the Free Software Foundation. 22.11 + * 22.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 22.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 22.15 + * version 2 for more details (a copy is included in the LICENSE file that 22.16 + * accompanied this code). 22.17 + * 22.18 + * You should have received a copy of the GNU General Public License version 22.19 + * 2 along with this work; if not, write to the Free Software Foundation, 22.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22.21 + * 22.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22.23 + * or visit www.oracle.com if you need additional information or have any 22.24 + * questions. 22.25 + */ 22.26 + 22.27 +/* 22.28 + * @test 22.29 + * @bug 7003595 22.30 + * @summary IncompatibleClassChangeError with unreferenced local class with subclass 22.31 + */ 22.32 + 22.33 +public class T7003595b { 22.34 + public static void main(String... args) throws Exception { 22.35 + class A {} 22.36 + class B extends A {} 22.37 + B.class.getSuperclass().getDeclaringClass(); 22.38 + } 22.39 +}
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/test/tools/javac/7086595/T7086595.java Mon Oct 03 18:26:59 2011 -0700 23.3 @@ -0,0 +1,32 @@ 23.4 +/* 23.5 + * @test /nodynamiccopyright/ 23.6 + * @bug 7086595 23.7 + * @summary Error message bug: name of initializer is 'null' 23.8 + * @compile/fail/ref=T7086595.out -XDrawDiagnostics T7086595.java 23.9 + */ 23.10 + 23.11 +class T7086595 { 23.12 + 23.13 + String s = "x"; 23.14 + String s = nonExistent; 23.15 + 23.16 + int foo() { 23.17 + String s = "x"; 23.18 + String s = nonExistent; 23.19 + } 23.20 + 23.21 + static int bar() { 23.22 + String s = "x"; 23.23 + String s = nonExistent; 23.24 + } 23.25 + 23.26 + { 23.27 + String s = "x"; 23.28 + String s = nonExistent; 23.29 + } 23.30 + 23.31 + static { 23.32 + String s = "x"; 23.33 + String s = nonExistent; 23.34 + } 23.35 +}
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/test/tools/javac/7086595/T7086595.out Mon Oct 03 18:26:59 2011 -0700 24.3 @@ -0,0 +1,11 @@ 24.4 +T7086595.java:11:12: compiler.err.already.defined: kindname.variable, s, kindname.class, T7086595 24.5 +T7086595.java:11:16: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null) 24.6 +T7086595.java:15:16: compiler.err.already.defined: kindname.variable, s, kindname.method, foo() 24.7 +T7086595.java:15:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null) 24.8 +T7086595.java:20:16: compiler.err.already.defined: kindname.variable, s, kindname.method, bar() 24.9 +T7086595.java:20:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null) 24.10 +T7086595.java:25:16: compiler.err.already.defined.in.clinit: kindname.variable, s, kindname.instance.init, kindname.class, T7086595 24.11 +T7086595.java:25:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null) 24.12 +T7086595.java:30:16: compiler.err.already.defined.in.clinit: kindname.variable, s, kindname.static.init, kindname.class, T7086595 24.13 +T7086595.java:30:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null) 24.14 +10 errors
25.1 --- a/test/tools/javac/Diagnostics/6860795/T6860795.out Thu Sep 29 18:54:01 2011 -0700 25.2 +++ b/test/tools/javac/Diagnostics/6860795/T6860795.out Mon Oct 03 18:26:59 2011 -0700 25.3 @@ -1,2 +1,2 @@ 25.4 -T6860795.java:10:27: compiler.err.already.defined: x, foo 25.5 +T6860795.java:10:27: compiler.err.already.defined: kindname.variable, x, kindname.method, foo 25.6 1 error
26.1 --- a/test/tools/javac/Diagnostics/6862608/T6862608a.out Thu Sep 29 18:54:01 2011 -0700 26.2 +++ b/test/tools/javac/Diagnostics/6862608/T6862608a.out Mon Oct 03 18:26:59 2011 -0700 26.3 @@ -1,3 +1,3 @@ 26.4 -T6862608a.java:19:41: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.infer.no.conforming.instance.exists: T, java.util.Comparator<T>, java.util.Comparator<java.lang.String>)), <T>java.util.Comparator<T>, java.util.Comparator<java.lang.String> 26.5 +T6862608a.java:19:33: compiler.err.cant.apply.symbol.1: kindname.method, compound, java.lang.Iterable<? extends java.util.Comparator<? super T>>, java.util.List<java.util.Comparator<?>>, kindname.class, T6862608a, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<java.util.Comparator<?>>, java.lang.Iterable<? extends java.util.Comparator<? super T>>) 26.6 - compiler.misc.where.description.typevar: T,{(compiler.misc.where.typevar: T, java.lang.Object, kindname.method, <T>compound(java.lang.Iterable<? extends java.util.Comparator<? super T>>))} 26.7 1 error
27.1 --- a/test/tools/javac/LocalClasses_2.out Thu Sep 29 18:54:01 2011 -0700 27.2 +++ b/test/tools/javac/LocalClasses_2.out Mon Oct 03 18:26:59 2011 -0700 27.3 @@ -1,2 +1,2 @@ 27.4 -LocalClasses_2.java:15:13: compiler.err.already.defined: Local, foo() 27.5 +LocalClasses_2.java:15:13: compiler.err.already.defined: kindname.class, Local, kindname.method, foo() 27.6 1 error
28.1 --- a/test/tools/javac/NestedInnerClassNames.out Thu Sep 29 18:54:01 2011 -0700 28.2 +++ b/test/tools/javac/NestedInnerClassNames.out Mon Oct 03 18:26:59 2011 -0700 28.3 @@ -1,18 +1,18 @@ 28.4 -NestedInnerClassNames.java:16:5: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package 28.5 -NestedInnerClassNames.java:23:9: compiler.err.already.defined: NestedInnerClassNames.foo, NestedInnerClassNames 28.6 -NestedInnerClassNames.java:34:9: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package 28.7 -NestedInnerClassNames.java:45:9: compiler.err.already.defined: NestedInnerClassNames.baz, NestedInnerClassNames 28.8 -NestedInnerClassNames.java:46:13: compiler.err.already.defined: NestedInnerClassNames.baz.baz, NestedInnerClassNames.baz 28.9 -NestedInnerClassNames.java:59:9: compiler.err.already.defined: NestedInnerClassNames.foo$bar, NestedInnerClassNames 28.10 -NestedInnerClassNames.java:76:13: compiler.err.already.defined: NestedInnerClassNames.$bar, NestedInnerClassNames 28.11 -NestedInnerClassNames.java:90:13: compiler.err.already.defined: NestedInnerClassNames.bar$bar.bar, NestedInnerClassNames.bar$bar 28.12 +NestedInnerClassNames.java:16:5: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package 28.13 +NestedInnerClassNames.java:23:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames.foo, kindname.class, NestedInnerClassNames 28.14 +NestedInnerClassNames.java:34:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package 28.15 +NestedInnerClassNames.java:45:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames.baz, kindname.class, NestedInnerClassNames 28.16 +NestedInnerClassNames.java:46:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames.baz.baz, kindname.class, NestedInnerClassNames.baz 28.17 +NestedInnerClassNames.java:59:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames.foo$bar, kindname.class, NestedInnerClassNames 28.18 +NestedInnerClassNames.java:76:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames.$bar, kindname.class, NestedInnerClassNames 28.19 +NestedInnerClassNames.java:90:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames.bar$bar.bar, kindname.class, NestedInnerClassNames.bar$bar 28.20 NestedInnerClassNames.java:109:5: compiler.err.duplicate.class: NestedInnerClassNames.foo.foo 28.21 -NestedInnerClassNames.java:19:9: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package 28.22 -NestedInnerClassNames.java:28:13: compiler.err.already.defined: foo, m2() 28.23 -NestedInnerClassNames.java:40:13: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package 28.24 -NestedInnerClassNames.java:52:13: compiler.err.already.defined: baz, m4() 28.25 -NestedInnerClassNames.java:53:17: compiler.err.already.defined: baz.baz, baz 28.26 -NestedInnerClassNames.java:67:13: compiler.err.already.defined: foo$bar, m5() 28.27 -NestedInnerClassNames.java:83:17: compiler.err.already.defined: $bar, m6() 28.28 -NestedInnerClassNames.java:97:17: compiler.err.already.defined: bar$bar.bar, bar$bar 28.29 +NestedInnerClassNames.java:19:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package 28.30 +NestedInnerClassNames.java:28:13: compiler.err.already.defined: kindname.class, foo, kindname.method, m2() 28.31 +NestedInnerClassNames.java:40:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package 28.32 +NestedInnerClassNames.java:52:13: compiler.err.already.defined: kindname.class, baz, kindname.method, m4() 28.33 +NestedInnerClassNames.java:53:17: compiler.err.already.defined: kindname.class, baz.baz, kindname.class, baz 28.34 +NestedInnerClassNames.java:67:13: compiler.err.already.defined: kindname.class, foo$bar, kindname.method, m5() 28.35 +NestedInnerClassNames.java:83:17: compiler.err.already.defined: kindname.class, $bar, kindname.method, m6() 28.36 +NestedInnerClassNames.java:97:17: compiler.err.already.defined: kindname.class, bar$bar.bar, kindname.class, bar$bar 28.37 17 errors
29.1 --- a/test/tools/javac/TryWithResources/BadTwr.out Thu Sep 29 18:54:01 2011 -0700 29.2 +++ b/test/tools/javac/TryWithResources/BadTwr.out Mon Oct 03 18:26:59 2011 -0700 29.3 @@ -1,5 +1,5 @@ 29.4 -BadTwr.java:13:46: compiler.err.already.defined: r1, main(java.lang.String...) 29.5 -BadTwr.java:18:20: compiler.err.already.defined: args, main(java.lang.String...) 29.6 +BadTwr.java:13:46: compiler.err.already.defined: kindname.variable, r1, kindname.method, main(java.lang.String...) 29.7 +BadTwr.java:18:20: compiler.err.already.defined: kindname.variable, args, kindname.method, main(java.lang.String...) 29.8 BadTwr.java:21:13: compiler.err.cant.assign.val.to.final.var: thatsIt 29.9 -BadTwr.java:26:24: compiler.err.already.defined: name, main(java.lang.String...) 29.10 +BadTwr.java:26:24: compiler.err.already.defined: kindname.variable, name, kindname.method, main(java.lang.String...) 29.11 4 errors
30.1 --- a/test/tools/javac/TryWithResources/DuplicateResourceDecl.out Thu Sep 29 18:54:01 2011 -0700 30.2 +++ b/test/tools/javac/TryWithResources/DuplicateResourceDecl.out Mon Oct 03 18:26:59 2011 -0700 30.3 @@ -1,2 +1,2 @@ 30.4 -DuplicateResourceDecl.java:12:56: compiler.err.already.defined: c, main(java.lang.String[]) 30.5 +DuplicateResourceDecl.java:12:56: compiler.err.already.defined: kindname.variable, c, kindname.method, main(java.lang.String[]) 30.6 1 error
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 31.2 +++ b/test/tools/javac/api/TestGetScope.java Mon Oct 03 18:26:59 2011 -0700 31.3 @@ -0,0 +1,101 @@ 31.4 +/* 31.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 31.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 31.7 + * 31.8 + * This code is free software; you can redistribute it and/or modify it 31.9 + * under the terms of the GNU General Public License version 2 only, as 31.10 + * published by the Free Software Foundation. 31.11 + * 31.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 31.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 31.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 31.15 + * version 2 for more details (a copy is included in the LICENSE file that 31.16 + * accompanied this code). 31.17 + * 31.18 + * You should have received a copy of the GNU General Public License version 31.19 + * 2 along with this work; if not, write to the Free Software Foundation, 31.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 31.21 + * 31.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 31.23 + * or visit www.oracle.com if you need additional information or have any 31.24 + * questions. 31.25 + */ 31.26 + 31.27 +/* 31.28 + * @test 31.29 + * @bug 7090249 31.30 + * @summary IllegalStateException from Trees.getScope when called from JSR 199 31.31 + */ 31.32 + 31.33 +import com.sun.source.tree.IdentifierTree; 31.34 +import java.io.File; 31.35 +import java.util.Arrays; 31.36 +import java.util.Collections; 31.37 +import java.util.List; 31.38 +import java.util.Set; 31.39 +import javax.annotation.processing.AbstractProcessor; 31.40 +import javax.annotation.processing.RoundEnvironment; 31.41 +import javax.lang.model.element.Element; 31.42 +import javax.lang.model.element.TypeElement; 31.43 +import javax.tools.JavaCompiler; 31.44 +import javax.tools.JavaFileObject; 31.45 +import javax.tools.StandardJavaFileManager; 31.46 +import javax.tools.ToolProvider; 31.47 + 31.48 +import com.sun.source.util.JavacTask; 31.49 +import com.sun.source.util.TreePath; 31.50 +import com.sun.source.util.TreePathScanner; 31.51 +import com.sun.source.util.Trees; 31.52 +import javax.annotation.processing.SupportedAnnotationTypes; 31.53 +import javax.lang.model.SourceVersion; 31.54 + 31.55 +@SupportedAnnotationTypes("*") 31.56 +public class TestGetScope extends AbstractProcessor { 31.57 + public static void main(String... args) { 31.58 + new TestGetScope().run(); 31.59 + } 31.60 + 31.61 + public void run() { 31.62 + File srcDir = new File(System.getProperty("test.src")); 31.63 + File thisFile = new File(srcDir, getClass().getName() + ".java"); 31.64 + 31.65 + JavaCompiler c = ToolProvider.getSystemJavaCompiler(); 31.66 + StandardJavaFileManager fm = c.getStandardFileManager(null, null, null); 31.67 + 31.68 + List<String> opts = Arrays.asList("-proc:only", "-doe"); 31.69 + Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile); 31.70 + JavacTask t = (JavacTask) c.getTask(null, fm, null, opts, null, files); 31.71 + t.setProcessors(Collections.singleton(this)); 31.72 + boolean ok = t.call(); 31.73 + if (!ok) 31.74 + throw new Error("compilation failed"); 31.75 + } 31.76 + 31.77 + @Override 31.78 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 31.79 + Trees trees = Trees.instance(processingEnv); 31.80 + if (round++ == 0) { 31.81 + for (Element e: roundEnv.getRootElements()) { 31.82 + TreePath p = trees.getPath(e); 31.83 + new Scanner().scan(p, trees); 31.84 + } 31.85 + } 31.86 + return false; 31.87 + } 31.88 + 31.89 + @Override 31.90 + public SourceVersion getSupportedSourceVersion() { 31.91 + return SourceVersion.latest(); 31.92 + } 31.93 + 31.94 + int round; 31.95 + 31.96 + static class Scanner extends TreePathScanner<Void,Trees> { 31.97 + @Override 31.98 + public Void visitIdentifier(IdentifierTree t, Trees trees) { 31.99 + System.err.println("visitIdentifier: " + t); 31.100 + trees.getScope(getCurrentPath()); 31.101 + return null; 31.102 + } 31.103 + } 31.104 +}
32.1 --- a/test/tools/javac/diags/ArgTypeCompilerFactory.java Thu Sep 29 18:54:01 2011 -0700 32.2 +++ b/test/tools/javac/diags/ArgTypeCompilerFactory.java Mon Oct 03 18:26:59 2011 -0700 32.3 @@ -146,9 +146,9 @@ 32.4 JavacFileManager.preRegister(c); // can't create it until Log has been set up 32.5 ArgTypeJavaCompiler.preRegister(c); 32.6 ArgTypeMessages.preRegister(c); 32.7 - int result = main.compile(args.toArray(new String[args.size()]), c); 32.8 + Main.Result result = main.compile(args.toArray(new String[args.size()]), c); 32.9 32.10 - return (result == 0); 32.11 + return result.isOK(); 32.12 } 32.13 } 32.14 32.15 @@ -172,10 +172,10 @@ 32.16 JavacFileManager.preRegister(c); // can't create it until Log has been set up 32.17 ArgTypeJavaCompiler.preRegister(c); 32.18 ArgTypeMessages.preRegister(c); 32.19 - com.sun.tools.javac.main.Main m = new com.sun.tools.javac.main.Main("javac", out); 32.20 - int rc = m.compile(args.toArray(new String[args.size()]), c); 32.21 + Main m = new Main("javac", out); 32.22 + Main.Result result = m.compile(args.toArray(new String[args.size()]), c); 32.23 32.24 - return (rc == 0); 32.25 + return result.isOK(); 32.26 } 32.27 32.28 }
33.1 --- a/test/tools/javac/diags/Example.java Thu Sep 29 18:54:01 2011 -0700 33.2 +++ b/test/tools/javac/diags/Example.java Mon Oct 03 18:26:59 2011 -0700 33.3 @@ -41,6 +41,7 @@ 33.4 33.5 import com.sun.tools.javac.api.ClientCodeWrapper; 33.6 import com.sun.tools.javac.file.JavacFileManager; 33.7 +import com.sun.tools.javac.main.Main; 33.8 import com.sun.tools.javac.util.Context; 33.9 import com.sun.tools.javac.util.JavacMessages; 33.10 import com.sun.tools.javac.util.JCDiagnostic; 33.11 @@ -515,14 +516,14 @@ 33.12 Context c = new Context(); 33.13 JavacFileManager.preRegister(c); // can't create it until Log has been set up 33.14 MessageTracker.preRegister(c, keys); 33.15 - com.sun.tools.javac.main.Main m = new com.sun.tools.javac.main.Main("javac", pw); 33.16 - int rc = m.compile(args.toArray(new String[args.size()]), c); 33.17 + Main m = new Main("javac", pw); 33.18 + Main.Result rc = m.compile(args.toArray(new String[args.size()]), c); 33.19 33.20 if (keys != null) { 33.21 pw.close(); 33.22 } 33.23 33.24 - return (rc == 0); 33.25 + return rc.isOK(); 33.26 } 33.27 33.28 static class MessageTracker extends JavacMessages {
34.1 --- a/test/tools/javac/diags/examples.not-yet.txt Thu Sep 29 18:54:01 2011 -0700 34.2 +++ b/test/tools/javac/diags/examples.not-yet.txt Mon Oct 03 18:26:59 2011 -0700 34.3 @@ -60,7 +60,7 @@ 34.4 compiler.misc.fatal.err.cant.locate.ctor # Resolve, from Lower 34.5 compiler.misc.fatal.err.cant.locate.field # Resolve, from Lower 34.6 compiler.misc.fatal.err.cant.locate.meth # Resolve, from Lower 34.7 -compiler.misc.fatal.err.cant.close.loader # JavacProcessingEnvironment 34.8 +compiler.misc.fatal.err.cant.close # JavaCompiler 34.9 compiler.misc.file.does.not.contain.package 34.10 compiler.misc.illegal.start.of.class.file 34.11 compiler.misc.kindname.annotation
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/test/tools/javac/diags/examples/AlreadyDefinedClinit.java Mon Oct 03 18:26:59 2011 -0700 35.3 @@ -0,0 +1,31 @@ 35.4 +/* 35.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 35.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 35.7 + * 35.8 + * This code is free software; you can redistribute it and/or modify it 35.9 + * under the terms of the GNU General Public License version 2 only, as 35.10 + * published by the Free Software Foundation. 35.11 + * 35.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 35.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 35.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 35.15 + * version 2 for more details (a copy is included in the LICENSE file that 35.16 + * accompanied this code). 35.17 + * 35.18 + * You should have received a copy of the GNU General Public License version 35.19 + * 2 along with this work; if not, write to the Free Software Foundation, 35.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 35.21 + * 35.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 35.23 + * or visit www.oracle.com if you need additional information or have any 35.24 + * questions. 35.25 + */ 35.26 + 35.27 +// key: compiler.err.already.defined.in.clinit 35.28 + 35.29 +class AlreadyDefinedClinit { 35.30 + static { 35.31 + int i; 35.32 + int i; 35.33 + } 35.34 +}
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 36.2 +++ b/test/tools/javac/diags/examples/IncompatibleUpperBounds.java Mon Oct 03 18:26:59 2011 -0700 36.3 @@ -0,0 +1,38 @@ 36.4 +/* 36.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 36.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 36.7 + * 36.8 + * This code is free software; you can redistribute it and/or modify it 36.9 + * under the terms of the GNU General Public License version 2 only, as 36.10 + * published by the Free Software Foundation. 36.11 + * 36.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 36.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 36.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 36.15 + * version 2 for more details (a copy is included in the LICENSE file that 36.16 + * accompanied this code). 36.17 + * 36.18 + * You should have received a copy of the GNU General Public License version 36.19 + * 2 along with this work; if not, write to the Free Software Foundation, 36.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 36.21 + * 36.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 36.23 + * or visit www.oracle.com if you need additional information or have any 36.24 + * questions. 36.25 + */ 36.26 + 36.27 +//key: compiler.err.cant.apply.symbols 36.28 +//key: compiler.misc.inapplicable.method 36.29 +//key: compiler.misc.arg.length.mismatch 36.30 +//key: compiler.misc.incompatible.upper.bounds 36.31 + 36.32 +import java.util.List; 36.33 + 36.34 +class IncompatibleUpperBounds { 36.35 + <S> void m(List<? super S> s1, List<? super S> s2) { } 36.36 + void m(Object o) {} 36.37 + 36.38 + void test(List<Integer> li, List<String> ls) { 36.39 + m(li, ls); 36.40 + } 36.41 +}
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 37.2 +++ b/test/tools/javac/diags/examples/KindnameInstanceInit.java Mon Oct 03 18:26:59 2011 -0700 37.3 @@ -0,0 +1,37 @@ 37.4 +/* 37.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 37.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 37.7 + * 37.8 + * This code is free software; you can redistribute it and/or modify it 37.9 + * under the terms of the GNU General Public License version 2 only, as 37.10 + * published by the Free Software Foundation. 37.11 + * 37.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 37.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 37.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 37.15 + * version 2 for more details (a copy is included in the LICENSE file that 37.16 + * accompanied this code). 37.17 + * 37.18 + * You should have received a copy of the GNU General Public License version 37.19 + * 2 along with this work; if not, write to the Free Software Foundation, 37.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 37.21 + * 37.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 37.23 + * or visit www.oracle.com if you need additional information or have any 37.24 + * questions. 37.25 + */ 37.26 + 37.27 +// key: compiler.err.already.defined.in.clinit 37.28 +// key: compiler.misc.kindname.instance.init 37.29 +// key: compiler.misc.kindname.class 37.30 +// key: compiler.misc.kindname.variable 37.31 +// key: compiler.misc.count.error 37.32 +// key: compiler.err.error 37.33 +// run: backdoor 37.34 + 37.35 +class KindnameInstanceInit { 37.36 + { 37.37 + int i; 37.38 + int i; 37.39 + } 37.40 +}
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/test/tools/javac/diags/examples/KindnameStaticInit.java Mon Oct 03 18:26:59 2011 -0700 38.3 @@ -0,0 +1,37 @@ 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 +// key: compiler.err.already.defined.in.clinit 38.28 +// key: compiler.misc.kindname.static.init 38.29 +// key: compiler.misc.kindname.class 38.30 +// key: compiler.misc.kindname.variable 38.31 +// key: compiler.misc.count.error 38.32 +// key: compiler.err.error 38.33 +// run: backdoor 38.34 + 38.35 +class KindnameStaticInit { 38.36 + static { 38.37 + int i; 38.38 + int i; 38.39 + } 38.40 +}
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/test/tools/javac/file/T7068437.java Mon Oct 03 18:26:59 2011 -0700 39.3 @@ -0,0 +1,136 @@ 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 7068437 39.30 + * @summary Filer.getResource(SOURCE_OUTPUT, ...) no longer works in JDK 7 w/o -s 39.31 + */ 39.32 + 39.33 +import java.io.FileNotFoundException; 39.34 +import java.io.IOException; 39.35 +import java.io.Writer; 39.36 +import java.util.Arrays; 39.37 +import java.util.Collections; 39.38 +import java.util.Map; 39.39 +import java.util.Set; 39.40 +import javax.annotation.processing.AbstractProcessor; 39.41 +import javax.annotation.processing.Filer; 39.42 +import javax.annotation.processing.Messager; 39.43 +import javax.annotation.processing.RoundEnvironment; 39.44 +import javax.annotation.processing.SupportedAnnotationTypes; 39.45 +import javax.annotation.processing.SupportedOptions; 39.46 +import javax.annotation.processing.SupportedSourceVersion; 39.47 +import javax.lang.model.SourceVersion; 39.48 +import javax.lang.model.element.TypeElement; 39.49 +import javax.tools.Diagnostic.Kind; 39.50 +import javax.tools.JavaCompiler; 39.51 +import javax.tools.JavaCompiler.CompilationTask; 39.52 +import javax.tools.StandardLocation; 39.53 +import javax.tools.ToolProvider; 39.54 + 39.55 +public class T7068437 { 39.56 + public static void main(String[] args) throws Exception { 39.57 + new T7068437().run(); 39.58 + } 39.59 + 39.60 + void run() throws Exception { 39.61 + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 39.62 + System.err.println("using " + compiler.getClass() 39.63 + + " from " + compiler.getClass().getProtectionDomain().getCodeSource()); 39.64 + 39.65 + CompilationTask task = compiler.getTask(null, null, null, 39.66 + Collections.singleton("-proc:only"), 39.67 + Collections.singleton("java.lang.Object"), 39.68 + null); 39.69 + task.setProcessors(Collections.singleton(new Proc())); 39.70 + check("compilation", task.call()); 39.71 + 39.72 + task = compiler.getTask(null, null, null, 39.73 + Arrays.asList("-proc:only", "-AexpectFile"), 39.74 + Collections.singleton("java.lang.Object"), 39.75 + null); 39.76 + task.setProcessors(Collections.singleton(new Proc())); 39.77 + check("compilation", task.call()); 39.78 + } 39.79 + 39.80 + void check(String msg, boolean ok) { 39.81 + System.err.println(msg + ": " + (ok ? "ok" : "failed")); 39.82 + if (!ok) 39.83 + throw new AssertionError(msg); 39.84 + } 39.85 + 39.86 + @SupportedAnnotationTypes("*") 39.87 + @SupportedOptions("expectFile") 39.88 + private static class Proc extends AbstractProcessor { 39.89 + int count; 39.90 + 39.91 + @Override 39.92 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 39.93 + if (roundEnv.processingOver() || count++ > 0) { 39.94 + return false; 39.95 + } 39.96 + 39.97 + Filer filer = processingEnv.getFiler(); 39.98 + Messager messager = processingEnv.getMessager(); 39.99 + Map<String, String> options = processingEnv.getOptions(); 39.100 + System.err.println(options); 39.101 + boolean expectFile = options.containsKey("expectFile"); 39.102 + 39.103 + System.err.println("running Proc: expectFile=" + expectFile); 39.104 + 39.105 + boolean found; 39.106 + try { 39.107 + messager.printMessage(Kind.NOTE, "found previous content of length " + 39.108 + filer.getResource(StandardLocation.SOURCE_OUTPUT, "p", "C.java").getCharContent(false).length()); 39.109 + found = true; 39.110 + } catch (FileNotFoundException x) { 39.111 + messager.printMessage(Kind.NOTE, "not previously there"); 39.112 + found = false; 39.113 + } catch (IOException x) { 39.114 + messager.printMessage(Kind.ERROR, "while reading: " + x); 39.115 + found = false; 39.116 + } 39.117 + 39.118 + if (expectFile && !found) { 39.119 + messager.printMessage(Kind.ERROR, "expected file but file not found"); 39.120 + } 39.121 + 39.122 + try { 39.123 + Writer w = filer.createSourceFile("p.C").openWriter(); 39.124 + w.write("/* hello! */ package p; class C {}"); 39.125 + w.close(); 39.126 + messager.printMessage(Kind.NOTE, "wrote new content"); 39.127 + } catch (IOException x) { 39.128 + messager.printMessage(Kind.ERROR, "while writing: " + x); 39.129 + } 39.130 + 39.131 + return true; 39.132 + } 39.133 + 39.134 + @Override 39.135 + public SourceVersion getSupportedSourceVersion() { 39.136 + return SourceVersion.latest(); 39.137 + } 39.138 + } 39.139 +}
40.1 --- a/test/tools/javac/generics/6910550/T6910550d.out Thu Sep 29 18:54:01 2011 -0700 40.2 +++ b/test/tools/javac/generics/6910550/T6910550d.out Mon Oct 03 18:26:59 2011 -0700 40.3 @@ -1,2 +1,2 @@ 40.4 -T6910550d.java:12:14: compiler.err.already.defined: <X>m(X), T6910550d 40.5 +T6910550d.java:12:14: compiler.err.already.defined: kindname.method, <X>m(X), kindname.class, T6910550d 40.6 1 error
41.1 --- a/test/tools/javac/generics/inference/6638712/T6638712a.out Thu Sep 29 18:54:01 2011 -0700 41.2 +++ b/test/tools/javac/generics/inference/6638712/T6638712a.out Mon Oct 03 18:26:59 2011 -0700 41.3 @@ -1,2 +1,2 @@ 41.4 -T6638712a.java:16:41: compiler.err.prob.found.req: (compiler.misc.incompatible.types.1: (compiler.misc.infer.no.conforming.instance.exists: T, java.util.Comparator<T>, java.util.Comparator<java.lang.String>)), <T>java.util.Comparator<T>, java.util.Comparator<java.lang.String> 41.5 +T6638712a.java:16:33: compiler.err.cant.apply.symbol.1: kindname.method, compound, java.lang.Iterable<? extends java.util.Comparator<? super T>>, java.util.List<java.util.Comparator<?>>, kindname.class, T6638712a, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<java.util.Comparator<?>>, java.lang.Iterable<? extends java.util.Comparator<? super T>>) 41.6 1 error
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 42.2 +++ b/test/tools/javac/generics/inference/7086586/T7086586.java Mon Oct 03 18:26:59 2011 -0700 42.3 @@ -0,0 +1,19 @@ 42.4 +/** 42.5 + * @test /nodynamiccopyright/ 42.6 + * @bug 7086586 42.7 + * @summary Inference producing null type argument 42.8 + * @compile/fail/ref=T7086586.out -XDrawDiagnostics T7086586.java 42.9 + */ 42.10 +import java.util.List; 42.11 + 42.12 +class T7086586 { 42.13 + 42.14 + <T> List<T> m(List<? super T> dummy) { return null; } 42.15 + 42.16 + void test(List<?> l) { 42.17 + String s = m(l).get(0); 42.18 + Number n = m(l).get(0); 42.19 + Exception e = m(l).get(0); 42.20 + m(l).nonExistentMethod(); 42.21 + } 42.22 +}
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 43.2 +++ b/test/tools/javac/generics/inference/7086586/T7086586.out Mon Oct 03 18:26:59 2011 -0700 43.3 @@ -0,0 +1,5 @@ 43.4 +T7086586.java:14:20: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>) 43.5 +T7086586.java:15:20: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>) 43.6 +T7086586.java:16:23: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>) 43.7 +T7086586.java:17:9: compiler.err.cant.apply.symbol.1: kindname.method, m, java.util.List<? super T>, java.util.List<compiler.misc.type.captureof: 1, ?>, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, java.util.List<compiler.misc.type.captureof: 1, ?>, java.util.List<? super T>) 43.8 +4 errors
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 44.2 +++ b/test/tools/javac/generics/inference/7086586/T7086586b.java Mon Oct 03 18:26:59 2011 -0700 44.3 @@ -0,0 +1,54 @@ 44.4 +/* 44.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 44.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 44.7 + * 44.8 + * This code is free software; you can redistribute it and/or modify it 44.9 + * under the terms of the GNU General Public License version 2 only, as 44.10 + * published by the Free Software Foundation. 44.11 + * 44.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 44.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 44.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 44.15 + * version 2 for more details (a copy is included in the LICENSE file that 44.16 + * accompanied this code). 44.17 + * 44.18 + * You should have received a copy of the GNU General Public License version 44.19 + * 2 along with this work; if not, write to the Free Software Foundation, 44.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 44.21 + * 44.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 44.23 + * or visit www.oracle.com if you need additional information or have any 44.24 + * questions. 44.25 + */ 44.26 + 44.27 +/* 44.28 + * @test 44.29 + * @bug 7086586 44.30 + * 44.31 + * @summary Inference producing null type argument 44.32 + */ 44.33 +import java.util.List; 44.34 + 44.35 +public class T7086586b { 44.36 + 44.37 + int assertionCount = 0; 44.38 + 44.39 + void assertTrue(boolean cond) { 44.40 + if (!cond) { 44.41 + throw new AssertionError(); 44.42 + } 44.43 + assertionCount++; 44.44 + } 44.45 + 44.46 + <T> void m(List<? super T> dummy) { assertTrue(false); } 44.47 + <T> void m(Object dummy) { assertTrue(true); } 44.48 + 44.49 + void test(List<?> l) { 44.50 + m(l); 44.51 + assertTrue(assertionCount == 1); 44.52 + } 44.53 + 44.54 + public static void main(String[] args) { 44.55 + new T7086586b().test(null); 44.56 + } 44.57 +}
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 45.2 +++ b/test/tools/javac/generics/inference/7086601/T7086601a.java Mon Oct 03 18:26:59 2011 -0700 45.3 @@ -0,0 +1,34 @@ 45.4 +/** 45.5 + * @test /nodynamiccopyright/ 45.6 + * @bug 7086601 45.7 + * @summary Error message bug: cause for method mismatch is 'null' 45.8 + * @compile/fail/ref=T7086601a.out -XDrawDiagnostics T7086601a.java 45.9 + */ 45.10 + 45.11 +class T7086601 { 45.12 + static <S> void m1(Iterable<? super S> s1, Iterable<? super S> s2) { } 45.13 + static void m1(Object o) {} 45.14 + 45.15 + static <S> void m2(Iterable<? super S> s1, Iterable<? super S> s2, Iterable<? super S> s3) { } 45.16 + static void m2(Object o) {} 45.17 + 45.18 + @SafeVarargs 45.19 + static <S> void m3(Iterable<? super S>... ss) { } 45.20 + static void m3(Object o) {} 45.21 + 45.22 + static void test1(Iterable<String> is, Iterable<Integer> ii) { 45.23 + m1(is, ii); 45.24 + } 45.25 + 45.26 + static void test2(Iterable<String> is, Iterable<Integer> ii, Iterable<Double> id) { 45.27 + m2(is, ii, id); 45.28 + } 45.29 + 45.30 + static void test3(Iterable<String> is, Iterable<Integer> ii) { 45.31 + m3(is, ii); 45.32 + } 45.33 + 45.34 + static void test4(Iterable<String> is, Iterable<Integer> ii, Iterable<Double> id) { 45.35 + m3(is, ii, id); 45.36 + } 45.37 +}
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 46.2 +++ b/test/tools/javac/generics/inference/7086601/T7086601a.out Mon Oct 03 18:26:59 2011 -0700 46.3 @@ -0,0 +1,5 @@ 46.4 +T7086601a.java:20:9: compiler.err.cant.apply.symbols: kindname.method, m1, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m1(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m1(java.lang.Iterable<? super S>,java.lang.Iterable<? super S>), (compiler.misc.incompatible.upper.bounds: S, java.lang.Integer,java.lang.String))} 46.5 +T7086601a.java:24:9: compiler.err.cant.apply.symbols: kindname.method, m2, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,java.lang.Iterable<java.lang.Double>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m2(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m2(java.lang.Iterable<? super S>,java.lang.Iterable<? super S>,java.lang.Iterable<? super S>), (compiler.misc.incompatible.upper.bounds: S, java.lang.Double,java.lang.Integer,java.lang.String))} 46.6 +T7086601a.java:28:9: compiler.err.cant.apply.symbols: kindname.method, m3, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m3(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m3(java.lang.Iterable<? super S>...), (compiler.misc.incompatible.upper.bounds: S, java.lang.Integer,java.lang.String))} 46.7 +T7086601a.java:32:9: compiler.err.cant.apply.symbols: kindname.method, m3, java.lang.Iterable<java.lang.String>,java.lang.Iterable<java.lang.Integer>,java.lang.Iterable<java.lang.Double>,{(compiler.misc.inapplicable.method: kindname.method, T7086601, m3(java.lang.Object), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.method, T7086601, <S>m3(java.lang.Iterable<? super S>...), (compiler.misc.incompatible.upper.bounds: S, java.lang.Double,java.lang.Integer,java.lang.String))} 46.8 +4 errors
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 47.2 +++ b/test/tools/javac/generics/inference/7086601/T7086601b.java Mon Oct 03 18:26:59 2011 -0700 47.3 @@ -0,0 +1,199 @@ 47.4 +/* 47.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 47.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 47.7 + * 47.8 + * This code is free software; you can redistribute it and/or modify it 47.9 + * under the terms of the GNU General Public License version 2 only, as 47.10 + * published by the Free Software Foundation. 47.11 + * 47.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 47.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 47.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 47.15 + * version 2 for more details (a copy is included in the LICENSE file that 47.16 + * accompanied this code). 47.17 + * 47.18 + * You should have received a copy of the GNU General Public License version 47.19 + * 2 along with this work; if not, write to the Free Software Foundation, 47.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 47.21 + * 47.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 47.23 + * or visit www.oracle.com if you need additional information or have any 47.24 + * questions. 47.25 + */ 47.26 + 47.27 +/* 47.28 + * @test 47.29 + * @bug 7086601 47.30 + * @summary Error message bug: cause for method mismatch is 'null' 47.31 + */ 47.32 + 47.33 +import com.sun.source.util.JavacTask; 47.34 +import java.net.URI; 47.35 +import java.util.Arrays; 47.36 +import java.util.ArrayList; 47.37 +import javax.tools.Diagnostic; 47.38 +import javax.tools.JavaCompiler; 47.39 +import javax.tools.JavaFileObject; 47.40 +import javax.tools.SimpleJavaFileObject; 47.41 +import javax.tools.StandardJavaFileManager; 47.42 +import javax.tools.ToolProvider; 47.43 + 47.44 + 47.45 +public class T7086601b { 47.46 + 47.47 + static int checkCount = 0; 47.48 + 47.49 + enum TypeKind { 47.50 + STRING("String", false), 47.51 + INTEGER("Integer", false), 47.52 + NUMBER("Number", false), 47.53 + SERIALIZABLE("java.io.Serializable", true), 47.54 + CLONEABLE("Cloneable", true), 47.55 + X("X", false), 47.56 + Y("Y", false), 47.57 + Z("Z", false); 47.58 + 47.59 + String typeStr; 47.60 + boolean isInterface; 47.61 + 47.62 + private TypeKind(String typeStr, boolean isInterface) { 47.63 + this.typeStr = typeStr; 47.64 + this.isInterface = isInterface; 47.65 + } 47.66 + 47.67 + boolean isSubtypeof(TypeKind other) { 47.68 + return (this == INTEGER && other == NUMBER || 47.69 + this == Z && other == Y || 47.70 + this == other); 47.71 + } 47.72 + } 47.73 + 47.74 + enum MethodCallKind { 47.75 + ARITY_ONE("m(a1);", 1), 47.76 + ARITY_TWO("m(a1, a2);", 2), 47.77 + ARITY_THREE("m(a1, a2, a3);", 3); 47.78 + 47.79 + String invokeString; 47.80 + int arity; 47.81 + 47.82 + private MethodCallKind(String invokeString, int arity) { 47.83 + this.invokeString = invokeString; 47.84 + this.arity = arity; 47.85 + } 47.86 + } 47.87 + 47.88 + public static void main(String... args) throws Exception { 47.89 + 47.90 + //create default shared JavaCompiler - reused across multiple compilations 47.91 + JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); 47.92 + StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); 47.93 + 47.94 + for (TypeKind a1 : TypeKind.values()) { 47.95 + for (TypeKind a2 : TypeKind.values()) { 47.96 + for (TypeKind a3 : TypeKind.values()) { 47.97 + for (MethodCallKind mck : MethodCallKind.values()) { 47.98 + new T7086601b(a1, a2, a3, mck).run(comp, fm); 47.99 + } 47.100 + } 47.101 + } 47.102 + } 47.103 + System.out.println("Total check executed: " + checkCount); 47.104 + } 47.105 + 47.106 + TypeKind a1; 47.107 + TypeKind a2; 47.108 + TypeKind a3; 47.109 + MethodCallKind mck; 47.110 + JavaSource source; 47.111 + DiagnosticChecker diagChecker; 47.112 + 47.113 + T7086601b(TypeKind a1, TypeKind a2, TypeKind a3, MethodCallKind mck) { 47.114 + this.a1 = a1; 47.115 + this.a2 = a2; 47.116 + this.a3 = a3; 47.117 + this.mck = mck; 47.118 + this.source = new JavaSource(); 47.119 + this.diagChecker = new DiagnosticChecker(); 47.120 + } 47.121 + 47.122 + class JavaSource extends SimpleJavaFileObject { 47.123 + 47.124 + final String bodyTemplate = "import java.util.List;\n"+ 47.125 + "class Test {\n" + 47.126 + " <Z> void m(List<? super Z> l1) { }\n" + 47.127 + " <Z> void m(List<? super Z> l1, List<? super Z> l2) { }\n" + 47.128 + " <Z> void m(List<? super Z> l1, List<? super Z> l2, List<? super Z> l3) { }\n" + 47.129 + " <X,Y,Z extends Y> void test(List<#A1> a1, List<#A2> a2, List<#A3> a3) { #MC } }"; 47.130 + 47.131 + String source; 47.132 + 47.133 + public JavaSource() { 47.134 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 47.135 + source = bodyTemplate.replace("#A1", a1.typeStr) 47.136 + .replace("#A2", a2.typeStr).replace("#A3", a3.typeStr) 47.137 + .replace("#MC", mck.invokeString); 47.138 + } 47.139 + 47.140 + @Override 47.141 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 47.142 + return source; 47.143 + } 47.144 + } 47.145 + 47.146 + void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception { 47.147 + JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker, 47.148 + null, null, Arrays.asList(source)); 47.149 + try { 47.150 + ct.analyze(); 47.151 + } catch (Throwable ex) { 47.152 + throw new AssertionError("Error thron when compiling the following code:\n" + source.getCharContent(true)); 47.153 + } 47.154 + check(); 47.155 + } 47.156 + 47.157 + void check() { 47.158 + checkCount++; 47.159 + 47.160 + boolean errorExpected = false; 47.161 + 47.162 + if (mck.arity > 1) { 47.163 + TypeKind[] argtypes = { a1, a2, a3 }; 47.164 + ArrayList<TypeKind> classes = new ArrayList<>(); 47.165 + for (int i = 0 ; i < mck.arity ; i ++ ) { 47.166 + if (!argtypes[i].isInterface) { 47.167 + classes.add(argtypes[i]); 47.168 + } 47.169 + } 47.170 + boolean glb_exists = true; 47.171 + for (TypeKind arg_i : classes) { 47.172 + glb_exists = true; 47.173 + for (TypeKind arg_j : classes) { 47.174 + if (!arg_i.isSubtypeof(arg_j)) { 47.175 + glb_exists = false; 47.176 + break; 47.177 + } 47.178 + } 47.179 + if (glb_exists) break; 47.180 + } 47.181 + errorExpected = !glb_exists; 47.182 + } 47.183 + 47.184 + if (errorExpected != diagChecker.errorFound) { 47.185 + throw new Error("invalid diagnostics for source:\n" + 47.186 + source.getCharContent(true) + 47.187 + "\nFound error: " + diagChecker.errorFound + 47.188 + "\nExpected error: " + errorExpected); 47.189 + } 47.190 + } 47.191 + 47.192 + static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { 47.193 + 47.194 + boolean errorFound; 47.195 + 47.196 + public void report(Diagnostic<? extends JavaFileObject> diagnostic) { 47.197 + if (diagnostic.getKind() == Diagnostic.Kind.ERROR) { 47.198 + errorFound = true; 47.199 + } 47.200 + } 47.201 + } 47.202 +}
48.1 --- a/test/tools/javac/lib/CompileFail.java Thu Sep 29 18:54:01 2011 -0700 48.2 +++ b/test/tools/javac/lib/CompileFail.java Mon Oct 03 18:26:59 2011 -0700 48.3 @@ -23,6 +23,7 @@ 48.4 48.5 import java.io.*; 48.6 import java.util.*; 48.7 +import com.sun.tools.javac.main.Main; 48.8 48.9 /* 48.10 * Utility class to emulate jtreg @compile/fail, but also checking the specific 48.11 @@ -58,32 +59,7 @@ 48.12 } 48.13 48.14 static int getReturnCode(String name) { 48.15 - switch (name) { 48.16 - case "OK": 48.17 - return EXIT_OK; 48.18 - 48.19 - case "ERROR": 48.20 - return EXIT_ERROR; 48.21 - 48.22 - case "CMDERR": 48.23 - return EXIT_CMDERR; 48.24 - 48.25 - case "SYSERR": 48.26 - return EXIT_SYSERR; 48.27 - 48.28 - case "ABNORMAL": 48.29 - return EXIT_ABNORMAL; 48.30 - 48.31 - default: 48.32 - throw new IllegalArgumentException(name); 48.33 - } 48.34 + return Main.Result.valueOf(name).exitCode; 48.35 } 48.36 48.37 - // The following is cut-n-paste from com.sun.tools.javac.main.Main 48.38 - static final int 48.39 - EXIT_OK = 0, // Compilation completed with no errors. 48.40 - EXIT_ERROR = 1, // Completed but reported errors. 48.41 - EXIT_CMDERR = 2, // Bad command-line arguments 48.42 - EXIT_SYSERR = 3, // System error or resource exhaustion. 48.43 - EXIT_ABNORMAL = 4; // Compiler terminated abnormally 48.44 }
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/test/tools/javac/processing/loader/testClose/TestClose.java Mon Oct 03 18:26:59 2011 -0700 49.3 @@ -0,0 +1,229 @@ 49.4 +/* 49.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 49.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 49.7 + * 49.8 + * This code is free software; you can redistribute it and/or modify it 49.9 + * under the terms of the GNU General Public License version 2 only, as 49.10 + * published by the Free Software Foundation. 49.11 + * 49.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 49.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 49.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 49.15 + * version 2 for more details (a copy is included in the LICENSE file that 49.16 + * accompanied this code). 49.17 + * 49.18 + * You should have received a copy of the GNU General Public License version 49.19 + * 2 along with this work; if not, write to the Free Software Foundation, 49.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 49.21 + * 49.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 49.23 + * or visit www.oracle.com if you need additional information or have any 49.24 + * questions. 49.25 + */ 49.26 + 49.27 +/* 49.28 + * @test 49.29 + * @bug 7092965 49.30 + * @summary javac should not close processorClassLoader before end of compilation 49.31 + */ 49.32 + 49.33 +import com.sun.source.util.JavacTask; 49.34 +import com.sun.source.util.TaskEvent; 49.35 +import com.sun.source.util.TaskListener; 49.36 +import com.sun.tools.javac.api.ClientCodeWrapper.Trusted; 49.37 +import com.sun.tools.javac.api.JavacTool; 49.38 +import com.sun.tools.javac.processing.JavacProcessingEnvironment; 49.39 +import com.sun.tools.javac.util.Context; 49.40 +import java.io.ByteArrayOutputStream; 49.41 +import java.io.File; 49.42 +import java.io.IOException; 49.43 +import java.io.PrintStream; 49.44 +import java.lang.reflect.Field; 49.45 +import java.net.URI; 49.46 +import java.util.ArrayList; 49.47 +import java.util.Arrays; 49.48 +import java.util.Collections; 49.49 +import java.util.List; 49.50 +import javax.annotation.processing.ProcessingEnvironment; 49.51 +import javax.tools.JavaFileObject; 49.52 +import javax.tools.SimpleJavaFileObject; 49.53 +import javax.tools.StandardJavaFileManager; 49.54 +import javax.tools.StandardLocation; 49.55 +import javax.tools.ToolProvider; 49.56 + 49.57 +/* 49.58 + * The test compiles an annotation processor and a helper class into a 49.59 + * custom classes directory. 49.60 + * 49.61 + * It then uses them while compiling a dummy file, with the custom classes 49.62 + * directory on the processor path, thus guaranteeing that references to 49.63 + * these class are satisfied by the processor class loader. 49.64 + * 49.65 + * The annotation processor uses the javac TaskListener to run code 49.66 + * after annotation processing has completed, to verify that the classloader 49.67 + * is not closed until the end of the compilation. 49.68 + */ 49.69 + 49.70 +@Trusted // avoids use of ClientCodeWrapper 49.71 +public class TestClose implements TaskListener { 49.72 + public static final String annoProc = 49.73 + "import java.util.*;\n" + 49.74 + "import javax.annotation.processing.*;\n" + 49.75 + "import javax.lang.model.*;\n" + 49.76 + "import javax.lang.model.element.*;\n" + 49.77 + "import com.sun.source.util.*;\n" + 49.78 + "import com.sun.tools.javac.processing.*;\n" + 49.79 + "import com.sun.tools.javac.util.*;\n" + 49.80 + "@SupportedAnnotationTypes(\"*\")\n" + 49.81 + "public class AnnoProc extends AbstractProcessor {\n" + 49.82 + " @Override\n" + 49.83 + " public SourceVersion getSupportedSourceVersion() {\n" + 49.84 + " return SourceVersion.latest();\n" + 49.85 + " }\n" + 49.86 + " @Override\n" + 49.87 + " public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {\n" + 49.88 + " System.out.println(\"in AnnoProc.process\");\n" + 49.89 + " final ClassLoader cl = getClass().getClassLoader();\n" + 49.90 + " if (roundEnv.processingOver()) {\n" + 49.91 + " TestClose.add(processingEnv, new Runnable() {\n" + 49.92 + " public void run() {\n" + 49.93 + " System.out.println(getClass().getName() + \": run()\");\n" + 49.94 + " try {\n" + 49.95 + " cl.loadClass(\"Callback\")\n" + 49.96 + " .asSubclass(Runnable.class)\n" + 49.97 + " .newInstance()\n" + 49.98 + " .run();\n" + 49.99 + " } catch (ReflectiveOperationException e) {\n" + 49.100 + " throw new Error(e);\n" + 49.101 + " }\n" + 49.102 + " }\n" + 49.103 + " });\n" + 49.104 + " }\n" + 49.105 + " return true;\n" + 49.106 + " }\n" + 49.107 + "}\n"; 49.108 + 49.109 + public static final String callback = 49.110 + "public class Callback implements Runnable {\n" + 49.111 + " public void run() {\n" + 49.112 + " System.out.println(getClass().getName() + \": run()\");\n" + 49.113 + " }\n" + 49.114 + "}"; 49.115 + 49.116 + public static void main(String... args) throws Exception { 49.117 + new TestClose().run(); 49.118 + } 49.119 + 49.120 + void run() throws IOException { 49.121 + JavacTool tool = (JavacTool) ToolProvider.getSystemJavaCompiler(); 49.122 + StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); 49.123 + 49.124 + File classes = new File("classes"); 49.125 + classes.mkdirs(); 49.126 + File extraClasses = new File("extraClasses"); 49.127 + extraClasses.mkdirs(); 49.128 + 49.129 + System.out.println("compiling classes to extraClasses"); 49.130 + { // setup class in extraClasses 49.131 + fm.setLocation(StandardLocation.CLASS_OUTPUT, 49.132 + Collections.singleton(extraClasses)); 49.133 + List<? extends JavaFileObject> files = Arrays.asList( 49.134 + new MemFile("AnnoProc.java", annoProc), 49.135 + new MemFile("Callback.java", callback)); 49.136 + JavacTask task = tool.getTask(null, fm, null, null, null, files); 49.137 + check(task.call()); 49.138 + } 49.139 + 49.140 + System.out.println("compiling dummy to classes with anno processor"); 49.141 + { // use that class in a TaskListener after processing has completed 49.142 + PrintStream prev = System.out; 49.143 + String out; 49.144 + ByteArrayOutputStream baos = new ByteArrayOutputStream(); 49.145 + try (PrintStream ps = new PrintStream(baos)) { 49.146 + System.setOut(ps); 49.147 + File testClasses = new File(System.getProperty("test.classes")); 49.148 + fm.setLocation(StandardLocation.CLASS_OUTPUT, 49.149 + Collections.singleton(classes)); 49.150 + fm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, 49.151 + Arrays.asList(extraClasses, testClasses)); 49.152 + List<? extends JavaFileObject> files = Arrays.asList( 49.153 + new MemFile("my://dummy", "class Dummy { }")); 49.154 + List<String> options = Arrays.asList("-processor", "AnnoProc"); 49.155 + JavacTask task = tool.getTask(null, fm, null, options, null, files); 49.156 + task.setTaskListener(this); 49.157 + check(task.call()); 49.158 + } finally { 49.159 + System.setOut(prev); 49.160 + out = baos.toString(); 49.161 + if (!out.isEmpty()) 49.162 + System.out.println(out); 49.163 + } 49.164 + check(out.contains("AnnoProc$1: run()")); 49.165 + check(out.contains("Callback: run()")); 49.166 + } 49.167 + } 49.168 + 49.169 + @Override 49.170 + public void started(TaskEvent e) { 49.171 + System.out.println("Started: " + e); 49.172 + } 49.173 + 49.174 + @Override 49.175 + public void finished(TaskEvent e) { 49.176 + System.out.println("Finished: " + e); 49.177 + if (e.getKind() == TaskEvent.Kind.ANALYZE) { 49.178 + for (Runnable r: runnables) { 49.179 + System.out.println("running " + r); 49.180 + r.run(); 49.181 + } 49.182 + } 49.183 + } 49.184 + 49.185 + void check(boolean b) { 49.186 + if (!b) 49.187 + throw new AssertionError(); 49.188 + } 49.189 + 49.190 + 49.191 + public static void add(ProcessingEnvironment env, Runnable r) { 49.192 + try { 49.193 + Context c = ((JavacProcessingEnvironment) env).getContext(); 49.194 + Object o = c.get(TaskListener.class); 49.195 + // The TaskListener is an instanceof TestClose, but when using the 49.196 + // default class loaders. the taskListener uses a different 49.197 + // instance of Class<TestClose> than the anno processor. 49.198 + // If you try to evaluate 49.199 + // TestClose tc = (TestClose) (o). 49.200 + // you get the following somewhat confusing error: 49.201 + // java.lang.ClassCastException: TestClose cannot be cast to TestClose 49.202 + // The workaround is to access the fields of TestClose with reflection. 49.203 + Field f = o.getClass().getField("runnables"); 49.204 + @SuppressWarnings("unchecked") 49.205 + List<Runnable> runnables = (List<Runnable>) f.get(o); 49.206 + runnables.add(r); 49.207 + } catch (Throwable t) { 49.208 + System.err.println(t); 49.209 + } 49.210 + } 49.211 + 49.212 + public List<Runnable> runnables = new ArrayList<>(); 49.213 + 49.214 + class MemFile extends SimpleJavaFileObject { 49.215 + public final String text; 49.216 + 49.217 + MemFile(String name, String text) { 49.218 + super(URI.create(name), JavaFileObject.Kind.SOURCE); 49.219 + this.text = text; 49.220 + } 49.221 + 49.222 + @Override 49.223 + public String getName() { 49.224 + return uri.toString(); 49.225 + } 49.226 + 49.227 + @Override 49.228 + public String getCharContent(boolean ignoreEncodingErrors) { 49.229 + return text; 49.230 + } 49.231 + } 49.232 +}
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 50.2 +++ b/test/tools/javac/processing/loader/testClose/TestClose2.java Mon Oct 03 18:26:59 2011 -0700 50.3 @@ -0,0 +1,141 @@ 50.4 +/* 50.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 50.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 50.7 + * 50.8 + * This code is free software; you can redistribute it and/or modify it 50.9 + * under the terms of the GNU General Public License version 2 only, as 50.10 + * published by the Free Software Foundation. 50.11 + * 50.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 50.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 50.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 50.15 + * version 2 for more details (a copy is included in the LICENSE file that 50.16 + * accompanied this code). 50.17 + * 50.18 + * You should have received a copy of the GNU General Public License version 50.19 + * 2 along with this work; if not, write to the Free Software Foundation, 50.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 50.21 + * 50.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 50.23 + * or visit www.oracle.com if you need additional information or have any 50.24 + * questions. 50.25 + */ 50.26 + 50.27 +/* 50.28 + * @test 50.29 + * @bug 7092965 50.30 + * @summary javac should not close processorClassLoader before end of compilation 50.31 + */ 50.32 + 50.33 +import com.sun.source.util.JavacTask; 50.34 +import com.sun.source.util.TaskEvent; 50.35 +import com.sun.source.util.TaskListener; 50.36 +import com.sun.tools.javac.api.JavacTool; 50.37 +import com.sun.tools.javac.file.JavacFileManager; 50.38 +import com.sun.tools.javac.util.Context; 50.39 +import java.io.File; 50.40 +import java.io.IOException; 50.41 +import java.net.URL; 50.42 +import java.net.URLClassLoader; 50.43 +import java.util.Arrays; 50.44 +import java.util.Collections; 50.45 +import java.util.List; 50.46 +import java.util.Set; 50.47 +import javax.annotation.processing.AbstractProcessor; 50.48 +import javax.annotation.processing.Messager; 50.49 +import javax.annotation.processing.RoundEnvironment; 50.50 +import javax.annotation.processing.SupportedAnnotationTypes; 50.51 +import javax.lang.model.SourceVersion; 50.52 +import javax.lang.model.element.TypeElement; 50.53 +import javax.tools.Diagnostic; 50.54 +import javax.tools.JavaFileObject; 50.55 +import javax.tools.StandardJavaFileManager; 50.56 +import javax.tools.StandardLocation; 50.57 +import javax.tools.ToolProvider; 50.58 + 50.59 +@SupportedAnnotationTypes("*") 50.60 +public class TestClose2 extends AbstractProcessor implements TaskListener { 50.61 + 50.62 + public static void main(String... args) throws Exception { 50.63 + new TestClose2().run(); 50.64 + } 50.65 + 50.66 + void run() throws IOException { 50.67 + File testSrc = new File(System.getProperty("test.src")); 50.68 + File testClasses = new File(System.getProperty("test.classes")); 50.69 + 50.70 + JavacTool tool = (JavacTool) ToolProvider.getSystemJavaCompiler(); 50.71 + final ClassLoader cl = getClass().getClassLoader(); 50.72 + Context c = new Context(); 50.73 + StandardJavaFileManager fm = new JavacFileManager(c, true, null) { 50.74 + @Override 50.75 + protected ClassLoader getClassLoader(URL[] urls) { 50.76 + return new URLClassLoader(urls, cl) { 50.77 + @Override 50.78 + public void close() throws IOException { 50.79 + System.err.println(getClass().getName() + " closing"); 50.80 + TestClose2.this.closedCount++; 50.81 + TestClose2.this.closedIsLast = true; 50.82 + super.close(); 50.83 + } 50.84 + }; 50.85 + } 50.86 + }; 50.87 + 50.88 + fm.setLocation(StandardLocation.CLASS_OUTPUT, 50.89 + Collections.singleton(new File("."))); 50.90 + fm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, 50.91 + Collections.singleton(testClasses)); 50.92 + Iterable<? extends JavaFileObject> files = 50.93 + fm.getJavaFileObjects(new File(testSrc, TestClose2.class.getName() + ".java")); 50.94 + List<String> options = Arrays.asList( 50.95 + "-processor", TestClose2.class.getName()); 50.96 + 50.97 + JavacTask task = tool.getTask(null, fm, null, options, null, files); 50.98 + task.setTaskListener(this); 50.99 + 50.100 + if (!task.call()) 50.101 + throw new Error("compilation failed"); 50.102 + 50.103 + if (closedCount == 0) 50.104 + throw new Error("no closing message"); 50.105 + else if (closedCount > 1) 50.106 + throw new Error(closedCount + " closed messages"); 50.107 + 50.108 + if (!closedIsLast) 50.109 + throw new Error("closing message not last"); 50.110 + } 50.111 + 50.112 + // AbstractProcessor methods 50.113 + 50.114 + @Override 50.115 + public SourceVersion getSupportedSourceVersion() { 50.116 + return SourceVersion.latest(); 50.117 + } 50.118 + 50.119 + @Override 50.120 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 50.121 + Messager messager = processingEnv.getMessager(); 50.122 + messager.printMessage(Diagnostic.Kind.NOTE, "processing"); 50.123 + return true; 50.124 + } 50.125 + 50.126 + // TaskListener methods 50.127 + 50.128 + @Override 50.129 + public void started(TaskEvent e) { 50.130 + System.err.println("Started: " + e); 50.131 + closedIsLast = false; 50.132 + } 50.133 + 50.134 + @Override 50.135 + public void finished(TaskEvent e) { 50.136 + System.err.println("Finished: " + e); 50.137 + closedIsLast = false; 50.138 + } 50.139 + 50.140 + // 50.141 + 50.142 + int closedCount = 0; 50.143 + boolean closedIsLast = false; 50.144 +}
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 51.2 +++ b/test/tools/javac/tree/TestToString.java Mon Oct 03 18:26:59 2011 -0700 51.3 @@ -0,0 +1,159 @@ 51.4 +/* 51.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 51.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 51.7 + * 51.8 + * This code is free software; you can redistribute it and/or modify it 51.9 + * under the terms of the GNU General Public License version 2 only, as 51.10 + * published by the Free Software Foundation. 51.11 + * 51.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 51.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 51.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 51.15 + * version 2 for more details (a copy is included in the LICENSE file that 51.16 + * accompanied this code). 51.17 + * 51.18 + * You should have received a copy of the GNU General Public License version 51.19 + * 2 along with this work; if not, write to the Free Software Foundation, 51.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 51.21 + * 51.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 51.23 + * or visit www.oracle.com if you need additional information or have any 51.24 + * questions. 51.25 + */ 51.26 + 51.27 +/* 51.28 + * @test 51.29 + * @bug 7080267 51.30 + * @summary Call to toString() from an ExpressionStatementTree doesn't take in 51.31 + * consideration the ";" at the end 51.32 + */ 51.33 + 51.34 +import com.sun.source.tree.BlockTree; 51.35 +import com.sun.source.tree.CompilationUnitTree; 51.36 +import com.sun.source.tree.StatementTree; 51.37 +import com.sun.source.tree.Tree; 51.38 +import java.io.IOException; 51.39 +import java.net.URI; 51.40 +import java.util.Arrays; 51.41 +import java.util.Collections; 51.42 +import java.util.List; 51.43 +import javax.tools.JavaFileObject; 51.44 +import javax.tools.SimpleJavaFileObject; 51.45 +import javax.tools.StandardJavaFileManager; 51.46 + 51.47 +import com.sun.source.util.JavacTask; 51.48 +import com.sun.source.util.TreeScanner; 51.49 +import com.sun.tools.javac.api.JavacTool; 51.50 + 51.51 +public class TestToString { 51.52 + String[] statements = { 51.53 + "i = i + 1;", 51.54 + "i++;", 51.55 + "m();", 51.56 + ";", 51.57 + "if (i == 0) return;", 51.58 + "while (i > 0) i--;", 51.59 + "{ }", 51.60 + "{ i++; }", 51.61 + "class C { }" 51.62 + }; 51.63 + 51.64 + public static void main(String... args) throws Exception { 51.65 + new TestToString().run(); 51.66 + } 51.67 + 51.68 + void run() throws Exception { 51.69 + for (String s: statements) { 51.70 + test(s); 51.71 + } 51.72 + 51.73 + if (errors > 0) 51.74 + throw new Exception(errors + " errors found"); 51.75 + } 51.76 + 51.77 + void test(String stmt) throws IOException { 51.78 + System.err.println("Test: " + stmt); 51.79 + List<String> options = Collections.<String>emptyList(); 51.80 + List<? extends JavaFileObject> files = Arrays.asList(new JavaSource(stmt)); 51.81 + JavacTask t = tool.getTask(null, fm, null, options, null, files); 51.82 + checkEqual(scan(t.parse()), stmt); 51.83 + } 51.84 + 51.85 + String scan(Iterable<? extends CompilationUnitTree> trees) { 51.86 + class Scanner extends TreeScanner<Void,StringBuilder> { 51.87 + String scan(Iterable<? extends Tree> trees) { 51.88 + StringBuilder sb = new StringBuilder(); 51.89 + scan(trees, sb); 51.90 + return sb.toString(); 51.91 + } 51.92 + @Override 51.93 + public Void scan(Tree tree, StringBuilder sb) { 51.94 + if (print && tree instanceof StatementTree) { 51.95 + sb.append(PREFIX); 51.96 + sb.append(tree); 51.97 + sb.append(SUFFIX); 51.98 + return null; 51.99 + } else { 51.100 + return super.scan(tree, sb); 51.101 + } 51.102 + } 51.103 + @Override 51.104 + public Void visitBlock(BlockTree tree, StringBuilder sb) { 51.105 + print = true; 51.106 + try { 51.107 + return super.visitBlock(tree, sb); 51.108 + } finally { 51.109 + print = false; 51.110 + } 51.111 + } 51.112 + boolean print = false; 51.113 + } 51.114 + return new Scanner().scan(trees); 51.115 + } 51.116 + 51.117 + void checkEqual(String found, String expect) { 51.118 + boolean match = (found == null) ? (expect == null) : 51.119 + expect.equals(found 51.120 + .replaceAll("^\\Q" + PREFIX + "\\E\\s*", "") 51.121 + .replaceAll("\\s*\\Q" + SUFFIX + "\\E$", "") 51.122 + .replaceAll("\\s+", " ")); 51.123 + 51.124 + if (!match) 51.125 + error("Mismatch: expected: " + expect + " found: " + found); 51.126 + } 51.127 + 51.128 + 51.129 + 51.130 + void error(String msg) { 51.131 + System.err.println("Error: " + msg); 51.132 + errors++; 51.133 + } 51.134 + 51.135 + static final String PREFIX = "#<"; 51.136 + static final String SUFFIX = "#>"; 51.137 + 51.138 + JavacTool tool = JavacTool.create(); 51.139 + StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); 51.140 + int errors = 0; 51.141 + 51.142 + static class JavaSource extends SimpleJavaFileObject { 51.143 + 51.144 + String source = 51.145 + "class Test {\n" + 51.146 + " int i;\n" + 51.147 + " void m() {\n" + 51.148 + " #S\n" + 51.149 + " }\n" + 51.150 + "}"; 51.151 + 51.152 + public JavaSource(String stmt) { 51.153 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 51.154 + source = source.replace("#S", stmt); 51.155 + } 51.156 + 51.157 + @Override 51.158 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 51.159 + return source; 51.160 + } 51.161 + } 51.162 +}
52.1 --- a/test/tools/javac/util/context/T7021650.java Thu Sep 29 18:54:01 2011 -0700 52.2 +++ b/test/tools/javac/util/context/T7021650.java Mon Oct 03 18:26:59 2011 -0700 52.3 @@ -101,13 +101,13 @@ 52.4 StringWriter sw = new StringWriter(); 52.5 PrintWriter pw = new PrintWriter(sw); 52.6 Main m = new Main("javac", pw); 52.7 - int rc = m.compile(args, context); 52.8 + Main.Result res = m.compile(args, context); 52.9 pw.close(); 52.10 String out = sw.toString(); 52.11 if (!out.isEmpty()) 52.12 System.err.println(out); 52.13 - if (rc != 0) 52.14 - throw new Exception("compilation failed unexpectedly: rc=" + rc); 52.15 + if (!res.isOK()) 52.16 + throw new Exception("compilation failed unexpectedly: result=" + res); 52.17 } 52.18 52.19 void checkEqual(String label, int found, int expect) throws Exception {
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 53.2 +++ b/test/tools/javadoc/parser/7091528/T7091528.java Mon Oct 03 18:26:59 2011 -0700 53.3 @@ -0,0 +1,71 @@ 53.4 +/* 53.5 + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. 53.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 53.7 + * 53.8 + * This code is free software; you can redistribute it and/or modify it 53.9 + * under the terms of the GNU General Public License version 2 only, as 53.10 + * published by the Free Software Foundation. 53.11 + * 53.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 53.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 53.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 53.15 + * version 2 for more details (a copy is included in the LICENSE file that 53.16 + * accompanied this code). 53.17 + * 53.18 + * You should have received a copy of the GNU General Public License version 53.19 + * 2 along with this work; if not, write to the Free Software Foundation, 53.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 53.21 + * 53.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 53.23 + * or visit www.oracle.com if you need additional information or have any 53.24 + * questions. 53.25 + */ 53.26 + 53.27 +/** 53.28 + * @test 53.29 + * @bug 7091528 53.30 + * @summary javadoc attempts to parse .class files 53.31 + * @compile p/C1.java p/q/C2.java 53.32 + * @run main T7091528 53.33 + */ 53.34 + 53.35 +import java.io.File; 53.36 +import java.io.PrintWriter; 53.37 +import java.io.StringWriter; 53.38 + 53.39 +public class T7091528 { 53.40 + public static void main(String... args) { 53.41 + new T7091528().run(); 53.42 + } 53.43 + 53.44 + void run() { 53.45 + File testSrc = new File(System.getProperty("test.src")); 53.46 + File testClasses = new File(System.getProperty("test.classes")); 53.47 + String[] args = { 53.48 + "-d", ".", 53.49 + "-sourcepath", testClasses + File.pathSeparator + testSrc, 53.50 + "-subpackages", 53.51 + "p" 53.52 + }; 53.53 + 53.54 + StringWriter sw = new StringWriter(); 53.55 + PrintWriter pw = new PrintWriter(sw); 53.56 + String doclet = com.sun.tools.doclets.standard.Standard.class.getName(); 53.57 + int rc = com.sun.tools.javadoc.Main.execute("javadoc", pw, pw, pw, doclet, args); 53.58 + pw.close(); 53.59 + 53.60 + String out = sw.toString(); 53.61 + if (!out.isEmpty()) { 53.62 + System.err.println(out); 53.63 + } 53.64 + 53.65 + if (rc != 0) 53.66 + System.err.println("javadoc failed: exit code = " + rc); 53.67 + 53.68 + if (out.matches("(?s).*p/[^ ]+\\.class.*")) 53.69 + throw new Error("reading .class files"); 53.70 + 53.71 + if (!new File("index.html").exists()) 53.72 + throw new Error("index.html not found"); 53.73 + } 53.74 +}
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 54.2 +++ b/test/tools/javadoc/parser/7091528/p/C1.java Mon Oct 03 18:26:59 2011 -0700 54.3 @@ -0,0 +1,28 @@ 54.4 +/* 54.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 54.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 54.7 + * 54.8 + * This code is free software; you can redistribute it and/or modify it 54.9 + * under the terms of the GNU General Public License version 2 only, as 54.10 + * published by the Free Software Foundation. 54.11 + * 54.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 54.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 54.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 54.15 + * version 2 for more details (a copy is included in the LICENSE file that 54.16 + * accompanied this code). 54.17 + * 54.18 + * You should have received a copy of the GNU General Public License version 54.19 + * 2 along with this work; if not, write to the Free Software Foundation, 54.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 54.21 + * 54.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 54.23 + * or visit www.oracle.com if you need additional information or have any 54.24 + * questions. 54.25 + */ 54.26 + 54.27 +package p1; 54.28 + 54.29 +/** This is class C1. */ 54.30 +public class C1 { } 54.31 +
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 55.2 +++ b/test/tools/javadoc/parser/7091528/p/q/C2.java Mon Oct 03 18:26:59 2011 -0700 55.3 @@ -0,0 +1,28 @@ 55.4 +/* 55.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 55.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 55.7 + * 55.8 + * This code is free software; you can redistribute it and/or modify it 55.9 + * under the terms of the GNU General Public License version 2 only, as 55.10 + * published by the Free Software Foundation. 55.11 + * 55.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 55.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 55.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 55.15 + * version 2 for more details (a copy is included in the LICENSE file that 55.16 + * accompanied this code). 55.17 + * 55.18 + * You should have received a copy of the GNU General Public License version 55.19 + * 2 along with this work; if not, write to the Free Software Foundation, 55.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 55.21 + * 55.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 55.23 + * or visit www.oracle.com if you need additional information or have any 55.24 + * questions. 55.25 + */ 55.26 + 55.27 +package p.q; 55.28 + 55.29 +/** This is class p.q.C2. */ 55.30 +public class C2 { } 55.31 +