--- a/langtools/src/share/classes/com/sun/tools/javac/Launcher.java Wed Jul 05 17:51:25 2017 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.tools.javac;
-
-import java.io.File;
-import java.util.prefs.Preferences;
-import javax.swing.JFileChooser;
-import javax.tools.JavaCompiler;
-import javax.tools.ToolProvider;
-
-
-/**
- * <b>Unsupported</b> entry point for starting javac from an IDE.
- *
- * <p><b>Note:</b> this class is not available in the JDK. It is not
- * compiled by default and will not be in tools.jar. It is designed
- * to be useful when editing the compiler sources in an IDE (as part
- * of a <em>project</em>). Simply ensure that this class is added to
- * the project and make it the main class of the project.</p>
- *
- * <p><b>This is NOT part of any supported API.
- * If you write code that depends on this, you do so at your own
- * risk. This code and its internal interfaces are subject to change
- * or deletion without notice.</b></p>
- *
- * @author Peter von der Ahé
- * @since 1.6
- */
-class Launcher {
- public static void main(String... args) {
- JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
- JFileChooser fileChooser;
- Preferences prefs = Preferences.userNodeForPackage(Launcher.class);
- if (args.length > 0)
- fileChooser = new JFileChooser(args[0]);
- else {
- String fileName = prefs.get("recent.file", null);
- fileChooser = new JFileChooser();
- if (fileName != null) {
- fileChooser = new JFileChooser();
- fileChooser.setSelectedFile(new File(fileName));
- }
- }
- if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
- String fileName = fileChooser.getSelectedFile().getPath();
- prefs.put("recent.file", fileName);
- javac.run(System.in, null, null, "-d", "/tmp", fileName);
- }
- }
-}
--- a/langtools/src/share/classes/com/sun/tools/javac/Main.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/Main.java Mon Sep 26 14:33:34 2011 -0700
@@ -73,7 +73,7 @@
public static int compile(String[] args) {
com.sun.tools.javac.main.Main compiler =
new com.sun.tools.javac.main.Main("javac");
- return compiler.compile(args);
+ return compiler.compile(args).exitCode;
}
@@ -91,6 +91,6 @@
public static int compile(String[] args, PrintWriter out) {
com.sun.tools.javac.main.Main compiler =
new com.sun.tools.javac.main.Main("javac", out);
- return compiler.compile(args);
+ return compiler.compile(args).exitCode;
}
}
--- a/langtools/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Mon Sep 26 14:33:34 2011 -0700
@@ -78,7 +78,7 @@
private AtomicBoolean used = new AtomicBoolean();
private Iterable<? extends Processor> processors;
- private Integer result = null;
+ private Main.Result result = null;
JavacTaskImpl(Main compilerMain,
String[] args,
@@ -131,7 +131,7 @@
compilerMain.setAPIMode(true);
result = compilerMain.compile(args, context, fileObjects, processors);
cleanup();
- return result == 0;
+ return result.isOK();
} else {
throw new IllegalStateException("multiple calls to method 'call'");
}
@@ -274,6 +274,9 @@
public Iterable<? extends TypeElement> enter(Iterable<? extends CompilationUnitTree> trees)
throws IOException
{
+ if (trees == null && notYetEntered != null && notYetEntered.isEmpty())
+ return List.nil();
+
prepareCompiler();
ListBuffer<JCCompilationUnit> roots = null;
--- a/langtools/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/api/JavacTrees.java Mon Sep 26 14:33:34 2011 -0700
@@ -65,6 +65,7 @@
import com.sun.tools.javac.tree.TreeCopier;
import com.sun.tools.javac.tree.TreeInfo;
import com.sun.tools.javac.tree.TreeMaker;
+import com.sun.tools.javac.util.Assert;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.JCDiagnostic;
import com.sun.tools.javac.util.List;
@@ -263,9 +264,10 @@
if (!(path.getLeaf() instanceof JCTree)) // implicit null-check
throw new IllegalArgumentException();
- // if we're being invoked via from a JSR199 client, we need to make sure
- // all the classes have been entered; if we're being invoked from JSR269,
- // then the classes will already have been entered.
+ // if we're being invoked from a Tree API client via parse/enter/analyze,
+ // we need to make sure all the classes have been entered;
+ // if we're being invoked from JSR 199 or JSR 269, then the classes
+ // will already have been entered.
if (javacTaskImpl != null) {
try {
javacTaskImpl.enter(null);
@@ -313,10 +315,19 @@
break;
case BLOCK: {
// System.err.println("BLOCK: ");
- if (method != null)
- env = memberEnter.getMethodEnv(method, env);
- JCTree body = copier.copy((JCTree)tree, (JCTree) path.getLeaf());
- env = attribStatToTree(body, env, copier.leafCopy);
+ if (method != null) {
+ try {
+ Assert.check(method.body == tree);
+ method.body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf());
+ env = memberEnter.getMethodEnv(method, env);
+ env = attribStatToTree(method.body, env, copier.leafCopy);
+ } finally {
+ method.body = (JCBlock) tree;
+ }
+ } else {
+ JCBlock body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf());
+ env = attribStatToTree(body, env, copier.leafCopy);
+ }
return env;
}
default:
@@ -329,7 +340,7 @@
}
}
}
- return field != null ? memberEnter.getInitEnv(field, env) : env;
+ return (field != null) ? memberEnter.getInitEnv(field, env) : env;
}
private Env<AttrContext> attribStatToTree(JCTree stat, Env<AttrContext>env, JCTree tree) {
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Kinds.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Kinds.java Mon Sep 26 14:33:34 2011 -0700
@@ -103,6 +103,8 @@
VAL("kindname.value"),
METHOD("kindname.method"),
CLASS("kindname.class"),
+ STATIC_INIT("kindname.static.init"),
+ INSTANCE_INIT("kindname.instance.init"),
PACKAGE("kindname.package");
private String name;
@@ -170,9 +172,11 @@
return KindName.CONSTRUCTOR;
case METHOD:
+ return KindName.METHOD;
case STATIC_INIT:
+ return KindName.STATIC_INIT;
case INSTANCE_INIT:
- return KindName.METHOD;
+ return KindName.INSTANCE_INIT;
default:
if (sym.kind == VAL)
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Printer.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Printer.java Mon Sep 26 14:33:34 2011 -0700
@@ -311,7 +311,7 @@
@Override
public String visitMethodSymbol(MethodSymbol s, Locale locale) {
- if ((s.flags() & BLOCK) != 0) {
+ if (s.isStaticOrInstanceInit()) {
return s.owner.name.toString();
} else {
String ms = (s.name == s.name.table.names.init)
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java Mon Sep 26 14:33:34 2011 -0700
@@ -149,7 +149,8 @@
* the default package; otherwise, the owner symbol is returned
*/
public Symbol location() {
- if (owner.name == null || (owner.name.isEmpty() && owner.kind != PCK && owner.kind != TYP)) {
+ if (owner.name == null || (owner.name.isEmpty() &&
+ (owner.flags() & BLOCK) == 0 && owner.kind != PCK && owner.kind != TYP)) {
return null;
}
return owner;
@@ -725,6 +726,11 @@
*/
public JavaFileObject classfile;
+ /** the list of translated local classes (used for generating
+ * InnerClasses attribute)
+ */
+ public List<ClassSymbol> trans_local;
+
/** the constant pool of the class
*/
public Pool pool;
@@ -1299,10 +1305,17 @@
return ElementKind.CONSTRUCTOR;
else if (name == name.table.names.clinit)
return ElementKind.STATIC_INIT;
+ else if ((flags() & BLOCK) != 0)
+ return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
else
return ElementKind.METHOD;
}
+ public boolean isStaticOrInstanceInit() {
+ return getKind() == ElementKind.STATIC_INIT ||
+ getKind() == ElementKind.INSTANCE_INIT;
+ }
+
public Attribute getDefaultValue() {
return defaultValue;
}
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java Mon Sep 26 14:33:34 2011 -0700
@@ -508,8 +508,13 @@
@Override
public Boolean visitUndetVar(UndetVar t, Type s) {
//todo: test against origin needed? or replace with substitution?
- if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN)
+ if (t == s || t.qtype == s || s.tag == ERROR || s.tag == UNKNOWN) {
return true;
+ } else if (s.tag == BOT) {
+ //if 's' is 'null' there's no instantiated type U for which
+ //U <: s (but 'null' itself, which is not a valid type)
+ return false;
+ }
if (t.inst != null)
return isSubtypeNoCapture(t.inst, s); // TODO: ", warn"?
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Mon Sep 26 14:33:34 2011 -0700
@@ -306,7 +306,16 @@
*/
void duplicateError(DiagnosticPosition pos, Symbol sym) {
if (!sym.type.isErroneous()) {
- log.error(pos, "already.defined", sym, sym.location());
+ Symbol location = sym.location();
+ if (location.kind == MTH &&
+ ((MethodSymbol)location).isStaticOrInstanceInit()) {
+ log.error(pos, "already.defined.in.clinit", kindName(sym), sym,
+ kindName(sym.location()), kindName(sym.location().enclClass()),
+ sym.location().enclClass());
+ } else {
+ log.error(pos, "already.defined", kindName(sym), sym,
+ kindName(sym.location()), sym.location());
+ }
}
}
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java Mon Sep 26 14:33:34 2011 -0700
@@ -269,21 +269,18 @@
// VGJ: sort of inlined maximizeInst() below. Adding
// bounds can cause lobounds that are above hibounds.
List<Type> hibounds = Type.filter(that.hibounds, errorFilter);
+ Type hb = null;
if (hibounds.isEmpty())
- return;
- Type hb = null;
- if (hibounds.tail.isEmpty())
+ hb = syms.objectType;
+ else if (hibounds.tail.isEmpty())
hb = hibounds.head;
- else for (List<Type> bs = hibounds;
- bs.nonEmpty() && hb == null;
- bs = bs.tail) {
- if (isSubClass(bs.head, hibounds))
- hb = types.fromUnknownFun.apply(bs.head);
- }
+ else
+ hb = types.glb(hibounds);
if (hb == null ||
- !types.isSubtypeUnchecked(hb, hibounds, warn) ||
- !types.isSubtypeUnchecked(that.inst, hb, warn))
- throw ambiguousNoInstanceException;
+ hb.isErroneous())
+ throw ambiguousNoInstanceException
+ .setMessage("incompatible.upper.bounds",
+ that.qtype, hibounds);
}
}
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java Mon Sep 26 14:33:34 2011 -0700
@@ -2271,6 +2271,14 @@
tree.extending = translate(tree.extending);
tree.implementing = translate(tree.implementing);
+ if (currentClass.isLocal()) {
+ ClassSymbol encl = currentClass.owner.enclClass();
+ if (encl.trans_local == null) {
+ encl.trans_local = List.nil();
+ }
+ encl.trans_local = encl.trans_local.prepend(currentClass);
+ }
+
// Recursively translate members, taking into account that new members
// might be created during the translation and prepended to the member
// list `tree.defs'.
--- a/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Mon Sep 26 14:33:34 2011 -0700
@@ -863,10 +863,10 @@
}
if (c.type.tag != CLASS) return; // arrays
if (pool != null && // pool might be null if called from xClassName
- c.owner.kind != PCK &&
+ c.owner.enclClass() != null &&
(innerClasses == null || !innerClasses.contains(c))) {
// log.errWriter.println("enter inner " + c);//DEBUG
- if (c.owner.kind == TYP) enterInner((ClassSymbol)c.owner);
+ enterInner(c.owner.enclClass());
pool.put(c);
pool.put(c.name);
if (innerClasses == null) {
@@ -1505,6 +1505,13 @@
default : Assert.error();
}
}
+
+ if (c.trans_local != null) {
+ for (ClassSymbol local : c.trans_local) {
+ enterInner(local);
+ }
+ }
+
databuf.appendChar(fieldsCount);
writeFields(c.members().elems);
databuf.appendChar(methodsCount);
--- a/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Mon Sep 26 14:33:34 2011 -0700
@@ -488,6 +488,10 @@
*/
public Todo todo;
+ /** A list of items to be closed when the compilation is complete.
+ */
+ public List<Closeable> closeables = List.nil();
+
/** Ordered list of compiler phases for each compilation unit. */
public enum CompileState {
PARSE(1),
@@ -1581,6 +1585,19 @@
if (names != null && disposeNames)
names.dispose();
names = null;
+
+ for (Closeable c: closeables) {
+ try {
+ c.close();
+ } catch (IOException e) {
+ // When javac uses JDK 7 as a baseline, this code would be
+ // better written to set any/all exceptions from all the
+ // Closeables as suppressed exceptions on the FatalError
+ // that is thrown.
+ JCDiagnostic msg = diagFactory.fragment("fatal.err.cant.close");
+ throw new FatalError(msg, e);
+ }
+ }
}
}
@@ -1615,6 +1632,8 @@
keepComments = prev.keepComments;
start_msec = prev.start_msec;
hasBeenUsed = true;
+ closeables = prev.closeables;
+ prev.closeables = List.nil();
}
public static void enableLogging() {
--- a/langtools/src/share/classes/com/sun/tools/javac/main/Main.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/main/Main.java Mon Sep 26 14:33:34 2011 -0700
@@ -76,12 +76,23 @@
/** Result codes.
*/
- static final int
- EXIT_OK = 0, // Compilation completed with no errors.
- EXIT_ERROR = 1, // Completed but reported errors.
- EXIT_CMDERR = 2, // Bad command-line arguments
- EXIT_SYSERR = 3, // System error or resource exhaustion.
- EXIT_ABNORMAL = 4; // Compiler terminated abnormally
+ public enum Result {
+ OK(0), // Compilation completed with no errors.
+ ERROR(1), // Completed but reported errors.
+ CMDERR(2), // Bad command-line arguments
+ SYSERR(3), // System error or resource exhaustion.
+ ABNORMAL(4); // Compiler terminated abnormally
+
+ Result(int exitCode) {
+ this.exitCode = exitCode;
+ }
+
+ public boolean isOK() {
+ return (exitCode == 0);
+ }
+
+ public final int exitCode;
+ }
private Option[] recognizedOptions = RecognizedOptions.getJavaCompilerOptions(new OptionHelper() {
@@ -318,10 +329,10 @@
/** Programmatic interface for main function.
* @param args The command line parameters.
*/
- public int compile(String[] args) {
+ public Result compile(String[] args) {
Context context = new Context();
JavacFileManager.preRegister(context); // can't create it until Log has been set up
- int result = compile(args, context);
+ Result result = compile(args, context);
if (fileManager instanceof JavacFileManager) {
// A fresh context was created above, so jfm must be a JavacFileManager
((JavacFileManager)fileManager).close();
@@ -329,14 +340,14 @@
return result;
}
- public int compile(String[] args, Context context) {
+ public Result compile(String[] args, Context context) {
return compile(args, context, List.<JavaFileObject>nil(), null);
}
/** Programmatic interface for main function.
* @param args The command line parameters.
*/
- public int compile(String[] args,
+ public Result compile(String[] args,
Context context,
List<JavaFileObject> fileObjects,
Iterable<? extends Processor> processors)
@@ -355,7 +366,7 @@
try {
if (args.length == 0 && fileObjects.isEmpty()) {
help();
- return EXIT_CMDERR;
+ return Result.CMDERR;
}
Collection<File> files;
@@ -363,26 +374,26 @@
files = processArgs(CommandLine.parse(args));
if (files == null) {
// null signals an error in options, abort
- return EXIT_CMDERR;
+ return Result.CMDERR;
} else if (files.isEmpty() && fileObjects.isEmpty() && classnames.isEmpty()) {
// it is allowed to compile nothing if just asking for help or version info
if (options.isSet(HELP)
|| options.isSet(X)
|| options.isSet(VERSION)
|| options.isSet(FULLVERSION))
- return EXIT_OK;
+ return Result.OK;
if (JavaCompiler.explicitAnnotationProcessingRequested(options)) {
error("err.no.source.files.classes");
} else {
error("err.no.source.files");
}
- return EXIT_CMDERR;
+ return Result.CMDERR;
}
} catch (java.io.FileNotFoundException e) {
Log.printLines(out, ownName + ": " +
getLocalizedString("err.file.not.found",
e.getMessage()));
- return EXIT_SYSERR;
+ return Result.SYSERR;
}
boolean forceStdOut = options.isSet("stdout");
@@ -402,7 +413,7 @@
fileManager = context.get(JavaFileManager.class);
comp = JavaCompiler.instance(context);
- if (comp == null) return EXIT_SYSERR;
+ if (comp == null) return Result.SYSERR;
Log log = Log.instance(context);
@@ -423,32 +434,32 @@
if (log.expectDiagKeys != null) {
if (log.expectDiagKeys.isEmpty()) {
Log.printLines(log.noticeWriter, "all expected diagnostics found");
- return EXIT_OK;
+ return Result.OK;
} else {
Log.printLines(log.noticeWriter, "expected diagnostic keys not found: " + log.expectDiagKeys);
- return EXIT_ERROR;
+ return Result.ERROR;
}
}
if (comp.errorCount() != 0)
- return EXIT_ERROR;
+ return Result.ERROR;
} catch (IOException ex) {
ioMessage(ex);
- return EXIT_SYSERR;
+ return Result.SYSERR;
} catch (OutOfMemoryError ex) {
resourceMessage(ex);
- return EXIT_SYSERR;
+ return Result.SYSERR;
} catch (StackOverflowError ex) {
resourceMessage(ex);
- return EXIT_SYSERR;
+ return Result.SYSERR;
} catch (FatalError ex) {
feMessage(ex);
- return EXIT_SYSERR;
+ return Result.SYSERR;
} catch (AnnotationProcessingError ex) {
if (apiMode)
throw new RuntimeException(ex.getCause());
apMessage(ex);
- return EXIT_SYSERR;
+ return Result.SYSERR;
} catch (ClientCodeException ex) {
// as specified by javax.tools.JavaCompiler#getTask
// and javax.tools.JavaCompiler.CompilationTask#call
@@ -462,7 +473,7 @@
if (comp == null || comp.errorCount() == 0 ||
options == null || options.isSet("dev"))
bugMessage(ex);
- return EXIT_ABNORMAL;
+ return Result.ABNORMAL;
} finally {
if (comp != null) {
try {
@@ -474,7 +485,7 @@
filenames = null;
options = null;
}
- return EXIT_OK;
+ return Result.OK;
}
/** Print a message reporting an internal error.
--- a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacFiler.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacFiler.java Mon Sep 26 14:33:34 2011 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -455,9 +455,24 @@
// TODO: Only support reading resources in selected output
// locations? Only allow reading of non-source, non-class
// files from the supported input locations?
- FileObject fileObject = fileManager.getFileForInput(location,
+
+ // In the following, getFileForInput is the "obvious" method
+ // to use, but it does not have the "obvious" semantics for
+ // SOURCE_OUTPUT and CLASS_OUTPUT. Conversely, getFileForOutput
+ // does not have the correct semantics for any "path" location
+ // with more than one component. So, for now, we use a hybrid
+ // invocation.
+ FileObject fileObject;
+ if (location.isOutputLocation()) {
+ fileObject = fileManager.getFileForOutput(location,
+ pkg.toString(),
+ relativeName.toString(),
+ null);
+ } else {
+ fileObject = fileManager.getFileForInput(location,
pkg.toString(),
relativeName.toString());
+ }
if (fileObject == null) {
String name = (pkg.length() == 0)
? relativeName.toString() : (pkg + "/" + relativeName);
--- a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Mon Sep 26 14:33:34 2011 -0700
@@ -225,6 +225,11 @@
? fileManager.getClassLoader(ANNOTATION_PROCESSOR_PATH)
: fileManager.getClassLoader(CLASS_PATH);
+ if (processorClassLoader != null && processorClassLoader instanceof Closeable) {
+ JavaCompiler compiler = JavaCompiler.instance(context);
+ compiler.closeables = compiler.closeables.prepend((Closeable) processorClassLoader);
+ }
+
/*
* If the "-processor" option is used, search the appropriate
* path for the named class. Otherwise, use a service
@@ -1211,14 +1216,6 @@
if (discoveredProcs != null) // Make calling close idempotent
discoveredProcs.close();
discoveredProcs = null;
- if (processorClassLoader != null && processorClassLoader instanceof Closeable) {
- try {
- ((Closeable) processorClassLoader).close();
- } catch (IOException e) {
- JCDiagnostic msg = diags.fragment("fatal.err.cant.close.loader");
- throw new FatalError(msg, e);
- }
- }
}
private List<ClassSymbol> getTopLevelClasses(List<? extends JCCompilationUnit> units) {
--- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Mon Sep 26 14:33:34 2011 -0700
@@ -68,9 +68,13 @@
compiler.err.already.annotated=\
{0} {1} has already been annotated
-# 0: symbol, 1: symbol
+# 0: symbol kind, 1: symbol, 2: symbol kind, 3: symbol
compiler.err.already.defined=\
- {0} is already defined in {1}
+ {0} {1} is already defined in {2} {3}
+
+# 0: symbol kind, 1: symbol, 2: symbol kind, 3: symbol kind, 4: symbol
+compiler.err.already.defined.in.clinit=\
+ {0} {1} is already defined in {2} of {3} {4}
# 0: string
compiler.err.already.defined.single.import=\
@@ -891,8 +895,8 @@
compiler.misc.fatal.err.cant.locate.ctor=\
Fatal Error: Unable to find constructor for {0}
-compiler.misc.fatal.err.cant.close.loader=\
- Fatal Error: Cannot close class loader for annotation processors
+compiler.misc.fatal.err.cant.close=\
+ Fatal Error: Cannot close compiler resources
#####
@@ -1598,6 +1602,10 @@
compiler.misc.no.unique.minimal.instance.exists=\
no unique minimal instance exists for type variable {0} with lower bounds {1}
+# 0: type, 1: list of type
+compiler.misc.incompatible.upper.bounds=\
+ inference variable {0} has incompatible upper bounds {1}
+
# 0: list of type, 1: type, 2: type
compiler.misc.infer.no.conforming.instance.exists=\
no instance(s) of type variable(s) {0} exist so that {1} conforms to {2}
@@ -1753,6 +1761,12 @@
compiler.misc.kindname.package=\
package
+compiler.misc.kindname.static.init=\
+ static initializer
+
+compiler.misc.kindname.instance.init=\
+ instance initializer
+
#####
compiler.misc.no.args=\
--- a/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java Mon Sep 26 14:33:34 2011 -0700
@@ -436,7 +436,6 @@
public PackageSymbol packge;
public ImportScope namedImportScope;
public StarImportScope starImportScope;
- public long flags;
public Position.LineMap lineMap = null;
public Map<JCTree, String> docComments = null;
public Map<JCTree, Integer> endPositions = null;
@@ -1176,6 +1175,21 @@
public int getTag() {
return EXEC;
}
+
+ /** Convert a expression-statement tree to a pretty-printed string. */
+ @Override
+ public String toString() {
+ StringWriter s = new StringWriter();
+ try {
+ new Pretty(s, false).printStat(this);
+ }
+ catch (IOException e) {
+ // should never happen, because StringWriter is defined
+ // never to throw any IOExceptions
+ throw new AssertionError(e);
+ }
+ return s.toString();
+ }
}
/**
--- a/langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java Mon Sep 26 14:33:34 2011 -0700
@@ -412,7 +412,7 @@
@Override
public String visitMethodSymbol(MethodSymbol s, Locale locale) {
String ownerName = visit(s.owner, locale);
- if ((s.flags() & BLOCK) != 0) {
+ if (s.isStaticOrInstanceInit()) {
return ownerName;
} else {
String ms = (s.name == s.name.table.names.init)
--- a/langtools/src/share/classes/com/sun/tools/javadoc/JavadocTool.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/src/share/classes/com/sun/tools/javadoc/JavadocTool.java Mon Sep 26 14:33:34 2011 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -257,24 +257,15 @@
for (String p: excludedPackages)
includedPackages.put(p, false);
- if (docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)) {
- searchSubPackages(subPackages,
- includedPackages,
- packages, packageFiles,
- StandardLocation.SOURCE_PATH,
- EnumSet.of(JavaFileObject.Kind.SOURCE));
- searchSubPackages(subPackages,
- includedPackages,
- packages, packageFiles,
- StandardLocation.CLASS_PATH,
- EnumSet.of(JavaFileObject.Kind.CLASS));
- } else {
- searchSubPackages(subPackages,
- includedPackages,
- packages, packageFiles,
- StandardLocation.CLASS_PATH,
- EnumSet.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS));
- }
+ StandardLocation path = docenv.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
+ ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;
+
+ searchSubPackages(subPackages,
+ includedPackages,
+ packages, packageFiles,
+ path,
+ EnumSet.of(JavaFileObject.Kind.SOURCE));
+
return packageFiles;
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/7003595/T7003595.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,233 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7003595
+ * @summary IncompatibleClassChangeError with unreferenced local class with subclass
+ */
+
+import com.sun.source.util.JavacTask;
+import com.sun.tools.classfile.Attribute;
+import com.sun.tools.classfile.ClassFile;
+import com.sun.tools.classfile.InnerClasses_attribute;
+import com.sun.tools.classfile.ConstantPool.*;
+import com.sun.tools.javac.api.JavacTool;
+
+import java.io.File;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.ArrayList;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.ToolProvider;
+
+
+public class T7003595 {
+
+ /** global decls ***/
+
+ // Create a single file manager and reuse it for each compile to save time.
+ static StandardJavaFileManager fm = JavacTool.create().getStandardFileManager(null, null, null);
+
+ //statistics
+ static int checkCount = 0;
+
+ enum ClassKind {
+ NESTED("static class #N { #B }", "$", true),
+ INNER("class #N { #B }", "$", false),
+ LOCAL_REF("void test() { class #N { #B }; new #N(); }", "$1", false),
+ LOCAL_NOREF("void test() { class #N { #B }; }", "$1", false),
+ ANON("void test() { new Object() { #B }; }", "$1", false),
+ NONE("", "", false);
+
+ String memberInnerStr;
+ String sep;
+ boolean staticAllowed;
+
+ private ClassKind(String memberInnerStr, String sep, boolean staticAllowed) {
+ this.memberInnerStr = memberInnerStr;
+ this.sep = sep;
+ this.staticAllowed = staticAllowed;
+ }
+
+ String getSource(String className, String outerName, String nested) {
+ return memberInnerStr.replaceAll("#O", outerName).
+ replaceAll("#N", className).replaceAll("#B", nested);
+ }
+
+ static String getClassfileName(String[] names, ClassKind[] outerKinds, int pos) {
+ System.out.println(" pos = " + pos + " kind = " + outerKinds[pos] + " sep = " + outerKinds[pos].sep);
+ String name = outerKinds[pos] != ANON ?
+ names[pos] : "";
+ if (pos == 0) {
+ return "Test" + outerKinds[pos].sep + name;
+ } else {
+ String outerStr = getClassfileName(names, outerKinds, pos - 1);
+ return outerStr + outerKinds[pos].sep + name;
+ }
+ }
+
+ boolean isAllowed(ClassKind nestedKind) {
+ return nestedKind != NESTED ||
+ staticAllowed;
+ }
+ }
+
+ enum LocalInnerClass {
+ LOCAL_REF("class L {}; new L();", "Test$1L"),
+ LOCAL_NOREF("class L {};", "Test$1L"),
+ ANON("new Object() {};", "Test$1"),
+ NONE("", "");
+
+ String localInnerStr;
+ String canonicalInnerStr;
+
+ private LocalInnerClass(String localInnerStr, String canonicalInnerStr) {
+ this.localInnerStr = localInnerStr;
+ this.canonicalInnerStr = canonicalInnerStr;
+ }
+ }
+
+ public static void main(String... args) throws Exception {
+ for (ClassKind ck1 : ClassKind.values()) {
+ String cname1 = "C1";
+ for (ClassKind ck2 : ClassKind.values()) {
+ if (!ck1.isAllowed(ck2)) continue;
+ String cname2 = "C2";
+ for (ClassKind ck3 : ClassKind.values()) {
+ if (!ck2.isAllowed(ck3)) continue;
+ String cname3 = "C3";
+ new T7003595(new ClassKind[] {ck1, ck2, ck3}, new String[] { cname1, cname2, cname3 }).compileAndCheck();
+ }
+ }
+ }
+
+ System.out.println("Total checks made: " + checkCount);
+ }
+
+ /** instance decls **/
+
+ ClassKind[] cks;
+ String[] cnames;
+
+ T7003595(ClassKind[] cks, String[] cnames) {
+ this.cks = cks;
+ this.cnames = cnames;
+ }
+
+ void compileAndCheck() throws Exception {
+ final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
+ JavaSource source = new JavaSource();
+ JavacTask ct = (JavacTask)tool.getTask(null, fm, null,
+ null, null, Arrays.asList(source));
+ ct.call();
+ verifyBytecode(source);
+ }
+
+ void verifyBytecode(JavaSource source) {
+ for (int i = 0; i < 3 ; i ++) {
+ if (cks[i] == ClassKind.NONE) break;
+ checkCount++;
+ String filename = cks[i].getClassfileName(cnames, cks, i);
+ File compiledTest = new File(filename + ".class");
+ try {
+ ClassFile cf = ClassFile.read(compiledTest);
+ if (cf == null) {
+ throw new Error("Classfile not found: " + filename);
+ }
+
+ InnerClasses_attribute innerClasses = (InnerClasses_attribute)cf.getAttribute(Attribute.InnerClasses);
+
+ ArrayList<String> foundInnerSig = new ArrayList<>();
+ if (innerClasses != null) {
+ for (InnerClasses_attribute.Info info : innerClasses.classes) {
+ String foundSig = info.getInnerClassInfo(cf.constant_pool).getName();
+ foundInnerSig.add(foundSig);
+ }
+ }
+
+ ArrayList<String> expectedInnerSig = new ArrayList<>();
+ //add inner class (if any)
+ if (i < 2 && cks[i + 1] != ClassKind.NONE) {
+ expectedInnerSig.add(cks[i + 1].getClassfileName(cnames, cks, i + 1));
+ }
+ //add inner classes
+ for (int j = 0 ; j != i + 1 && j < 3; j++) {
+ expectedInnerSig.add(cks[j].getClassfileName(cnames, cks, j));
+ }
+
+ if (expectedInnerSig.size() != foundInnerSig.size()) {
+ throw new Error("InnerClasses attribute for " + cnames[i] + " has wrong size\n" +
+ "expected " + expectedInnerSig.size() + "\n" +
+ "found " + innerClasses.number_of_classes + "\n" +
+ source);
+ }
+
+ for (String foundSig : foundInnerSig) {
+ if (!expectedInnerSig.contains(foundSig)) {
+ throw new Error("InnerClasses attribute for " + cnames[i] + " has unexpected signature: " +
+ foundSig + "\n" + source + "\n" + expectedInnerSig);
+ }
+ }
+
+ for (String expectedSig : expectedInnerSig) {
+ if (!foundInnerSig.contains(expectedSig)) {
+ throw new Error("InnerClasses attribute for " + cnames[i] + " does not contain expected signature: " +
+ expectedSig + "\n" + source);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new Error("error reading " + compiledTest +": " + e);
+ }
+ }
+ }
+
+ class JavaSource extends SimpleJavaFileObject {
+
+ static final String source_template = "class Test { #C }";
+
+ String source;
+
+ public JavaSource() {
+ super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
+ String c3 = cks[2].getSource(cnames[2], cnames[1], "");
+ String c2 = cks[1].getSource(cnames[1], cnames[0], c3);
+ String c1 = cks[0].getSource(cnames[0], "Test", c2);
+ source = source_template.replace("#C", c1);
+ }
+
+ @Override
+ public String toString() {
+ return source;
+ }
+
+ @Override
+ public CharSequence getCharContent(boolean ignoreEncodingErrors) {
+ return source;
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/7003595/T7003595b.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7003595
+ * @summary IncompatibleClassChangeError with unreferenced local class with subclass
+ */
+
+public class T7003595b {
+ public static void main(String... args) throws Exception {
+ class A {}
+ class B extends A {}
+ B.class.getSuperclass().getDeclaringClass();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/7086595/T7086595.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,32 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 7086595
+ * @summary Error message bug: name of initializer is 'null'
+ * @compile/fail/ref=T7086595.out -XDrawDiagnostics T7086595.java
+ */
+
+class T7086595 {
+
+ String s = "x";
+ String s = nonExistent;
+
+ int foo() {
+ String s = "x";
+ String s = nonExistent;
+ }
+
+ static int bar() {
+ String s = "x";
+ String s = nonExistent;
+ }
+
+ {
+ String s = "x";
+ String s = nonExistent;
+ }
+
+ static {
+ String s = "x";
+ String s = nonExistent;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/7086595/T7086595.out Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,11 @@
+T7086595.java:11:12: compiler.err.already.defined: kindname.variable, s, kindname.class, T7086595
+T7086595.java:11:16: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null)
+T7086595.java:15:16: compiler.err.already.defined: kindname.variable, s, kindname.method, foo()
+T7086595.java:15:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null)
+T7086595.java:20:16: compiler.err.already.defined: kindname.variable, s, kindname.method, bar()
+T7086595.java:20:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null)
+T7086595.java:25:16: compiler.err.already.defined.in.clinit: kindname.variable, s, kindname.instance.init, kindname.class, T7086595
+T7086595.java:25:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null)
+T7086595.java:30:16: compiler.err.already.defined.in.clinit: kindname.variable, s, kindname.static.init, kindname.class, T7086595
+T7086595.java:30:20: compiler.err.cant.resolve.location: kindname.variable, nonExistent, , , (compiler.misc.location: kindname.class, T7086595, null)
+10 errors
--- a/langtools/test/tools/javac/Diagnostics/6860795/T6860795.out Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/test/tools/javac/Diagnostics/6860795/T6860795.out Mon Sep 26 14:33:34 2011 -0700
@@ -1,2 +1,2 @@
-T6860795.java:10:27: compiler.err.already.defined: x, foo
+T6860795.java:10:27: compiler.err.already.defined: kindname.variable, x, kindname.method, foo
1 error
--- a/langtools/test/tools/javac/Diagnostics/6862608/T6862608a.out Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/test/tools/javac/Diagnostics/6862608/T6862608a.out Mon Sep 26 14:33:34 2011 -0700
@@ -1,3 +1,3 @@
-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>
+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>>)
- 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>>))}
1 error
--- a/langtools/test/tools/javac/LocalClasses_2.out Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/test/tools/javac/LocalClasses_2.out Mon Sep 26 14:33:34 2011 -0700
@@ -1,2 +1,2 @@
-LocalClasses_2.java:15:13: compiler.err.already.defined: Local, foo()
+LocalClasses_2.java:15:13: compiler.err.already.defined: kindname.class, Local, kindname.method, foo()
1 error
--- a/langtools/test/tools/javac/NestedInnerClassNames.out Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/test/tools/javac/NestedInnerClassNames.out Mon Sep 26 14:33:34 2011 -0700
@@ -1,18 +1,18 @@
-NestedInnerClassNames.java:16:5: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package
-NestedInnerClassNames.java:23:9: compiler.err.already.defined: NestedInnerClassNames.foo, NestedInnerClassNames
-NestedInnerClassNames.java:34:9: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package
-NestedInnerClassNames.java:45:9: compiler.err.already.defined: NestedInnerClassNames.baz, NestedInnerClassNames
-NestedInnerClassNames.java:46:13: compiler.err.already.defined: NestedInnerClassNames.baz.baz, NestedInnerClassNames.baz
-NestedInnerClassNames.java:59:9: compiler.err.already.defined: NestedInnerClassNames.foo$bar, NestedInnerClassNames
-NestedInnerClassNames.java:76:13: compiler.err.already.defined: NestedInnerClassNames.$bar, NestedInnerClassNames
-NestedInnerClassNames.java:90:13: compiler.err.already.defined: NestedInnerClassNames.bar$bar.bar, NestedInnerClassNames.bar$bar
+NestedInnerClassNames.java:16:5: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package
+NestedInnerClassNames.java:23:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames.foo, kindname.class, NestedInnerClassNames
+NestedInnerClassNames.java:34:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package
+NestedInnerClassNames.java:45:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames.baz, kindname.class, NestedInnerClassNames
+NestedInnerClassNames.java:46:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames.baz.baz, kindname.class, NestedInnerClassNames.baz
+NestedInnerClassNames.java:59:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames.foo$bar, kindname.class, NestedInnerClassNames
+NestedInnerClassNames.java:76:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames.$bar, kindname.class, NestedInnerClassNames
+NestedInnerClassNames.java:90:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames.bar$bar.bar, kindname.class, NestedInnerClassNames.bar$bar
NestedInnerClassNames.java:109:5: compiler.err.duplicate.class: NestedInnerClassNames.foo.foo
-NestedInnerClassNames.java:19:9: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package
-NestedInnerClassNames.java:28:13: compiler.err.already.defined: foo, m2()
-NestedInnerClassNames.java:40:13: compiler.err.already.defined: NestedInnerClassNames, compiler.misc.unnamed.package
-NestedInnerClassNames.java:52:13: compiler.err.already.defined: baz, m4()
-NestedInnerClassNames.java:53:17: compiler.err.already.defined: baz.baz, baz
-NestedInnerClassNames.java:67:13: compiler.err.already.defined: foo$bar, m5()
-NestedInnerClassNames.java:83:17: compiler.err.already.defined: $bar, m6()
-NestedInnerClassNames.java:97:17: compiler.err.already.defined: bar$bar.bar, bar$bar
+NestedInnerClassNames.java:19:9: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package
+NestedInnerClassNames.java:28:13: compiler.err.already.defined: kindname.class, foo, kindname.method, m2()
+NestedInnerClassNames.java:40:13: compiler.err.already.defined: kindname.class, NestedInnerClassNames, kindname.package, compiler.misc.unnamed.package
+NestedInnerClassNames.java:52:13: compiler.err.already.defined: kindname.class, baz, kindname.method, m4()
+NestedInnerClassNames.java:53:17: compiler.err.already.defined: kindname.class, baz.baz, kindname.class, baz
+NestedInnerClassNames.java:67:13: compiler.err.already.defined: kindname.class, foo$bar, kindname.method, m5()
+NestedInnerClassNames.java:83:17: compiler.err.already.defined: kindname.class, $bar, kindname.method, m6()
+NestedInnerClassNames.java:97:17: compiler.err.already.defined: kindname.class, bar$bar.bar, kindname.class, bar$bar
17 errors
--- a/langtools/test/tools/javac/TryWithResources/BadTwr.out Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/test/tools/javac/TryWithResources/BadTwr.out Mon Sep 26 14:33:34 2011 -0700
@@ -1,5 +1,5 @@
-BadTwr.java:13:46: compiler.err.already.defined: r1, main(java.lang.String...)
-BadTwr.java:18:20: compiler.err.already.defined: args, main(java.lang.String...)
+BadTwr.java:13:46: compiler.err.already.defined: kindname.variable, r1, kindname.method, main(java.lang.String...)
+BadTwr.java:18:20: compiler.err.already.defined: kindname.variable, args, kindname.method, main(java.lang.String...)
BadTwr.java:21:13: compiler.err.cant.assign.val.to.final.var: thatsIt
-BadTwr.java:26:24: compiler.err.already.defined: name, main(java.lang.String...)
+BadTwr.java:26:24: compiler.err.already.defined: kindname.variable, name, kindname.method, main(java.lang.String...)
4 errors
--- a/langtools/test/tools/javac/TryWithResources/DuplicateResourceDecl.out Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/test/tools/javac/TryWithResources/DuplicateResourceDecl.out Mon Sep 26 14:33:34 2011 -0700
@@ -1,2 +1,2 @@
-DuplicateResourceDecl.java:12:56: compiler.err.already.defined: c, main(java.lang.String[])
+DuplicateResourceDecl.java:12:56: compiler.err.already.defined: kindname.variable, c, kindname.method, main(java.lang.String[])
1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/api/TestGetScope.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7090249
+ * @summary IllegalStateException from Trees.getScope when called from JSR 199
+ */
+
+import com.sun.source.tree.IdentifierTree;
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.TypeElement;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.ToolProvider;
+
+import com.sun.source.util.JavacTask;
+import com.sun.source.util.TreePath;
+import com.sun.source.util.TreePathScanner;
+import com.sun.source.util.Trees;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.lang.model.SourceVersion;
+
+@SupportedAnnotationTypes("*")
+public class TestGetScope extends AbstractProcessor {
+ public static void main(String... args) {
+ new TestGetScope().run();
+ }
+
+ public void run() {
+ File srcDir = new File(System.getProperty("test.src"));
+ File thisFile = new File(srcDir, getClass().getName() + ".java");
+
+ JavaCompiler c = ToolProvider.getSystemJavaCompiler();
+ StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
+
+ List<String> opts = Arrays.asList("-proc:only", "-doe");
+ Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile);
+ JavacTask t = (JavacTask) c.getTask(null, fm, null, opts, null, files);
+ t.setProcessors(Collections.singleton(this));
+ boolean ok = t.call();
+ if (!ok)
+ throw new Error("compilation failed");
+ }
+
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ Trees trees = Trees.instance(processingEnv);
+ if (round++ == 0) {
+ for (Element e: roundEnv.getRootElements()) {
+ TreePath p = trees.getPath(e);
+ new Scanner().scan(p, trees);
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public SourceVersion getSupportedSourceVersion() {
+ return SourceVersion.latest();
+ }
+
+ int round;
+
+ static class Scanner extends TreePathScanner<Void,Trees> {
+ @Override
+ public Void visitIdentifier(IdentifierTree t, Trees trees) {
+ System.err.println("visitIdentifier: " + t);
+ trees.getScope(getCurrentPath());
+ return null;
+ }
+ }
+}
--- a/langtools/test/tools/javac/diags/ArgTypeCompilerFactory.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/test/tools/javac/diags/ArgTypeCompilerFactory.java Mon Sep 26 14:33:34 2011 -0700
@@ -146,9 +146,9 @@
JavacFileManager.preRegister(c); // can't create it until Log has been set up
ArgTypeJavaCompiler.preRegister(c);
ArgTypeMessages.preRegister(c);
- int result = main.compile(args.toArray(new String[args.size()]), c);
+ Main.Result result = main.compile(args.toArray(new String[args.size()]), c);
- return (result == 0);
+ return result.isOK();
}
}
@@ -172,10 +172,10 @@
JavacFileManager.preRegister(c); // can't create it until Log has been set up
ArgTypeJavaCompiler.preRegister(c);
ArgTypeMessages.preRegister(c);
- com.sun.tools.javac.main.Main m = new com.sun.tools.javac.main.Main("javac", out);
- int rc = m.compile(args.toArray(new String[args.size()]), c);
+ Main m = new Main("javac", out);
+ Main.Result result = m.compile(args.toArray(new String[args.size()]), c);
- return (rc == 0);
+ return result.isOK();
}
}
--- a/langtools/test/tools/javac/diags/Example.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/test/tools/javac/diags/Example.java Mon Sep 26 14:33:34 2011 -0700
@@ -41,6 +41,7 @@
import com.sun.tools.javac.api.ClientCodeWrapper;
import com.sun.tools.javac.file.JavacFileManager;
+import com.sun.tools.javac.main.Main;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.JavacMessages;
import com.sun.tools.javac.util.JCDiagnostic;
@@ -515,14 +516,14 @@
Context c = new Context();
JavacFileManager.preRegister(c); // can't create it until Log has been set up
MessageTracker.preRegister(c, keys);
- com.sun.tools.javac.main.Main m = new com.sun.tools.javac.main.Main("javac", pw);
- int rc = m.compile(args.toArray(new String[args.size()]), c);
+ Main m = new Main("javac", pw);
+ Main.Result rc = m.compile(args.toArray(new String[args.size()]), c);
if (keys != null) {
pw.close();
}
- return (rc == 0);
+ return rc.isOK();
}
static class MessageTracker extends JavacMessages {
--- a/langtools/test/tools/javac/diags/examples.not-yet.txt Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/test/tools/javac/diags/examples.not-yet.txt Mon Sep 26 14:33:34 2011 -0700
@@ -60,7 +60,7 @@
compiler.misc.fatal.err.cant.locate.ctor # Resolve, from Lower
compiler.misc.fatal.err.cant.locate.field # Resolve, from Lower
compiler.misc.fatal.err.cant.locate.meth # Resolve, from Lower
-compiler.misc.fatal.err.cant.close.loader # JavacProcessingEnvironment
+compiler.misc.fatal.err.cant.close # JavaCompiler
compiler.misc.file.does.not.contain.package
compiler.misc.illegal.start.of.class.file
compiler.misc.kindname.annotation
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/diags/examples/AlreadyDefinedClinit.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// key: compiler.err.already.defined.in.clinit
+
+class AlreadyDefinedClinit {
+ static {
+ int i;
+ int i;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/diags/examples/IncompatibleUpperBounds.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+//key: compiler.err.cant.apply.symbols
+//key: compiler.misc.inapplicable.method
+//key: compiler.misc.arg.length.mismatch
+//key: compiler.misc.incompatible.upper.bounds
+
+import java.util.List;
+
+class IncompatibleUpperBounds {
+ <S> void m(List<? super S> s1, List<? super S> s2) { }
+ void m(Object o) {}
+
+ void test(List<Integer> li, List<String> ls) {
+ m(li, ls);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/diags/examples/KindnameInstanceInit.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// key: compiler.err.already.defined.in.clinit
+// key: compiler.misc.kindname.instance.init
+// key: compiler.misc.kindname.class
+// key: compiler.misc.kindname.variable
+// key: compiler.misc.count.error
+// key: compiler.err.error
+// run: backdoor
+
+class KindnameInstanceInit {
+ {
+ int i;
+ int i;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/diags/examples/KindnameStaticInit.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+// key: compiler.err.already.defined.in.clinit
+// key: compiler.misc.kindname.static.init
+// key: compiler.misc.kindname.class
+// key: compiler.misc.kindname.variable
+// key: compiler.misc.count.error
+// key: compiler.err.error
+// run: backdoor
+
+class KindnameStaticInit {
+ static {
+ int i;
+ int i;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/file/T7068437.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7068437
+ * @summary Filer.getResource(SOURCE_OUTPUT, ...) no longer works in JDK 7 w/o -s
+ */
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.Filer;
+import javax.annotation.processing.Messager;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedOptions;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.TypeElement;
+import javax.tools.Diagnostic.Kind;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaCompiler.CompilationTask;
+import javax.tools.StandardLocation;
+import javax.tools.ToolProvider;
+
+public class T7068437 {
+ public static void main(String[] args) throws Exception {
+ new T7068437().run();
+ }
+
+ void run() throws Exception {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ System.err.println("using " + compiler.getClass()
+ + " from " + compiler.getClass().getProtectionDomain().getCodeSource());
+
+ CompilationTask task = compiler.getTask(null, null, null,
+ Collections.singleton("-proc:only"),
+ Collections.singleton("java.lang.Object"),
+ null);
+ task.setProcessors(Collections.singleton(new Proc()));
+ check("compilation", task.call());
+
+ task = compiler.getTask(null, null, null,
+ Arrays.asList("-proc:only", "-AexpectFile"),
+ Collections.singleton("java.lang.Object"),
+ null);
+ task.setProcessors(Collections.singleton(new Proc()));
+ check("compilation", task.call());
+ }
+
+ void check(String msg, boolean ok) {
+ System.err.println(msg + ": " + (ok ? "ok" : "failed"));
+ if (!ok)
+ throw new AssertionError(msg);
+ }
+
+ @SupportedAnnotationTypes("*")
+ @SupportedOptions("expectFile")
+ private static class Proc extends AbstractProcessor {
+ int count;
+
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ if (roundEnv.processingOver() || count++ > 0) {
+ return false;
+ }
+
+ Filer filer = processingEnv.getFiler();
+ Messager messager = processingEnv.getMessager();
+ Map<String, String> options = processingEnv.getOptions();
+ System.err.println(options);
+ boolean expectFile = options.containsKey("expectFile");
+
+ System.err.println("running Proc: expectFile=" + expectFile);
+
+ boolean found;
+ try {
+ messager.printMessage(Kind.NOTE, "found previous content of length " +
+ filer.getResource(StandardLocation.SOURCE_OUTPUT, "p", "C.java").getCharContent(false).length());
+ found = true;
+ } catch (FileNotFoundException x) {
+ messager.printMessage(Kind.NOTE, "not previously there");
+ found = false;
+ } catch (IOException x) {
+ messager.printMessage(Kind.ERROR, "while reading: " + x);
+ found = false;
+ }
+
+ if (expectFile && !found) {
+ messager.printMessage(Kind.ERROR, "expected file but file not found");
+ }
+
+ try {
+ Writer w = filer.createSourceFile("p.C").openWriter();
+ w.write("/* hello! */ package p; class C {}");
+ w.close();
+ messager.printMessage(Kind.NOTE, "wrote new content");
+ } catch (IOException x) {
+ messager.printMessage(Kind.ERROR, "while writing: " + x);
+ }
+
+ return true;
+ }
+
+ @Override
+ public SourceVersion getSupportedSourceVersion() {
+ return SourceVersion.latest();
+ }
+ }
+}
--- a/langtools/test/tools/javac/generics/6910550/T6910550d.out Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/test/tools/javac/generics/6910550/T6910550d.out Mon Sep 26 14:33:34 2011 -0700
@@ -1,2 +1,2 @@
-T6910550d.java:12:14: compiler.err.already.defined: <X>m(X), T6910550d
+T6910550d.java:12:14: compiler.err.already.defined: kindname.method, <X>m(X), kindname.class, T6910550d
1 error
--- a/langtools/test/tools/javac/generics/inference/6638712/T6638712a.out Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/test/tools/javac/generics/inference/6638712/T6638712a.out Mon Sep 26 14:33:34 2011 -0700
@@ -1,2 +1,2 @@
-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>
+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>>)
1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/inference/7086586/T7086586.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,19 @@
+/**
+ * @test /nodynamiccopyright/
+ * @bug 7086586
+ * @summary Inference producing null type argument
+ * @compile/fail/ref=T7086586.out -XDrawDiagnostics T7086586.java
+ */
+import java.util.List;
+
+class T7086586 {
+
+ <T> List<T> m(List<? super T> dummy) { return null; }
+
+ void test(List<?> l) {
+ String s = m(l).get(0);
+ Number n = m(l).get(0);
+ Exception e = m(l).get(0);
+ m(l).nonExistentMethod();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/inference/7086586/T7086586.out Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,5 @@
+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>)
+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>)
+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>)
+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>)
+4 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/inference/7086586/T7086586b.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7086586
+ *
+ * @summary Inference producing null type argument
+ */
+import java.util.List;
+
+public class T7086586b {
+
+ int assertionCount = 0;
+
+ void assertTrue(boolean cond) {
+ if (!cond) {
+ throw new AssertionError();
+ }
+ assertionCount++;
+ }
+
+ <T> void m(List<? super T> dummy) { assertTrue(false); }
+ <T> void m(Object dummy) { assertTrue(true); }
+
+ void test(List<?> l) {
+ m(l);
+ assertTrue(assertionCount == 1);
+ }
+
+ public static void main(String[] args) {
+ new T7086586b().test(null);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/inference/7086601/T7086601a.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,34 @@
+/**
+ * @test /nodynamiccopyright/
+ * @bug 7086601
+ * @summary Error message bug: cause for method mismatch is 'null'
+ * @compile/fail/ref=T7086601a.out -XDrawDiagnostics T7086601a.java
+ */
+
+class T7086601 {
+ static <S> void m1(Iterable<? super S> s1, Iterable<? super S> s2) { }
+ static void m1(Object o) {}
+
+ static <S> void m2(Iterable<? super S> s1, Iterable<? super S> s2, Iterable<? super S> s3) { }
+ static void m2(Object o) {}
+
+ @SafeVarargs
+ static <S> void m3(Iterable<? super S>... ss) { }
+ static void m3(Object o) {}
+
+ static void test1(Iterable<String> is, Iterable<Integer> ii) {
+ m1(is, ii);
+ }
+
+ static void test2(Iterable<String> is, Iterable<Integer> ii, Iterable<Double> id) {
+ m2(is, ii, id);
+ }
+
+ static void test3(Iterable<String> is, Iterable<Integer> ii) {
+ m3(is, ii);
+ }
+
+ static void test4(Iterable<String> is, Iterable<Integer> ii, Iterable<Double> id) {
+ m3(is, ii, id);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/inference/7086601/T7086601a.out Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,5 @@
+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))}
+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))}
+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))}
+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))}
+4 errors
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/inference/7086601/T7086601b.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,199 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7086601
+ * @summary Error message bug: cause for method mismatch is 'null'
+ */
+
+import com.sun.source.util.JavacTask;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.ArrayList;
+import javax.tools.Diagnostic;
+import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.ToolProvider;
+
+
+public class T7086601b {
+
+ static int checkCount = 0;
+
+ enum TypeKind {
+ STRING("String", false),
+ INTEGER("Integer", false),
+ NUMBER("Number", false),
+ SERIALIZABLE("java.io.Serializable", true),
+ CLONEABLE("Cloneable", true),
+ X("X", false),
+ Y("Y", false),
+ Z("Z", false);
+
+ String typeStr;
+ boolean isInterface;
+
+ private TypeKind(String typeStr, boolean isInterface) {
+ this.typeStr = typeStr;
+ this.isInterface = isInterface;
+ }
+
+ boolean isSubtypeof(TypeKind other) {
+ return (this == INTEGER && other == NUMBER ||
+ this == Z && other == Y ||
+ this == other);
+ }
+ }
+
+ enum MethodCallKind {
+ ARITY_ONE("m(a1);", 1),
+ ARITY_TWO("m(a1, a2);", 2),
+ ARITY_THREE("m(a1, a2, a3);", 3);
+
+ String invokeString;
+ int arity;
+
+ private MethodCallKind(String invokeString, int arity) {
+ this.invokeString = invokeString;
+ this.arity = arity;
+ }
+ }
+
+ public static void main(String... args) throws Exception {
+
+ //create default shared JavaCompiler - reused across multiple compilations
+ JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
+ StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null);
+
+ for (TypeKind a1 : TypeKind.values()) {
+ for (TypeKind a2 : TypeKind.values()) {
+ for (TypeKind a3 : TypeKind.values()) {
+ for (MethodCallKind mck : MethodCallKind.values()) {
+ new T7086601b(a1, a2, a3, mck).run(comp, fm);
+ }
+ }
+ }
+ }
+ System.out.println("Total check executed: " + checkCount);
+ }
+
+ TypeKind a1;
+ TypeKind a2;
+ TypeKind a3;
+ MethodCallKind mck;
+ JavaSource source;
+ DiagnosticChecker diagChecker;
+
+ T7086601b(TypeKind a1, TypeKind a2, TypeKind a3, MethodCallKind mck) {
+ this.a1 = a1;
+ this.a2 = a2;
+ this.a3 = a3;
+ this.mck = mck;
+ this.source = new JavaSource();
+ this.diagChecker = new DiagnosticChecker();
+ }
+
+ class JavaSource extends SimpleJavaFileObject {
+
+ final String bodyTemplate = "import java.util.List;\n"+
+ "class Test {\n" +
+ " <Z> void m(List<? super Z> l1) { }\n" +
+ " <Z> void m(List<? super Z> l1, List<? super Z> l2) { }\n" +
+ " <Z> void m(List<? super Z> l1, List<? super Z> l2, List<? super Z> l3) { }\n" +
+ " <X,Y,Z extends Y> void test(List<#A1> a1, List<#A2> a2, List<#A3> a3) { #MC } }";
+
+ String source;
+
+ public JavaSource() {
+ super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
+ source = bodyTemplate.replace("#A1", a1.typeStr)
+ .replace("#A2", a2.typeStr).replace("#A3", a3.typeStr)
+ .replace("#MC", mck.invokeString);
+ }
+
+ @Override
+ public CharSequence getCharContent(boolean ignoreEncodingErrors) {
+ return source;
+ }
+ }
+
+ void run(JavaCompiler tool, StandardJavaFileManager fm) throws Exception {
+ JavacTask ct = (JavacTask)tool.getTask(null, fm, diagChecker,
+ null, null, Arrays.asList(source));
+ try {
+ ct.analyze();
+ } catch (Throwable ex) {
+ throw new AssertionError("Error thron when compiling the following code:\n" + source.getCharContent(true));
+ }
+ check();
+ }
+
+ void check() {
+ checkCount++;
+
+ boolean errorExpected = false;
+
+ if (mck.arity > 1) {
+ TypeKind[] argtypes = { a1, a2, a3 };
+ ArrayList<TypeKind> classes = new ArrayList<>();
+ for (int i = 0 ; i < mck.arity ; i ++ ) {
+ if (!argtypes[i].isInterface) {
+ classes.add(argtypes[i]);
+ }
+ }
+ boolean glb_exists = true;
+ for (TypeKind arg_i : classes) {
+ glb_exists = true;
+ for (TypeKind arg_j : classes) {
+ if (!arg_i.isSubtypeof(arg_j)) {
+ glb_exists = false;
+ break;
+ }
+ }
+ if (glb_exists) break;
+ }
+ errorExpected = !glb_exists;
+ }
+
+ if (errorExpected != diagChecker.errorFound) {
+ throw new Error("invalid diagnostics for source:\n" +
+ source.getCharContent(true) +
+ "\nFound error: " + diagChecker.errorFound +
+ "\nExpected error: " + errorExpected);
+ }
+ }
+
+ static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> {
+
+ boolean errorFound;
+
+ public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
+ if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
+ errorFound = true;
+ }
+ }
+ }
+}
--- a/langtools/test/tools/javac/lib/CompileFail.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/test/tools/javac/lib/CompileFail.java Mon Sep 26 14:33:34 2011 -0700
@@ -23,6 +23,7 @@
import java.io.*;
import java.util.*;
+import com.sun.tools.javac.main.Main;
/*
* Utility class to emulate jtreg @compile/fail, but also checking the specific
@@ -58,32 +59,7 @@
}
static int getReturnCode(String name) {
- switch (name) {
- case "OK":
- return EXIT_OK;
-
- case "ERROR":
- return EXIT_ERROR;
-
- case "CMDERR":
- return EXIT_CMDERR;
-
- case "SYSERR":
- return EXIT_SYSERR;
-
- case "ABNORMAL":
- return EXIT_ABNORMAL;
-
- default:
- throw new IllegalArgumentException(name);
- }
+ return Main.Result.valueOf(name).exitCode;
}
- // The following is cut-n-paste from com.sun.tools.javac.main.Main
- static final int
- EXIT_OK = 0, // Compilation completed with no errors.
- EXIT_ERROR = 1, // Completed but reported errors.
- EXIT_CMDERR = 2, // Bad command-line arguments
- EXIT_SYSERR = 3, // System error or resource exhaustion.
- EXIT_ABNORMAL = 4; // Compiler terminated abnormally
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/processing/loader/testClose/TestClose.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,229 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7092965
+ * @summary javac should not close processorClassLoader before end of compilation
+ */
+
+import com.sun.source.util.JavacTask;
+import com.sun.source.util.TaskEvent;
+import com.sun.source.util.TaskListener;
+import com.sun.tools.javac.api.ClientCodeWrapper.Trusted;
+import com.sun.tools.javac.api.JavacTool;
+import com.sun.tools.javac.processing.JavacProcessingEnvironment;
+import com.sun.tools.javac.util.Context;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.lang.reflect.Field;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.tools.JavaFileObject;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
+import javax.tools.ToolProvider;
+
+/*
+ * The test compiles an annotation processor and a helper class into a
+ * custom classes directory.
+ *
+ * It then uses them while compiling a dummy file, with the custom classes
+ * directory on the processor path, thus guaranteeing that references to
+ * these class are satisfied by the processor class loader.
+ *
+ * The annotation processor uses the javac TaskListener to run code
+ * after annotation processing has completed, to verify that the classloader
+ * is not closed until the end of the compilation.
+ */
+
+@Trusted // avoids use of ClientCodeWrapper
+public class TestClose implements TaskListener {
+ public static final String annoProc =
+ "import java.util.*;\n" +
+ "import javax.annotation.processing.*;\n" +
+ "import javax.lang.model.*;\n" +
+ "import javax.lang.model.element.*;\n" +
+ "import com.sun.source.util.*;\n" +
+ "import com.sun.tools.javac.processing.*;\n" +
+ "import com.sun.tools.javac.util.*;\n" +
+ "@SupportedAnnotationTypes(\"*\")\n" +
+ "public class AnnoProc extends AbstractProcessor {\n" +
+ " @Override\n" +
+ " public SourceVersion getSupportedSourceVersion() {\n" +
+ " return SourceVersion.latest();\n" +
+ " }\n" +
+ " @Override\n" +
+ " public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {\n" +
+ " System.out.println(\"in AnnoProc.process\");\n" +
+ " final ClassLoader cl = getClass().getClassLoader();\n" +
+ " if (roundEnv.processingOver()) {\n" +
+ " TestClose.add(processingEnv, new Runnable() {\n" +
+ " public void run() {\n" +
+ " System.out.println(getClass().getName() + \": run()\");\n" +
+ " try {\n" +
+ " cl.loadClass(\"Callback\")\n" +
+ " .asSubclass(Runnable.class)\n" +
+ " .newInstance()\n" +
+ " .run();\n" +
+ " } catch (ReflectiveOperationException e) {\n" +
+ " throw new Error(e);\n" +
+ " }\n" +
+ " }\n" +
+ " });\n" +
+ " }\n" +
+ " return true;\n" +
+ " }\n" +
+ "}\n";
+
+ public static final String callback =
+ "public class Callback implements Runnable {\n" +
+ " public void run() {\n" +
+ " System.out.println(getClass().getName() + \": run()\");\n" +
+ " }\n" +
+ "}";
+
+ public static void main(String... args) throws Exception {
+ new TestClose().run();
+ }
+
+ void run() throws IOException {
+ JavacTool tool = (JavacTool) ToolProvider.getSystemJavaCompiler();
+ StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
+
+ File classes = new File("classes");
+ classes.mkdirs();
+ File extraClasses = new File("extraClasses");
+ extraClasses.mkdirs();
+
+ System.out.println("compiling classes to extraClasses");
+ { // setup class in extraClasses
+ fm.setLocation(StandardLocation.CLASS_OUTPUT,
+ Collections.singleton(extraClasses));
+ List<? extends JavaFileObject> files = Arrays.asList(
+ new MemFile("AnnoProc.java", annoProc),
+ new MemFile("Callback.java", callback));
+ JavacTask task = tool.getTask(null, fm, null, null, null, files);
+ check(task.call());
+ }
+
+ System.out.println("compiling dummy to classes with anno processor");
+ { // use that class in a TaskListener after processing has completed
+ PrintStream prev = System.out;
+ String out;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try (PrintStream ps = new PrintStream(baos)) {
+ System.setOut(ps);
+ File testClasses = new File(System.getProperty("test.classes"));
+ fm.setLocation(StandardLocation.CLASS_OUTPUT,
+ Collections.singleton(classes));
+ fm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH,
+ Arrays.asList(extraClasses, testClasses));
+ List<? extends JavaFileObject> files = Arrays.asList(
+ new MemFile("my://dummy", "class Dummy { }"));
+ List<String> options = Arrays.asList("-processor", "AnnoProc");
+ JavacTask task = tool.getTask(null, fm, null, options, null, files);
+ task.setTaskListener(this);
+ check(task.call());
+ } finally {
+ System.setOut(prev);
+ out = baos.toString();
+ if (!out.isEmpty())
+ System.out.println(out);
+ }
+ check(out.contains("AnnoProc$1: run()"));
+ check(out.contains("Callback: run()"));
+ }
+ }
+
+ @Override
+ public void started(TaskEvent e) {
+ System.out.println("Started: " + e);
+ }
+
+ @Override
+ public void finished(TaskEvent e) {
+ System.out.println("Finished: " + e);
+ if (e.getKind() == TaskEvent.Kind.ANALYZE) {
+ for (Runnable r: runnables) {
+ System.out.println("running " + r);
+ r.run();
+ }
+ }
+ }
+
+ void check(boolean b) {
+ if (!b)
+ throw new AssertionError();
+ }
+
+
+ public static void add(ProcessingEnvironment env, Runnable r) {
+ try {
+ Context c = ((JavacProcessingEnvironment) env).getContext();
+ Object o = c.get(TaskListener.class);
+ // The TaskListener is an instanceof TestClose, but when using the
+ // default class loaders. the taskListener uses a different
+ // instance of Class<TestClose> than the anno processor.
+ // If you try to evaluate
+ // TestClose tc = (TestClose) (o).
+ // you get the following somewhat confusing error:
+ // java.lang.ClassCastException: TestClose cannot be cast to TestClose
+ // The workaround is to access the fields of TestClose with reflection.
+ Field f = o.getClass().getField("runnables");
+ @SuppressWarnings("unchecked")
+ List<Runnable> runnables = (List<Runnable>) f.get(o);
+ runnables.add(r);
+ } catch (Throwable t) {
+ System.err.println(t);
+ }
+ }
+
+ public List<Runnable> runnables = new ArrayList<>();
+
+ class MemFile extends SimpleJavaFileObject {
+ public final String text;
+
+ MemFile(String name, String text) {
+ super(URI.create(name), JavaFileObject.Kind.SOURCE);
+ this.text = text;
+ }
+
+ @Override
+ public String getName() {
+ return uri.toString();
+ }
+
+ @Override
+ public String getCharContent(boolean ignoreEncodingErrors) {
+ return text;
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/processing/loader/testClose/TestClose2.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7092965
+ * @summary javac should not close processorClassLoader before end of compilation
+ */
+
+import com.sun.source.util.JavacTask;
+import com.sun.source.util.TaskEvent;
+import com.sun.source.util.TaskListener;
+import com.sun.tools.javac.api.JavacTool;
+import com.sun.tools.javac.file.JavacFileManager;
+import com.sun.tools.javac.util.Context;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.Messager;
+import javax.annotation.processing.RoundEnvironment;
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.TypeElement;
+import javax.tools.Diagnostic;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
+import javax.tools.ToolProvider;
+
+@SupportedAnnotationTypes("*")
+public class TestClose2 extends AbstractProcessor implements TaskListener {
+
+ public static void main(String... args) throws Exception {
+ new TestClose2().run();
+ }
+
+ void run() throws IOException {
+ File testSrc = new File(System.getProperty("test.src"));
+ File testClasses = new File(System.getProperty("test.classes"));
+
+ JavacTool tool = (JavacTool) ToolProvider.getSystemJavaCompiler();
+ final ClassLoader cl = getClass().getClassLoader();
+ Context c = new Context();
+ StandardJavaFileManager fm = new JavacFileManager(c, true, null) {
+ @Override
+ protected ClassLoader getClassLoader(URL[] urls) {
+ return new URLClassLoader(urls, cl) {
+ @Override
+ public void close() throws IOException {
+ System.err.println(getClass().getName() + " closing");
+ TestClose2.this.closedCount++;
+ TestClose2.this.closedIsLast = true;
+ super.close();
+ }
+ };
+ }
+ };
+
+ fm.setLocation(StandardLocation.CLASS_OUTPUT,
+ Collections.singleton(new File(".")));
+ fm.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH,
+ Collections.singleton(testClasses));
+ Iterable<? extends JavaFileObject> files =
+ fm.getJavaFileObjects(new File(testSrc, TestClose2.class.getName() + ".java"));
+ List<String> options = Arrays.asList(
+ "-processor", TestClose2.class.getName());
+
+ JavacTask task = tool.getTask(null, fm, null, options, null, files);
+ task.setTaskListener(this);
+
+ if (!task.call())
+ throw new Error("compilation failed");
+
+ if (closedCount == 0)
+ throw new Error("no closing message");
+ else if (closedCount > 1)
+ throw new Error(closedCount + " closed messages");
+
+ if (!closedIsLast)
+ throw new Error("closing message not last");
+ }
+
+ // AbstractProcessor methods
+
+ @Override
+ public SourceVersion getSupportedSourceVersion() {
+ return SourceVersion.latest();
+ }
+
+ @Override
+ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ Messager messager = processingEnv.getMessager();
+ messager.printMessage(Diagnostic.Kind.NOTE, "processing");
+ return true;
+ }
+
+ // TaskListener methods
+
+ @Override
+ public void started(TaskEvent e) {
+ System.err.println("Started: " + e);
+ closedIsLast = false;
+ }
+
+ @Override
+ public void finished(TaskEvent e) {
+ System.err.println("Finished: " + e);
+ closedIsLast = false;
+ }
+
+ //
+
+ int closedCount = 0;
+ boolean closedIsLast = false;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/tree/TestToString.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7080267
+ * @summary Call to toString() from an ExpressionStatementTree doesn't take in
+ * consideration the ";" at the end
+ */
+
+import com.sun.source.tree.BlockTree;
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.tree.StatementTree;
+import com.sun.source.tree.Tree;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import javax.tools.JavaFileObject;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.StandardJavaFileManager;
+
+import com.sun.source.util.JavacTask;
+import com.sun.source.util.TreeScanner;
+import com.sun.tools.javac.api.JavacTool;
+
+public class TestToString {
+ String[] statements = {
+ "i = i + 1;",
+ "i++;",
+ "m();",
+ ";",
+ "if (i == 0) return;",
+ "while (i > 0) i--;",
+ "{ }",
+ "{ i++; }",
+ "class C { }"
+ };
+
+ public static void main(String... args) throws Exception {
+ new TestToString().run();
+ }
+
+ void run() throws Exception {
+ for (String s: statements) {
+ test(s);
+ }
+
+ if (errors > 0)
+ throw new Exception(errors + " errors found");
+ }
+
+ void test(String stmt) throws IOException {
+ System.err.println("Test: " + stmt);
+ List<String> options = Collections.<String>emptyList();
+ List<? extends JavaFileObject> files = Arrays.asList(new JavaSource(stmt));
+ JavacTask t = tool.getTask(null, fm, null, options, null, files);
+ checkEqual(scan(t.parse()), stmt);
+ }
+
+ String scan(Iterable<? extends CompilationUnitTree> trees) {
+ class Scanner extends TreeScanner<Void,StringBuilder> {
+ String scan(Iterable<? extends Tree> trees) {
+ StringBuilder sb = new StringBuilder();
+ scan(trees, sb);
+ return sb.toString();
+ }
+ @Override
+ public Void scan(Tree tree, StringBuilder sb) {
+ if (print && tree instanceof StatementTree) {
+ sb.append(PREFIX);
+ sb.append(tree);
+ sb.append(SUFFIX);
+ return null;
+ } else {
+ return super.scan(tree, sb);
+ }
+ }
+ @Override
+ public Void visitBlock(BlockTree tree, StringBuilder sb) {
+ print = true;
+ try {
+ return super.visitBlock(tree, sb);
+ } finally {
+ print = false;
+ }
+ }
+ boolean print = false;
+ }
+ return new Scanner().scan(trees);
+ }
+
+ void checkEqual(String found, String expect) {
+ boolean match = (found == null) ? (expect == null) :
+ expect.equals(found
+ .replaceAll("^\\Q" + PREFIX + "\\E\\s*", "")
+ .replaceAll("\\s*\\Q" + SUFFIX + "\\E$", "")
+ .replaceAll("\\s+", " "));
+
+ if (!match)
+ error("Mismatch: expected: " + expect + " found: " + found);
+ }
+
+
+
+ void error(String msg) {
+ System.err.println("Error: " + msg);
+ errors++;
+ }
+
+ static final String PREFIX = "#<";
+ static final String SUFFIX = "#>";
+
+ JavacTool tool = JavacTool.create();
+ StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
+ int errors = 0;
+
+ static class JavaSource extends SimpleJavaFileObject {
+
+ String source =
+ "class Test {\n" +
+ " int i;\n" +
+ " void m() {\n" +
+ " #S\n" +
+ " }\n" +
+ "}";
+
+ public JavaSource(String stmt) {
+ super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
+ source = source.replace("#S", stmt);
+ }
+
+ @Override
+ public CharSequence getCharContent(boolean ignoreEncodingErrors) {
+ return source;
+ }
+ }
+}
--- a/langtools/test/tools/javac/util/context/T7021650.java Wed Jul 05 17:51:25 2017 +0200
+++ b/langtools/test/tools/javac/util/context/T7021650.java Mon Sep 26 14:33:34 2011 -0700
@@ -101,13 +101,13 @@
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
Main m = new Main("javac", pw);
- int rc = m.compile(args, context);
+ Main.Result res = m.compile(args, context);
pw.close();
String out = sw.toString();
if (!out.isEmpty())
System.err.println(out);
- if (rc != 0)
- throw new Exception("compilation failed unexpectedly: rc=" + rc);
+ if (!res.isOK())
+ throw new Exception("compilation failed unexpectedly: result=" + res);
}
void checkEqual(String label, int found, int expect) throws Exception {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javadoc/parser/7091528/T7091528.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 7091528
+ * @summary javadoc attempts to parse .class files
+ * @compile p/C1.java p/q/C2.java
+ * @run main T7091528
+ */
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+public class T7091528 {
+ public static void main(String... args) {
+ new T7091528().run();
+ }
+
+ void run() {
+ File testSrc = new File(System.getProperty("test.src"));
+ File testClasses = new File(System.getProperty("test.classes"));
+ String[] args = {
+ "-d", ".",
+ "-sourcepath", testClasses + File.pathSeparator + testSrc,
+ "-subpackages",
+ "p"
+ };
+
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ String doclet = com.sun.tools.doclets.standard.Standard.class.getName();
+ int rc = com.sun.tools.javadoc.Main.execute("javadoc", pw, pw, pw, doclet, args);
+ pw.close();
+
+ String out = sw.toString();
+ if (!out.isEmpty()) {
+ System.err.println(out);
+ }
+
+ if (rc != 0)
+ System.err.println("javadoc failed: exit code = " + rc);
+
+ if (out.matches("(?s).*p/[^ ]+\\.class.*"))
+ throw new Error("reading .class files");
+
+ if (!new File("index.html").exists())
+ throw new Error("index.html not found");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javadoc/parser/7091528/p/C1.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package p1;
+
+/** This is class C1. */
+public class C1 { }
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javadoc/parser/7091528/p/q/C2.java Mon Sep 26 14:33:34 2011 -0700
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package p.q;
+
+/** This is class p.q.C2. */
+public class C2 { }
+