# HG changeset patch # User lana # Date 1364929248 25200 # Node ID ea3325542aa8df58c53f2acd9fbc9ccf13d81c17 # Parent e2de240b437f124681f4bb6575241bf6af90a2f0# Parent d7ad0dfaa41151bd3a9ae46725b0aec3730a9cd0 Merge diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/src/share/classes/com/sun/tools/doclint/Checker.java --- a/langtools/src/share/classes/com/sun/tools/doclint/Checker.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/doclint/Checker.java Tue Apr 02 12:00:48 2013 -0700 @@ -122,12 +122,15 @@ private Deque tagStack; // TODO: maybe want to record starting tree as well private HtmlTag currHeaderTag; + private final int implicitHeaderLevel; + // Checker(Env env) { env.getClass(); this.env = env; tagStack = new LinkedList(); + implicitHeaderLevel = env.implicitHeaderLevel; } public Void scan(DocCommentTree tree, TreePath p) { @@ -386,7 +389,7 @@ private int getHeaderLevel(HtmlTag tag) { if (tag == null) - return 0; + return implicitHeaderLevel; switch (tag) { case H1: return 1; case H2: return 2; diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/src/share/classes/com/sun/tools/doclint/DocLint.java --- a/langtools/src/share/classes/com/sun/tools/doclint/DocLint.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/doclint/DocLint.java Tue Apr 02 12:00:48 2013 -0700 @@ -30,6 +30,7 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; import javax.lang.model.element.Name; import javax.tools.StandardLocation; @@ -72,6 +73,7 @@ public static final String XMSGS_OPTION = "-Xmsgs"; public static final String XMSGS_CUSTOM_PREFIX = "-Xmsgs:"; private static final String STATS = "-stats"; + public static final String XIMPLICIT_HEADERS = "-XimplicitHeaders:"; // public static void main(String... args) { @@ -289,6 +291,9 @@ env.messages.setOptions(null); } else if (arg.startsWith(XMSGS_CUSTOM_PREFIX)) { env.messages.setOptions(arg.substring(arg.indexOf(":") + 1)); + } else if (arg.matches(XIMPLICIT_HEADERS + "[1-6]")) { + char ch = arg.charAt(arg.length() - 1); + env.setImplicitHeaders(Character.digit(ch, 10)); } else throw new IllegalArgumentException(arg); } diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/src/share/classes/com/sun/tools/doclint/Env.java --- a/langtools/src/share/classes/com/sun/tools/doclint/Env.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/doclint/Env.java Tue Apr 02 12:00:48 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, 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 @@ -83,6 +83,8 @@ /** Message handler. */ final Messages messages; + int implicitHeaderLevel = 0; + // Utility classes DocTrees trees; Elements elements; @@ -102,7 +104,7 @@ DocCommentTree currDocComment; /** * The access kind of the declaration containing the comment currently being analyzed. - * This is the minimum (most restrictive) access kind of the declaration iteself + * This is the minimum (most restrictive) access kind of the declaration itself * and that of its containers. For example, a public method in a private class is * noted as private. */ @@ -128,6 +130,10 @@ java_lang_Void = elements.getTypeElement("java.lang.Void").asType(); } + void setImplicitHeaders(int n) { + implicitHeaderLevel = n; + } + /** Set the current declaration and its doc comment. */ void setCurrent(TreePath path, DocCommentTree comment) { currPath = path; diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java Tue Apr 02 12:00:48 2013 -0700 @@ -384,18 +384,6 @@ Symbol translatedSym = lambdaContext.getSymbolMap(CAPTURED_VAR).get(tree.sym); result = make.Ident(translatedSym).setType(tree.type); } else { - if (tree.sym.owner.kind == Kinds.TYP) { - for (Map.Entry encl_entry : lambdaContext.getSymbolMap(CAPTURED_THIS).entrySet()) { - if (tree.sym.isMemberOf((ClassSymbol) encl_entry.getKey(), types)) { - JCExpression enclRef = make.Ident(encl_entry.getValue()); - result = tree.sym.name == names._this - ? enclRef.setType(tree.type) - : make.Select(enclRef, tree.sym).setType(tree.type); - result = tree; - return; - } - } - } //access to untranslated symbols (i.e. compile-time constants, //members defined inside the lambda body, etc.) ) super.visitIdent(tree); @@ -1315,6 +1303,7 @@ // the generated lambda method will not have type yet, but the // enclosing method's name will have been generated with this same // method, so it will be unique and never be overloaded. + Assert.check(owner.type != null || directlyEnclosingLambda() != null); if (owner.type != null) { int methTypeHash = methodSig(owner.type).hashCode(); buf.append(Integer.toHexString(methTypeHash)); diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Code.java Tue Apr 02 12:00:48 2013 -0700 @@ -373,6 +373,17 @@ Assert.check(alive || state.stacksize == 0); } + /** Emit a ldc (or ldc_w) instruction, taking into account operand size + */ + public void emitLdc(int od) { + if (od <= 255) { + emitop1(ldc1, od); + } + else { + emitop2(ldc2, od); + } + } + /** Emit a multinewarray instruction. */ public void emitMultianewarray(int ndims, int type, Type arrayType) { diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Gen.java Tue Apr 02 12:00:48 2013 -0700 @@ -2227,7 +2227,7 @@ if (tree.name == names._class) { Assert.check(target.hasClassLiterals()); - code.emitop2(ldc2, makeRef(tree.pos(), tree.selected.type)); + code.emitLdc(makeRef(tree.pos(), tree.selected.type)); result = items.makeStackItem(pt); return; } diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/src/share/classes/com/sun/tools/javac/jvm/Items.java --- a/langtools/src/share/classes/com/sun/tools/javac/jvm/Items.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javac/jvm/Items.java Tue Apr 02 12:00:48 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2013, 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 @@ -571,10 +571,8 @@ int idx = pool.put(value); if (typecode == LONGcode || typecode == DOUBLEcode) { code.emitop2(ldc2w, idx); - } else if (idx <= 255) { - code.emitop1(ldc1, idx); } else { - code.emitop2(ldc2, idx); + code.emitLdc(idx); } } diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/src/share/classes/com/sun/tools/javac/main/Main.java --- a/langtools/src/share/classes/com/sun/tools/javac/main/Main.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javac/main/Main.java Tue Apr 02 12:00:48 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2013, 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 @@ -497,6 +497,8 @@ if (!(doclintOpts.size() == 1 && doclintOpts.iterator().next().equals(DocLint.XMSGS_CUSTOM_PREFIX + "none"))) { JavacTask t = BasicJavacTask.instance(context); + // standard doclet normally generates H1, H2 + doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2"); new DocLint().init(t, doclintOpts.toArray(new String[doclintOpts.size()])); comp.keepComments = true; } diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java --- a/langtools/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/BaseFileManager.java Tue Apr 02 12:00:48 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2013, 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 @@ -112,9 +112,8 @@ protected ClassLoader getClassLoader(URL[] urls) { ClassLoader thisClassLoader = getClass().getClassLoader(); - // Bug: 6558476 - // Ideally, ClassLoader should be Closeable, but before JDK7 it is not. - // On older versions, try the following, to get a closeable classloader. + // Allow the following to specify a closeable classloader + // other than URLClassLoader. // 1: Allow client to specify the class to use via hidden option if (classLoaderClass != null) { @@ -128,19 +127,6 @@ // ignore errors loading user-provided class loader, fall through } } - - // 2: If URLClassLoader implements Closeable, use that. - if (Closeable.class.isAssignableFrom(URLClassLoader.class)) - return new URLClassLoader(urls, thisClassLoader); - - // 3: Try using private reflection-based CloseableURLClassLoader - try { - return new CloseableURLClassLoader(urls, thisClassLoader); - } catch (Throwable t) { - // ignore errors loading workaround class loader, fall through - } - - // 4: If all else fails, use plain old standard URLClassLoader return new URLClassLoader(urls, thisClassLoader); } diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/src/share/classes/com/sun/tools/javac/util/CloseableURLClassLoader.java --- a/langtools/src/share/classes/com/sun/tools/javac/util/CloseableURLClassLoader.java Wed Jul 05 18:48:16 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2007, 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.util; - -import java.io.Closeable; -import java.io.IOException; -import java.lang.reflect.Field; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.jar.JarFile; - -/** - * A URLClassLoader that also implements Closeable. - * Reflection is used to access internal data structures in the URLClassLoader, - * since no public API exists for this purpose. Therefore this code is somewhat - * fragile. Caveat emptor. - * @throws Error if the internal data structures are not as expected. - * - *

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. - */ -public class CloseableURLClassLoader - extends URLClassLoader implements Closeable { - public CloseableURLClassLoader(URL[] urls, ClassLoader parent) throws Error { - super(urls, parent); - try { - getLoaders(); //proactive check that URLClassLoader is as expected - } catch (Throwable t) { - throw new Error("cannot create CloseableURLClassLoader", t); - } - } - - /** - * Close any jar files that may have been opened by the class loader. - * Reflection is used to access the jar files in the URLClassLoader's - * internal data structures. - * @throws java.io.IOException if the jar files cannot be found for any - * reson, or if closing the jar file itself causes an IOException. - */ - @Override - public void close() throws IOException { - try { - for (Object l: getLoaders()) { - if (l.getClass().getName().equals("sun.misc.URLClassPath$JarLoader")) { - Field jarField = l.getClass().getDeclaredField("jar"); - JarFile jar = (JarFile) getField(l, jarField); - if (jar != null) { - //System.err.println("CloseableURLClassLoader: closing " + jar); - jar.close(); - } - } - } - } catch (Throwable t) { - IOException e = new IOException("cannot close class loader"); - e.initCause(t); - throw e; - } - } - - private ArrayList getLoaders() - throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException - { - Field ucpField = URLClassLoader.class.getDeclaredField("ucp"); - Object urlClassPath = getField(this, ucpField); - if (urlClassPath == null) - throw new AssertionError("urlClassPath not set in URLClassLoader"); - Field loadersField = urlClassPath.getClass().getDeclaredField("loaders"); - return (ArrayList) getField(urlClassPath, loadersField); - } - - private Object getField(Object o, Field f) - throws IllegalArgumentException, IllegalAccessException { - boolean prev = f.isAccessible(); - try { - f.setAccessible(true); - return f.get(o); - } finally { - f.setAccessible(prev); - } - } - -} diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/src/share/classes/com/sun/tools/javac/util/Pair.java --- a/langtools/src/share/classes/com/sun/tools/javac/util/Pair.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/Pair.java Tue Apr 02 12:00:48 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,8 @@ package com.sun.tools.javac.util; +import java.util.Objects; + /** A generic class for pairs. * *

This is NOT part of any supported API. @@ -46,15 +48,11 @@ return "Pair[" + fst + "," + snd + "]"; } - private static boolean equals(Object x, Object y) { - return (x == null && y == null) || (x != null && x.equals(y)); - } - public boolean equals(Object other) { return other instanceof Pair && - equals(fst, ((Pair)other).fst) && - equals(snd, ((Pair)other).snd); + Objects.equals(fst, ((Pair)other).fst) && + Objects.equals(snd, ((Pair)other).snd); } public int hashCode() { diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/src/share/classes/com/sun/tools/javadoc/DocEnv.java --- a/langtools/src/share/classes/com/sun/tools/javadoc/DocEnv.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javadoc/DocEnv.java Tue Apr 02 12:00:48 2013 -0700 @@ -810,6 +810,8 @@ JavacTask t = BasicJavacTask.instance(context); doclint = new DocLint(); + // standard doclet normally generates H1, H2 + doclintOpts.add(DocLint.XIMPLICIT_HEADERS + "2"); doclint.init(t, doclintOpts.toArray(new String[doclintOpts.size()]), false); } diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/src/share/classes/javax/annotation/processing/AbstractProcessor.java --- a/langtools/src/share/classes/javax/annotation/processing/AbstractProcessor.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/src/share/classes/javax/annotation/processing/AbstractProcessor.java Tue Apr 02 12:00:48 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2013, 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 @@ -28,6 +28,7 @@ import java.util.Set; import java.util.HashSet; import java.util.Collections; +import java.util.Objects; import javax.lang.model.element.*; import javax.lang.model.SourceVersion; import javax.tools.Diagnostic; @@ -146,8 +147,7 @@ public synchronized void init(ProcessingEnvironment processingEnv) { if (initialized) throw new IllegalStateException("Cannot call init more than once."); - if (processingEnv == null) - throw new NullPointerException("Tool provided null ProcessingEnvironment"); + Objects.requireNonNull(processingEnv, "Tool provided null ProcessingEnvironment"); this.processingEnv = processingEnv; initialized = true; diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/test/tools/javac/T4965689/ClassLiteralWastesByteTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/T4965689/ClassLiteralWastesByteTest.java Tue Apr 02 12:00:48 2013 -0700 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013, 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 4965689 + * @summary class literal code wastes a byte + */ + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.nio.file.Paths; + +public class ClassLiteralWastesByteTest { + + private static final String assertionErrorMsg = + "Instead of ldc_w, ldc instruction should have been generated"; + + public static void main(String[] args) { + new ClassLiteralWastesByteTest().run(); + } + + void run() { + check("-c", Paths.get(System.getProperty("test.classes"), + "test.class").toString()); + } + + void check(String... params) { + StringWriter s; + String out; + try (PrintWriter pw = new PrintWriter(s = new StringWriter())) { + com.sun.tools.javap.Main.run(params, pw); + out = s.toString(); + } + if (out.contains("ldc_w")) { + throw new AssertionError(assertionErrorMsg); + } + } + +} + +class test { + void m() { + Class aClass = test.class; + } +} diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/test/tools/javac/T6558476.java --- a/langtools/test/tools/javac/T6558476.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/test/tools/javac/T6558476.java Tue Apr 02 12:00:48 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2013, 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 @@ -23,6 +23,8 @@ /* * @test + * @bug 6558476 + * @summary com/sun/tools/javac/Main.compile don't release file handles on return * @run main/othervm -Xmx512m -Xms512m T6558476 */ @@ -70,8 +72,7 @@ public static void main(String[] args) throws IOException { File javaHomeDir = new File(System.getProperty("java.home")); - File tmpDir = new File(System.getProperty("java.io.tmpdir")); - File outputDir = new File(tmpDir, "outputDir" + new Random().nextInt(65536)); + File outputDir = new File("outputDir" + new Random().nextInt(65536)); outputDir.mkdir(); outputDir.deleteOnExit(); diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/test/tools/javac/T6900149.java --- a/langtools/test/tools/javac/T6900149.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/test/tools/javac/T6900149.java Tue Apr 02 12:00:48 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, 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 @@ -39,7 +39,7 @@ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); - File emptyFile = File.createTempFile("Empty", ".java"); + File emptyFile = createTempFile("Empty.java"); File[] files = new File[] { emptyFile, emptyFile }; CompilationTask task = compiler.getTask(null, fm, diag, null, null, fm.getJavaFileObjects(files)); @@ -47,4 +47,10 @@ throw new AssertionError("compilation failed"); } } + + private static File createTempFile(String path) throws IOException { + File f = new File(path); + try (FileWriter out = new FileWriter(f)) { } + return f; + } } diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/test/tools/javac/diags/CheckExamples.java --- a/langtools/test/tools/javac/diags/CheckExamples.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/test/tools/javac/diags/CheckExamples.java Tue Apr 02 12:00:48 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, 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 @@ -34,6 +34,8 @@ */ import java.io.*; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; import java.util.*; /** @@ -53,7 +55,27 @@ * Standard entry point. */ public static void main(String... args) throws Exception { - new CheckExamples().run(); + boolean jtreg = (System.getProperty("test.src") != null); + Path tmpDir; + boolean deleteOnExit; + if (jtreg) { + // use standard jtreg scratch directory: the current directory + tmpDir = Paths.get(System.getProperty("user.dir")); + deleteOnExit = false; + } else { + tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), + CheckExamples.class.getName()); + deleteOnExit = true; + } + Example.setTempDir(tmpDir.toFile()); + + try { + new CheckExamples().run(); + } finally { + if (deleteOnExit) { + clean(tmpDir); + } + } } /** @@ -190,6 +212,25 @@ int errors; + /** + * Clean the contents of a directory. + */ + static void clean(Path dir) throws IOException { + Files.walkFileTree(dir, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Files.delete(file); + return super.visitFile(file, attrs); + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + if (exc == null) Files.delete(dir); + return super.postVisitDirectory(dir, exc); + } + }); + } + static class Counts { static String[] prefixes = { "compiler.err.", diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/test/tools/javac/diags/RunExamples.java --- a/langtools/test/tools/javac/diags/RunExamples.java Wed Jul 05 18:48:16 2017 +0200 +++ b/langtools/test/tools/javac/diags/RunExamples.java Tue Apr 02 12:00:48 2013 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2013, 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 @@ -33,7 +33,8 @@ */ import java.io.*; -import java.text.SimpleDateFormat; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -56,16 +57,18 @@ public class RunExamples { public static void main(String... args) throws Exception { jtreg = (System.getProperty("test.src") != null); - File tmpDir; + Path tmpDir; + boolean deleteOnExit; if (jtreg) { // use standard jtreg scratch directory: the current directory - tmpDir = new File(System.getProperty("user.dir")); + tmpDir = Paths.get(System.getProperty("user.dir")); + deleteOnExit = false; } else { - tmpDir = new File(System.getProperty("java.io.tmpdir"), - RunExamples.class.getName() - + (new SimpleDateFormat("yyMMddHHmmss")).format(new Date())); + tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), + RunExamples.class.getName()); + deleteOnExit = true; } - Example.setTempDir(tmpDir); + Example.setTempDir(tmpDir.toFile()); RunExamples r = new RunExamples(); @@ -73,15 +76,8 @@ if (r.run(args)) return; } finally { - /* VERY IMPORTANT NOTE. In jtreg mode, tmpDir is set to the - * jtreg scratch directory, which is the current directory. - * In case someone is faking jtreg mode, make sure to only - * clean tmpDir when it is reasonable to do so. - */ - if (tmpDir.isDirectory() && - tmpDir.getName().startsWith(RunExamples.class.getName())) { - if (clean(tmpDir)) - tmpDir.delete(); + if (deleteOnExit) { + clean(tmpDir); } } @@ -203,14 +199,20 @@ /** * Clean the contents of a directory. */ - static boolean clean(File dir) { - boolean ok = true; - for (File f: dir.listFiles()) { - if (f.isDirectory()) - ok &= clean(f); - ok &= f.delete(); - } - return ok; + static void clean(Path dir) throws IOException { + Files.walkFileTree(dir, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Files.delete(file); + return super.visitFile(file, attrs); + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + if (exc == null) Files.delete(dir); + return super.postVisitDirectory(dir, exc); + } + }); } static abstract class Runner { diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/test/tools/javac/doclint/ImplicitHeadersTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/doclint/ImplicitHeadersTest.java Tue Apr 02 12:00:48 2013 -0700 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013, 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 8006346 + * @summary doclint should make allowance for headers generated by standard doclet + * @compile -Xdoclint:all/public ImplicitHeadersTest.java + */ + +/** + *

Header

+ */ +public class ImplicitHeadersTest { } + diff -r d7ad0dfaa411 -r ea3325542aa8 langtools/test/tools/javadoc/doclint/ImplicitHeadersTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javadoc/doclint/ImplicitHeadersTest.java Tue Apr 02 12:00:48 2013 -0700 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, 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 8006346 + * @summary doclint should make allowance for headers generated by standard doclet + */ + +import java.io.File; + +/** + *

Header

+ */ +public class ImplicitHeadersTest { + public static void main(String... args) { + File testSrc = new File(System.getProperty("test.src")); + File testFile = new File(testSrc, ImplicitHeadersTest.class.getSimpleName() + ".java"); + String[] javadocArgs = { "-d", "out", testFile.getPath() }; + int rc = com.sun.tools.javadoc.Main.execute(javadocArgs); + if (rc != 0) + throw new Error("unexpected exit: rc=" + rc); + } +} +