# HG changeset patch # User lana # Date 1301123494 25200 # Node ID 6aa795396cc8a644d19a3d91a4026f7e4b492826 # Parent 0b40da2d6908a3108c2e79271b1013152f904ccb# Parent c228cf346138c2528cc13abb70229b6ee36094d7 Merge diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/ClassUseWriter.java Sat Mar 26 00:11:34 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -305,11 +305,7 @@ tr.addContent(tdFirst); HtmlTree tdLast = new HtmlTree(HtmlTag.TD); tdLast.addStyle(HtmlStyle.colLast); - if (pkg != null) { - addSummaryComment(pkg, tdLast); - } else { - tdLast.addContent(getSpace()); - } + addSummaryComment(pkg, tdLast); tr.addContent(tdLast); tbody.addContent(tr); } @@ -355,10 +351,7 @@ contentTree.addContent(tdFirst); HtmlTree tdLast = new HtmlTree(HtmlTag.TD); tdLast.addStyle(HtmlStyle.colLast); - if (pkg != null) - addSummaryComment(pkg, tdLast); - else - tdLast.addContent(getSpace()); + addSummaryComment(pkg, tdLast); contentTree.addContent(tdLast); } diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/HelpWriter.java Sat Mar 26 00:11:34 2011 -0700 @@ -283,23 +283,32 @@ Content framePara = HtmlTree.P(line26); liFrame.addContent(framePara); ul.addContent(liFrame); + Content allclassesHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, + getResource("doclet.All_Classes")); + Content liAllClasses = HtmlTree.LI(HtmlStyle.blockList, allclassesHead); + Content line27 = getResource("doclet.Help_line_27", + getHyperLinkString("allclasses-noframe.html", + configuration.getText("doclet.All_Classes"))); + Content allclassesPara = HtmlTree.P(line27); + liAllClasses.addContent(allclassesPara); + ul.addContent(liAllClasses); Content sHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, getResource("doclet.Serialized_Form")); Content liSerial = HtmlTree.LI(HtmlStyle.blockList, sHead); - Content line27 = getResource("doclet.Help_line_27"); - Content serialPara = HtmlTree.P(line27); + Content line28 = getResource("doclet.Help_line_28"); + Content serialPara = HtmlTree.P(line28); liSerial.addContent(serialPara); ul.addContent(liSerial); Content constHead = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, getResource("doclet.Constants_Summary")); Content liConst = HtmlTree.LI(HtmlStyle.blockList, constHead); - Content line28 = getResource("doclet.Help_line_28"); - Content constPara = HtmlTree.P(line28); + Content line29 = getResource("doclet.Help_line_29"); + Content constPara = HtmlTree.P(line29); liConst.addContent(constPara); ul.addContent(liConst); Content divContent = HtmlTree.DIV(HtmlStyle.contentContainer, ul); - Content line29 = HtmlTree.EM(getResource("doclet.Help_line_29")); - divContent.addContent(line29); + Content line30 = HtmlTree.EM(getResource("doclet.Help_line_30")); + divContent.addContent(line30); contentTree.addContent(divContent); } diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageUseWriter.java --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageUseWriter.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/PackageUseWriter.java Sat Mar 26 00:11:34 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -246,10 +246,7 @@ contentTree.addContent(tdFirst); HtmlTree tdLast = new HtmlTree(HtmlTag.TD); tdLast.addStyle(HtmlStyle.colLast); - if (pkg != null) - addSummaryComment(pkg, tdLast); - else - tdLast.addContent(getSpace()); + addSummaryComment(pkg, tdLast); contentTree.addContent(tdLast); } diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties --- a/langtools/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard.properties Sat Mar 26 00:11:34 2011 -0700 @@ -167,7 +167,7 @@ doclet.Help_line_1=How This API Document Is Organized doclet.Help_line_2=This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows. doclet.Help_line_3=The {0} page is the front page of this API document and provides a list of all packages with a summary for each. This page can also contain an overall description of the set of packages. -doclet.Help_line_4=Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories: +doclet.Help_line_4=Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain six categories: doclet.Help_line_5=Class/Interface doclet.Help_line_6=Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions: doclet.Help_line_7=Class inheritance diagram @@ -190,9 +190,10 @@ doclet.Help_line_24=These links take you to the next or previous class, interface, package, or related page. doclet.Help_line_25=Frames/No Frames doclet.Help_line_26=These links show and hide the HTML frames. All pages are available with or without frames. -doclet.Help_line_27=Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. -doclet.Help_line_28=The Constant Field Values page lists the static final fields and their values. -doclet.Help_line_29=This help file applies to API documentation generated using the standard doclet. +doclet.Help_line_27=The {0} link shows all classes and interfaces except non-static nested types. +doclet.Help_line_28=Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description. +doclet.Help_line_29=The Constant Field Values page lists the static final fields and their values. +doclet.Help_line_30=This help file applies to API documentation generated using the standard doclet. doclet.Help_enum_line_1=Each enum has its own separate page with the following sections: doclet.Help_enum_line_2=Enum declaration doclet.Help_enum_line_3=Enum description diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java --- a/langtools/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java Sat Mar 26 00:11: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 @@ -129,19 +129,11 @@ public Boolean call() { if (!used.getAndSet(true)) { - beginContext(); + initContext(); notYetEntered = new HashMap(); - try { - compilerMain.setFatalErrors(true); - result = compilerMain.compile(args, context, fileObjects, processors); - } finally { - endContext(); - } - compilerMain = null; - args = null; - context = null; - fileObjects = null; - notYetEntered = null; + compilerMain.setFatalErrors(true); + result = compilerMain.compile(args, context, fileObjects, processors); + cleanup(); return result == 0; } else { throw new IllegalStateException("multiple calls to method 'call'"); @@ -163,8 +155,11 @@ } private void prepareCompiler() throws IOException { - if (!used.getAndSet(true)) { - beginContext(); + if (used.getAndSet(true)) { + if (compiler == null) + throw new IllegalStateException(); + } else { + initContext(); compilerMain.setOptions(Options.instance(context)); compilerMain.filenames = new ListBuffer(); List filenames = compilerMain.processArgs(CommandLine.parse(args)); @@ -185,13 +180,12 @@ } } - private void beginContext() { + private void initContext() { context.put(JavacTaskImpl.class, this); if (context.get(TaskListener.class) != null) context.put(TaskListener.class, (TaskListener)null); if (taskListener != null) context.put(TaskListener.class, wrap(taskListener)); - tool.beginContext(context); //initialize compiler's default locale JavacMessages.instance(context).setCurrentLocale(locale); } @@ -218,8 +212,15 @@ }; } - private void endContext() { - tool.endContext(); + void cleanup() { + if (compiler != null) + compiler.close(); + compiler = null; + compilerMain = null; + args = null; + context = null; + fileObjects = null; + notYetEntered = null; } /** @@ -446,12 +447,12 @@ } if (genList.isEmpty()) { compiler.reportDeferredDiagnostics(); - compiler.log.flush(); - endContext(); + cleanup(); } } finally { - compiler.log.flush(); + if (compiler != null) + compiler.log.flush(); } return results; } diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/javac/api/JavacTool.java --- a/langtools/src/share/classes/com/sun/tools/javac/api/JavacTool.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/api/JavacTool.java Sat Mar 26 00:11:34 2011 -0700 @@ -152,36 +152,6 @@ return new JavacFileManager(context, true, charset); } - private boolean compilationInProgress = false; - - /** - * Register that a compilation is about to start. - */ - void beginContext(Context context) { - if (compilationInProgress) - throw new IllegalStateException("Compilation in progress"); - compilationInProgress = true; - final JavaFileManager givenFileManager = context.get(JavaFileManager.class); - context.put(JavaFileManager.class, (JavaFileManager)null); - context.put(JavaFileManager.class, new Context.Factory() { - public JavaFileManager make(Context c) { - if (givenFileManager != null) { - c.put(JavaFileManager.class, givenFileManager); - return givenFileManager; - } else { - return new JavacFileManager(c, true, null); - } - } - }); - } - - /** - * Register that a compilation is completed. - */ - void endContext() { - compilationInProgress = false; - } - public JavacTask getTask(Writer out, JavaFileManager fileManager, DiagnosticListener diagnosticListener, diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/javac/code/Source.java --- a/langtools/src/share/classes/com/sun/tools/javac/code/Source.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Source.java Sat Mar 26 00:11:34 2011 -0700 @@ -131,6 +131,12 @@ public boolean allowMulticatch() { return compareTo(JDK1_7) >= 0; } + public boolean allowImprovedRethrowAnalysis() { + return compareTo(JDK1_7) >= 0; + } + public boolean allowImprovedCatchAnalysis() { + return compareTo(JDK1_7) >= 0; + } public boolean allowEnums() { return compareTo(JDK1_5) >= 0; } diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Sat Mar 26 00:11:34 2011 -0700 @@ -3004,6 +3004,30 @@ throw new AssertionError(); } + /** + * Attribute an env for either a top level tree or class declaration. + */ + public void attrib(Env env) { + if (env.tree.getTag() == JCTree.TOPLEVEL) + attribTopLevel(env); + else + attribClass(env.tree.pos(), env.enclClass.sym); + } + + /** + * Attribute a top level tree. These trees are encountered when the + * package declaration has annotations. + */ + public void attribTopLevel(Env env) { + JCCompilationUnit toplevel = env.toplevel; + try { + annotate.flush(); + chk.validateAnnotations(toplevel.packageAnnotations, toplevel.packge); + } catch (CompletionFailure ex) { + chk.completionError(toplevel.pos(), ex); + } + } + /** Main method: attribute class definition associated with given class symbol. * reporting completion failures at the given position. * @param pos The source position at which completion errors are to be diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Flow.java Sat Mar 26 00:11:34 2011 -0700 @@ -190,7 +190,8 @@ private final Resolve rs; private Env attrEnv; private Lint lint; - private final boolean allowRethrowAnalysis; + private final boolean allowImprovedRethrowAnalysis; + private final boolean allowImprovedCatchAnalysis; public static Flow instance(Context context) { Flow instance = context.get(flowKey); @@ -209,7 +210,8 @@ lint = Lint.instance(context); rs = Resolve.instance(context); Source source = Source.instance(context); - allowRethrowAnalysis = source.allowMulticatch(); + allowImprovedRethrowAnalysis = source.allowImprovedRethrowAnalysis(); + allowImprovedCatchAnalysis = source.allowImprovedCatchAnalysis(); } /** A flag that indicates whether the last statement could @@ -1046,7 +1048,9 @@ } } scanStat(tree.body); - List thrownInTry = thrown; + List thrownInTry = allowImprovedCatchAnalysis ? + chk.union(thrown, List.of(syms.runtimeExceptionType, syms.errorType)) : + thrown; thrown = thrownPrev; caught = caughtPrev; boolean aliveEnd = alive; @@ -1081,16 +1085,7 @@ ctypes = ctypes.append(exc); if (types.isSameType(exc, syms.objectType)) continue; - if (chk.subset(exc, caughtInTry)) { - log.error(l.head.pos(), - "except.already.caught", exc); - } else if (!chk.isUnchecked(l.head.pos(), exc) && - exc.tsym != syms.throwableType.tsym && - exc.tsym != syms.exceptionType.tsym && - !chk.intersects(exc, thrownInTry)) { - log.error(l.head.pos(), - "except.never.thrown.in.try", exc); - } + checkCaughtType(l.head.pos(), exc, thrownInTry, caughtInTry); caughtInTry = chk.incl(exc, caughtInTry); } } @@ -1154,6 +1149,29 @@ uninitsTry.andSet(uninitsTryPrev).andSet(uninits); } + void checkCaughtType(DiagnosticPosition pos, Type exc, List thrownInTry, List caughtInTry) { + if (chk.subset(exc, caughtInTry)) { + log.error(pos, "except.already.caught", exc); + } else if (!chk.isUnchecked(pos, exc) && + exc.tsym != syms.throwableType.tsym && + exc.tsym != syms.exceptionType.tsym && + !chk.intersects(exc, thrownInTry)) { + log.error(pos, "except.never.thrown.in.try", exc); + } else if (allowImprovedCatchAnalysis) { + List catchableThrownTypes = chk.intersect(List.of(exc), thrownInTry); + // 'catchableThrownTypes' cannnot possibly be empty - if 'exc' was an + // unchecked exception, the result list would not be empty, as the augmented + // thrown set includes { RuntimeException, Error }; if 'exc' was a checked + // exception, that would have been covered in the branch above + if (chk.diff(catchableThrownTypes, caughtInTry).isEmpty()) { + String key = catchableThrownTypes.length() == 1 ? + "unreachable.catch" : + "unreachable.catch.1"; + log.warning(pos, key, catchableThrownTypes); + } + } + } + public void visitConditional(JCConditional tree) { scanCond(tree.cond); Bits initsBeforeElse = initsWhenFalse; @@ -1238,7 +1256,7 @@ sym.kind == VAR && (sym.flags() & (FINAL | EFFECTIVELY_FINAL)) != 0 && preciseRethrowTypes.get(sym) != null && - allowRethrowAnalysis) { + allowImprovedRethrowAnalysis) { for (Type t : preciseRethrowTypes.get(sym)) { markThrown(tree, t); } diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java --- a/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java Sat Mar 26 00:11:34 2011 -0700 @@ -89,7 +89,7 @@ private FSInfo fsInfo; - private boolean useZipFileIndex; + private boolean contextUseOptimizedZip; private ZipFileIndexCache zipFileIndexCache; private final File uninited = new File("U N I N I T E D"); @@ -164,8 +164,8 @@ fsInfo = FSInfo.instance(context); - useZipFileIndex = options.isSet("useOptimizedZip"); - if (useZipFileIndex) + contextUseOptimizedZip = options.getBoolean("useOptimizedZip", true); + if (contextUseOptimizedZip) zipFileIndexCache = ZipFileIndexCache.getSharedInstance(); mmappedIO = options.isSet("mmappedIO"); @@ -471,9 +471,27 @@ private static final RelativeDirectory symbolFilePrefix = new RelativeDirectory("META-INF/sym/rt.jar/"); + /* + * This method looks for a ZipFormatException and takes appropriate + * evasive action. If there is a failure in the fast mode then we + * fail over to the platform zip, and allow it to deal with a potentially + * non compliant zip file. + */ + protected Archive openArchive(File zipFilename) throws IOException { + try { + return openArchive(zipFilename, contextUseOptimizedZip); + } catch (IOException ioe) { + if (ioe instanceof ZipFileIndex.ZipFormatException) { + return openArchive(zipFilename, false); + } else { + throw ioe; + } + } + } + /** Open a new zip file directory, and cache it. */ - protected Archive openArchive(File zipFileName) throws IOException { + private Archive openArchive(File zipFileName, boolean useOptimizedZip) throws IOException { File origZipFileName = zipFileName; if (!ignoreSymbolFile && paths.isDefaultBootClassPathRtJar(zipFileName)) { File file = zipFileName.getParentFile().getParentFile(); // ${java.home} @@ -495,7 +513,7 @@ boolean usePreindexedCache = false; String preindexCacheLocation = null; - if (!useZipFileIndex) { + if (!useOptimizedZip) { zdir = new ZipFile(zipFileName); } else { usePreindexedCache = options.isSet("usezipindex"); @@ -524,23 +542,22 @@ } if (origZipFileName == zipFileName) { - if (!useZipFileIndex) { + if (!useOptimizedZip) { archive = new ZipArchive(this, zdir); } else { archive = new ZipFileIndexArchive(this, - zipFileIndexCache.getZipFileIndex(zipFileName, + zipFileIndexCache.getZipFileIndex(zipFileName, null, usePreindexedCache, preindexCacheLocation, options.isSet("writezipindexfiles"))); } } else { - if (!useZipFileIndex) { + if (!useOptimizedZip) { archive = new SymbolArchive(this, origZipFileName, zdir, symbolFilePrefix); - } - else { + } else { archive = new ZipFileIndexArchive(this, - zipFileIndexCache.getZipFileIndex(zipFileName, + zipFileIndexCache.getZipFileIndex(zipFileName, symbolFilePrefix, usePreindexedCache, preindexCacheLocation, @@ -549,6 +566,8 @@ } } catch (FileNotFoundException ex) { archive = new MissingArchive(zipFileName); + } catch (ZipFileIndex.ZipFormatException zfe) { + throw zfe; } catch (IOException ex) { if (zipFileName.exists()) log.error("error.reading.file", zipFileName, getMessage(ex)); diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java --- a/langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java Sat Mar 26 00:11:34 2011 -0700 @@ -492,8 +492,30 @@ public ZipDirectory(RandomAccessFile zipRandomFile, long start, long end, ZipFileIndex index) throws IOException { this.zipRandomFile = zipRandomFile; this.zipFileIndex = index; + hasValidHeader(); + findCENRecord(start, end); + } - findCENRecord(start, end); + /* + * the zip entry signature should be at offset 0, otherwise allow the + * calling logic to take evasive action by throwing ZipFormatException. + */ + private boolean hasValidHeader() throws IOException { + final long pos = zipRandomFile.getFilePointer(); + try { + if (zipRandomFile.read() == 'P') { + if (zipRandomFile.read() == 'K') { + if (zipRandomFile.read() == 0x03) { + if (zipRandomFile.read() == 0x04) { + return true; + } + } + } + } + } finally { + zipRandomFile.seek(pos); + } + throw new ZipFormatException("invalid zip magic"); } /* @@ -529,7 +551,13 @@ zipDir = new byte[get4ByteLittleEndian(endbuf, i + 12) + 2]; zipDir[0] = endbuf[i + 10]; zipDir[1] = endbuf[i + 11]; - zipRandomFile.seek(start + get4ByteLittleEndian(endbuf, i + 16)); + int sz = get4ByteLittleEndian(endbuf, i + 16); + // a negative offset or the entries field indicates a + // potential zip64 archive + if (sz < 0 || get2ByteLittleEndian(zipDir, 0) == 0xffff) { + throw new ZipFormatException("detected a zip64 archive"); + } + zipRandomFile.seek(start + sz); zipRandomFile.readFully(zipDir, 2, zipDir.length - 2); return; } else { @@ -1127,4 +1155,18 @@ } } + /* + * Exception primarily used to implement a failover, used exclusively here. + */ + + static final class ZipFormatException extends IOException { + private static final long serialVersionUID = 8000196834066748623L; + protected ZipFormatException(String message) { + super(message); + } + + protected ZipFormatException(String message, Throwable cause) { + super(message, cause); + } + } } diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java --- a/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Sat Mar 26 00:11:34 2011 -0700 @@ -638,6 +638,19 @@ } } + /** Resolve an identifier which may be the binary name of a class or + * the Java name of a class or package. + * @param name The name to resolve + */ + public Symbol resolveBinaryNameOrIdent(String name) { + try { + Name flatname = names.fromString(name.replace("/", ".")); + return reader.loadClass(flatname); + } catch (CompletionFailure ignore) { + return resolveIdent(name); + } + } + /** Resolve an identifier. * @param name The identifier to resolve */ @@ -1058,7 +1071,7 @@ } else { boolean errors = false; for (String nameStr : classnames) { - Symbol sym = resolveIdent(nameStr); + Symbol sym = resolveBinaryNameOrIdent(nameStr); if (sym == null || (sym.kind == Kinds.PCK && !processPcks)) { log.error("proc.cant.find.class", nameStr); errors = true; @@ -1166,7 +1179,7 @@ env.enclClass.sym.sourcefile : env.toplevel.sourcefile); try { - attr.attribClass(env.tree.pos(), env.enclClass.sym); + attr.attrib(env); if (errorCount() > 0 && !shouldStop(CompileState.ATTR)) { //if in fail-over mode, ensure that AST expression nodes //are correctly initialized (e.g. they have a type/symbol) diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/javac/model/JavacTypes.java --- a/langtools/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Sat Mar 26 00:11: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 @@ -73,9 +73,14 @@ public Element asElement(TypeMirror t) { Type type = cast(Type.class, t); - if (type.tag != TypeTags.CLASS && type.tag != TypeTags.TYPEVAR) - return null; - return type.asElement(); + switch (type.tag) { + case TypeTags.CLASS: + case TypeTags.ERROR: + case TypeTags.TYPEVAR: + return type.asElement(); + default: + return null; + } } public boolean isSameType(TypeMirror t1, TypeMirror t2) { diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java --- a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Sat Mar 26 00:11:34 2011 -0700 @@ -820,13 +820,17 @@ /** The set of package-info files to be processed this round. */ List packageInfoFiles; + /** The number of Messager errors generated in this round. */ + int nMessagerErrors; + /** Create a round (common code). */ - private Round(Context context, int number, int priorWarnings) { + private Round(Context context, int number, int priorErrors, int priorWarnings) { this.context = context; this.number = number; compiler = JavaCompiler.instance(context); log = Log.instance(context); + log.nerrors = priorErrors; log.nwarnings += priorWarnings; log.deferDiagnostics = true; @@ -840,7 +844,7 @@ /** Create the first round. */ Round(Context context, List roots, List classSymbols) { - this(context, 1, 0); + this(context, 1, 0, 0); this.roots = roots; genClassFiles = new HashMap(); @@ -860,7 +864,10 @@ /** Create a new round. */ private Round(Round prev, Set newSourceFiles, Map newClassFiles) { - this(prev.nextContext(), prev.number+1, prev.compiler.log.nwarnings); + this(prev.nextContext(), + prev.number+1, + prev.nMessagerErrors, + prev.compiler.log.nwarnings); this.genClassFiles = prev.genClassFiles; List parsedFiles = compiler.parseFiles(newSourceFiles); @@ -1014,6 +1021,8 @@ if (taskListener != null) taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND)); } + + nMessagerErrors = messager.errorCount(); } void showDiagnostics(boolean showAll) { diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties --- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties Sat Mar 26 00:11:34 2011 -0700 @@ -1102,6 +1102,16 @@ cast to {0} for a varargs call\n\ cast to {1} for a non-varargs call and to suppress this warning +# 0: list of type +compiler.warn.unreachable.catch=\ + unreachable catch clause\n\ + thrown type {0} has already been caught + +# 0: list of type +compiler.warn.unreachable.catch.1=\ + unreachable catch clause\n\ + thrown types {0} have already been caught + # 0: symbol compiler.warn.long.SVUID=\ serialVersionUID must be of type long in class {0} diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java --- a/langtools/src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/BasicDiagnosticFormatter.java Sat Mar 26 00:11: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 @@ -26,6 +26,7 @@ package com.sun.tools.javac.util; import java.util.Collection; +import java.util.EnumMap; import java.util.EnumSet; import java.util.HashMap; import java.util.Locale; @@ -226,17 +227,14 @@ DiagnosticPart.SOURCE)); initFormat(); initIndentation(); + if (options.isSet("oldDiags")) + initOldFormat(); String fmt = options.get("diagsFormat"); if (fmt != null) { - String[] formats = fmt.split("\\|"); - switch (formats.length) { - case 3: - setFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT, formats[2]); - case 2: - setFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT, formats[1]); - default: - setFormat(BasicFormatKind.DEFAULT_POS_FORMAT, formats[0]); - } + if (fmt.equals("OLD")) + initOldFormat(); + else + initFormats(fmt); } String srcPos = null; if ((((srcPos = options.get("sourcePosition")) != null)) && @@ -280,14 +278,35 @@ initFormat(); initIndentation(); } - //where + private void initFormat() { - availableFormats = new HashMap(); - setFormat(BasicFormatKind.DEFAULT_POS_FORMAT, "%f:%l:%_%t%L%m"); - setFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT, "%p%L%m"); - setFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT, "%f:%_%t%L%m"); + initFormats("%f:%l:%_%p%L%m", "%p%L%m", "%f:%_%p%L%m"); + } + + private void initOldFormat() { + initFormats("%f:%l:%_%t%L%m", "%p%L%m", "%f:%_%t%L%m"); + } + + private void initFormats(String pos, String nopos, String clazz) { + availableFormats = new EnumMap(BasicFormatKind.class); + setFormat(BasicFormatKind.DEFAULT_POS_FORMAT, pos); + setFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT, nopos); + setFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT, clazz); } - //where + + @SuppressWarnings("fallthrough") + private void initFormats(String fmt) { + String[] formats = fmt.split("\\|"); + switch (formats.length) { + case 3: + setFormat(BasicFormatKind.DEFAULT_CLASS_FORMAT, formats[2]); + case 2: + setFormat(BasicFormatKind.DEFAULT_NO_POS_FORMAT, formats[1]); + default: + setFormat(BasicFormatKind.DEFAULT_POS_FORMAT, formats[0]); + } + } + private void initIndentation() { indentationLevels = new HashMap(); setIndentation(DiagnosticPart.SUMMARY, 0); diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/com/sun/tools/javac/util/Options.java --- a/langtools/src/share/classes/com/sun/tools/javac/util/Options.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/Options.java Sat Mar 26 00:11:34 2011 -0700 @@ -76,6 +76,22 @@ } /** + * Get the boolean value for an option, patterned after Boolean.getBoolean, + * essentially will return true, iff the value exists and is set to "true". + */ + public boolean getBoolean(String name) { + return getBoolean(name, false); + } + + /** + * Get the boolean with a default value if the option is not set. + */ + public boolean getBoolean(String name, boolean defaultValue) { + String value = get(name); + return (value == null) ? defaultValue : Boolean.parseBoolean(value); + } + + /** * Check if the value for an undocumented option has been set. */ public boolean isSet(String name) { diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/javax/lang/model/element/Element.java --- a/langtools/src/share/classes/javax/lang/model/element/Element.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/javax/lang/model/element/Element.java Sat Mar 26 00:11:34 2011 -0700 @@ -197,11 +197,12 @@ *
  • If this is a {@linkplain * PackageElement#getEnclosingElement package}, {@code null} is * returned. - + * *
  • If this is a {@linkplain * TypeParameterElement#getEnclosingElement type parameter}, - * {@code null} is returned. - + * {@linkplain TypeParameterElement#getGenericElement the + * generic element} of the type parameter is returned. + * * * * @return the enclosing element, or {@code null} if there is none diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/src/share/classes/javax/lang/model/element/TypeParameterElement.java --- a/langtools/src/share/classes/javax/lang/model/element/TypeParameterElement.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/src/share/classes/javax/lang/model/element/TypeParameterElement.java Sat Mar 26 00:11:34 2011 -0700 @@ -64,9 +64,9 @@ List getBounds(); /** - * Returns {@code null}. + * Returns the {@linkplain TypeParameterElement#getGenericElement generic element} of this type parameter. * - * @return {@code null} + * @return the generic element of this type parameter */ @Override Element getEnclosingElement(); diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/com/sun/javadoc/testUseOption/C.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/com/sun/javadoc/testUseOption/C.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,41 @@ +/* + * 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. + */ + +/** + * Class in an unnamed package. + */ + +public class C { + + /** + * Field in C. + */ + public UsedInC fieldInC; + + /** + * Method in C. + */ + public UsedInC methodInC(UsedInC p) { + return p; + } +} diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/com/sun/javadoc/testUseOption/TestUseOption.java --- a/langtools/test/com/sun/javadoc/testUseOption/TestUseOption.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/com/sun/javadoc/testUseOption/TestUseOption.java Sat Mar 26 00:11:34 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 4496290 4985072 + * @bug 4496290 4985072 7006178 * @summary A simple test to determine if -use works. * @author jamieh * @library ../lib/ @@ -34,7 +34,7 @@ public class TestUseOption extends JavadocTester { - private static final String BUG_ID = "4496290-4985072"; + private static final String BUG_ID = "4496290-4985072-7006178"; //Input for string search tests. private static final String[] TEST2 = { @@ -54,6 +54,16 @@ "Method in C8.", }; + private static final String[][] TEST3 = { + {BUG_ID + "-3" + FS + "class-use" + FS + "UsedInC.html", "Uses of " + + "UsedInC in <Unnamed>" + }, + {BUG_ID + "-3" + FS + "package-use.html", "" + + "UsedInC " + } + }; + private static final String[] ARGS = new String[] { "-d", BUG_ID, "-sourcepath", SRC_DIR, "-use", "pkg1", "pkg2" }; @@ -62,6 +72,10 @@ "-d", BUG_ID+"-2", "-sourcepath", SRC_DIR, "-use", "pkg1", "pkg2" }; + private static final String[] ARGS3 = new String[] { + "-d", BUG_ID + "-3", "-sourcepath", SRC_DIR, "-use", SRC_DIR + FS + "C.java", SRC_DIR + FS + "UsedInC.java" + }; + /** * The entry point of the test. * @param args the array of command line arguments. @@ -93,6 +107,8 @@ prevIndex = currentIndex; } tester.printSummary(); + run(tester, ARGS3, TEST3, NO_TEST); + tester.printSummary(); } /** diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/com/sun/javadoc/testUseOption/UsedInC.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/com/sun/javadoc/testUseOption/UsedInC.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,26 @@ +/* + * 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. + */ + +public class UsedInC +{ +} diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/apt/Compile/golden.txt --- a/langtools/test/tools/apt/Compile/golden.txt Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/apt/Compile/golden.txt Sat Mar 26 00:11:34 2011 -0700 @@ -1,6 +1,6 @@ error: It's a mad, mad, mad, mad world error: Something wicked this way comes -HelloWorld.java:2: Boring class name +HelloWorld.java:2: error: Boring class name public class HelloWorld { ^ 3 errors diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/4846262/Test.out --- a/langtools/test/tools/javac/4846262/Test.out Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/4846262/Test.out Sat Mar 26 00:11:34 2011 -0700 @@ -1,7 +1,7 @@ -Test.java:4: not a statement +Test.java:4: error: not a statement abcdefg ^ -Test.java:4: ';' expected +Test.java:4: error: ';' expected abcdefg ^ 2 errors diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/6508981/TestInferBinaryName.java --- a/langtools/test/tools/javac/6508981/TestInferBinaryName.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/6508981/TestInferBinaryName.java Sat Mar 26 00:11:34 2011 -0700 @@ -139,9 +139,8 @@ throws IOException { Context ctx = new Context(); Options options = Options.instance(ctx); - // uugh, ugly back door, should be cleaned up, someday - if (zipFileIndexKind == USE_ZIP_FILE_INDEX) - options.put("useOptimizedZip", "true"); + options.put("useOptimizedZip", + Boolean.toString(zipFileIndexKind == USE_ZIP_FILE_INDEX)); if (symFileKind == IGNORE_SYMBOL_FILE) options.put("ignore.symbol.file", "true"); diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/6558548/T6558548.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/6558548/T6558548.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,300 @@ +/* + * @test /nodynamiccopyright/ + * @bug 6558548 + * @summary The compiler needs to be aligned with clarified specification of throws + * @compile/fail/ref=T6558548_latest.out -XDrawDiagnostics T6558548.java + * @compile/fail/ref=T6558548_6.out -source 6 -XDrawDiagnostics T6558548.java + */ + +class T6558548 { + + void nothing() {} + void checked() throws InterruptedException {} + void runtime() throws IllegalArgumentException {} + + void m1() { + try { + throw new java.io.FileNotFoundException(); + } + catch(java.io.FileNotFoundException exc) { } + catch(java.io.IOException exc) { } // 6: ok; latest: unreachable + } + + void m1a() { + try { + throw new java.io.IOException(); + } + catch(java.io.FileNotFoundException exc) { } + catch(java.io.IOException exc) { } //ok + } + + void m2() { + try { + nothing(); + } + catch(Exception exc) { } // ok + } + + void m3() { + try { + checked(); + } + catch(Exception exc) { } //ok + } + + void m4() { + try { + runtime(); + } + catch(Exception exc) { } //ok + } + + void m5() { + try { + nothing(); + } + catch(Throwable exc) { } //ok + } + + void m6() { + try { + checked(); + } + catch(Throwable exc) { } //ok + } + + void m7() { + try { + runtime(); + } + catch(Throwable exc) { } //ok + } + + void m9() { + try { + checked(); + } + catch(Error exc) { } + catch(Throwable exc) { } //ok + } + + void m10() { + try { + runtime(); + } + catch(Error exc) { } + catch(Throwable exc) { } //ok + } + + void m11() { + try { + nothing(); + } + catch(Error exc) { } + catch(Throwable exc) { } //ok + } + + void m12() { + try { + checked(); + } + catch(RuntimeException exc) { } + catch(Throwable exc) { } // ok + } + + void m13() { + try { + runtime(); + } + catch(RuntimeException exc) { } + catch(Throwable exc) { } // ok + } + + void m14() { + try { + nothing(); + } + catch(RuntimeException exc) { } + catch(Throwable exc) { } // ok + } + + void m15() { + try { + checked(); + } + catch(RuntimeException exc) { } + catch(Exception exc) { } //ok + } + + void m16() { + try { + runtime(); + } + catch(RuntimeException exc) { } + catch(Exception exc) { } //6: ok; latest: unreachable + } + + void m17() { + try { + nothing(); + } + catch(RuntimeException exc) { } + catch(Exception exc) { } //6: ok; latest: unreachable + } + + void m18() { + try { + checked(); + } + catch(RuntimeException exc) { } + catch(InterruptedException exc) { } + catch(Exception exc) { } //6: ok; latest: unreachable + } + + void m19() { + try { + runtime(); + } + catch(RuntimeException exc) { } + catch(InterruptedException exc) { } //never thrown in try + catch(Exception exc) { } //6: ok; latest: unreachable + } + + void m20() { + try { + nothing(); + } + catch(RuntimeException exc) { } + catch(InterruptedException exc) { } //never thrown in try + catch(Exception exc) { } //6: ok; latest: unreachable + } + + void m21() { + try { + checked(); + } + catch(RuntimeException exc) { } + catch(Exception exc) { } // ok + } + + void m22() { + try { + runtime(); + } + catch(RuntimeException exc) { } + catch(Exception exc) { } // 6: ok; latest: unreachable + } + + void m23() { + try { + nothing(); + } + catch(RuntimeException exc) { } + catch(Exception exc) { } // 6: ok; latest: unreachable + } + + void m24() { + try { + checked(); + } + catch(RuntimeException exc) { } + catch(Error exc) { } + catch(Throwable exc) { } //ok + } + + void m25() { + try { + runtime(); + } + catch(RuntimeException exc) { } + catch(Error exc) { } + catch(Throwable exc) { } //6: ok; latest: unreachable + } + + void m26() { + try { + nothing(); + } + catch(RuntimeException exc) { } + catch(Error exc) { } + catch(Throwable exc) { } //6: ok; latest: unreachable + } + + void m27() { + try { + checked(); + } + catch(RuntimeException exc) { } + catch(Error exc) { } + catch(InterruptedException exc) { } + catch(Throwable exc) { } //6: ok; latest: unreachable + } + + void m28() { + try { + runtime(); + } + catch(RuntimeException exc) { } + catch(Error exc) { } + catch(InterruptedException exc) { } //never thrown in try + catch(Throwable exc) { } //6: ok; latest: unreachable + } + + void m29() { + try { + nothing(); + } + catch(RuntimeException exc) { } + catch(Error exc) { } + catch(InterruptedException exc) { } //never thrown in try + catch(Throwable exc) { } //6: ok; latest: unreachable + } + + void m30() { + try { + checked(); + } + catch(RuntimeException exc) { } + catch(Error exc) { } + catch(Throwable exc) { } //ok + } + + void m31() { + try { + runtime(); + } + catch(RuntimeException exc) { } + catch(Error exc) { } + catch(Throwable exc) { } //6: ok; latest: unreachable + } + + void m32() { + try { + nothing(); + } + catch(RuntimeException exc) { } + catch(Error exc) { } + catch(Throwable exc) { } //6: ok; latest: unreachable + } + + void m33() { + try { + checked(); + } + catch(InterruptedException exc) { } //ok + } + + void m34() { + try { + runtime(); + } + catch(InterruptedException exc) { } //never thrown in try + } + + void m35() { + try { + nothing(); + } + catch(InterruptedException exc) { } //never thrown in try + } +} diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/6558548/T6558548_6.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/6558548/T6558548_6.out Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,9 @@ +- compiler.warn.source.no.bootclasspath: 1.6 +T6558548.java:159:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException +T6558548.java:168:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException +T6558548.java:239:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException +T6558548.java:249:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException +T6558548.java:291:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException +T6558548.java:298:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException +6 errors +1 warning diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/6558548/T6558548_latest.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/6558548/T6558548_latest.out Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,23 @@ +T6558548.java:20:9: compiler.warn.unreachable.catch: java.io.FileNotFoundException +T6558548.java:134:9: compiler.warn.unreachable.catch: java.lang.RuntimeException +T6558548.java:142:9: compiler.warn.unreachable.catch: java.lang.RuntimeException +T6558548.java:151:9: compiler.warn.unreachable.catch.1: java.lang.InterruptedException,java.lang.RuntimeException +T6558548.java:159:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException +T6558548.java:160:9: compiler.warn.unreachable.catch: java.lang.RuntimeException +T6558548.java:168:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException +T6558548.java:169:9: compiler.warn.unreachable.catch: java.lang.RuntimeException +T6558548.java:185:9: compiler.warn.unreachable.catch: java.lang.RuntimeException +T6558548.java:193:9: compiler.warn.unreachable.catch: java.lang.RuntimeException +T6558548.java:211:9: compiler.warn.unreachable.catch.1: java.lang.RuntimeException,java.lang.Error +T6558548.java:220:9: compiler.warn.unreachable.catch.1: java.lang.RuntimeException,java.lang.Error +T6558548.java:230:9: compiler.warn.unreachable.catch.1: java.lang.InterruptedException,java.lang.RuntimeException,java.lang.Error +T6558548.java:239:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException +T6558548.java:240:9: compiler.warn.unreachable.catch.1: java.lang.RuntimeException,java.lang.Error +T6558548.java:249:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException +T6558548.java:250:9: compiler.warn.unreachable.catch.1: java.lang.RuntimeException,java.lang.Error +T6558548.java:268:9: compiler.warn.unreachable.catch.1: java.lang.RuntimeException,java.lang.Error +T6558548.java:277:9: compiler.warn.unreachable.catch.1: java.lang.RuntimeException,java.lang.Error +T6558548.java:291:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException +T6558548.java:298:9: compiler.err.except.never.thrown.in.try: java.lang.InterruptedException +6 errors +15 warnings diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/Diagnostics/6769027/T6769027.java --- a/langtools/test/tools/javac/Diagnostics/6769027/T6769027.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/Diagnostics/6769027/T6769027.java Sat Mar 26 00:11:34 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -261,7 +261,7 @@ enum PositionKind { NOPOS(Position.NOPOS, "- ", "error: "), - POS(5, "Test.java:1:6: ", "/Test.java:1: "); + POS(5, "Test.java:1:6: ", "/Test.java:1: error: "); int pos; String rawOutput; diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/Diagnostics/7010608/Test.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/Diagnostics/7010608/Test.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,92 @@ +/* + * 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 7010608 + * @summary the string 'error' should appear in error messages + */ + +import java.io.*; +import java.net.URI; +import java.util.*; +import javax.tools.*; +import javax.tools.JavaCompiler.CompilationTask; + +public class Test { + public static void main(String... args) throws Exception { + new Test().run(); + } + + void run() throws Exception { + Locale prev = Locale.getDefault(); + Locale.setDefault(Locale.ENGLISH); + try { + test(Arrays.asList(), + "myfo://test:1: error: cannot find symbol"); + test(Arrays.asList("-XDdiagsFormat=OLD"), + "myfo://test:1: cannot find symbol"); + test(Arrays.asList("-XDoldDiags"), + "myfo://test:1: cannot find symbol"); + } finally { + Locale.setDefault(prev); + } + } + + void test(List options, String expect) throws Exception { + System.err.println("test: " + options); + JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + JavaFileObject f = new MyFileObject("myfo://test", "class Bad { Missing x; }"); + List files = Arrays.asList(f); + CompilationTask task = javac.getTask(pw, null, null, options, null, files); + boolean ok = task.call(); + pw.close(); + String out = sw.toString(); + if (!out.isEmpty()) + System.err.println(out); + if (ok) + throw new Exception("Compilation succeeded unexpectedly"); + if (!out.contains(expect)) + throw new Exception("expected text not found: " + expect); + } + + class MyFileObject extends SimpleJavaFileObject { + MyFileObject(String uri, String text) { + super(URI.create(uri), JavaFileObject.Kind.SOURCE); + this.text = text; + } + @Override + public String getName() { + return uri.toString(); + } + @Override + public String getCharContent(boolean ignoreEncodingErrors) { + return text; + } + final String text; + } +} + + diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/annotations/TestAnnotationPackageInfo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/annotations/TestAnnotationPackageInfo.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,87 @@ +/* + * 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 6993311 + * @summary annotations on packages are not validated + */ + +import java.io.*; +import java.net.*; +import java.util.*; +import javax.tools.*; +import com.sun.source.util.*; + +public class TestAnnotationPackageInfo { + public static void main(String... args) throws Exception { + new TestAnnotationPackageInfo().run(); + } + + static class MyFileObject extends SimpleJavaFileObject { + private String text; + public MyFileObject(String fileName, String text) { + super(URI.create("myfo:/" + fileName), JavaFileObject.Kind.SOURCE); + this.text = text; + } + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return text; + } + } + + public void run() throws Exception { + final String bootPath = System.getProperty("sun.boot.class.path"); + final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); + assert tool != null; + + JavaFileObject test_java = new MyFileObject("test/Test.java", + "package test; public @interface Test {\n" + + " public int mandatory();\n" + + "}\n"); + + JavaFileObject package_info_java = new MyFileObject("test/package-info.java", + "@Test package test;"); + + DiagnosticCollector coll = new DiagnosticCollector(); + + List options = Arrays.asList("-bootclasspath", bootPath); + List files = Arrays.asList(test_java, package_info_java); + JavacTask ct = (JavacTask)tool.getTask(null, null, coll, options, null, files); + ct.analyze(); + + String expectedCode = "compiler.err.annotation.missing.default.value"; + List> diags = coll.getDiagnostics(); + switch (diags.size()) { + case 0: + throw new Exception("no diagnostics reported"); + case 1: + String code = diags.get(0).getCode(); + if (code.equals(expectedCode)) + return; + throw new Exception("unexpected diag: " + diags.get(0)); + default: + throw new Exception("unexpected diags reported: " + diags); + } + } +} diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/annotations/pos/package-info.java --- a/langtools/test/tools/javac/annotations/pos/package-info.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/annotations/pos/package-info.java Sat Mar 26 00:11:34 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -23,12 +23,12 @@ /* * @test - * @bug 4901290 + * @bug 4901290 6993311 * @summary Package annotations * @author gafter * * @compile package-info.java */ -@java.lang.annotation.Documented +@Deprecated package foo.bar; diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/api/6411310/Test.java --- a/langtools/test/tools/javac/api/6411310/Test.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/api/6411310/Test.java Sat Mar 26 00:11:34 2011 -0700 @@ -153,14 +153,12 @@ Context c = new Context(); Options options = Options.instance(c); - if (useOptimizedZip) { - options.put("useOptimizedZip", "true"); - } + options.put("useOptimizedZip", Boolean.toString(useOptimizedZip)); - if (!useSymbolFile) { - options.put("ignore.symbol.file", "true"); - } - return new JavacFileManager(c, false, null); + if (!useSymbolFile) { + options.put("ignore.symbol.file", "true"); + } + return new JavacFileManager(c, false, null); } File createDir(String name, String... entries) throws Exception { diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/api/6557752/T6557752.java --- a/langtools/test/tools/javac/api/6557752/T6557752.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/api/6557752/T6557752.java Sat Mar 26 00:11:34 2011 -0700 @@ -118,7 +118,8 @@ Types types = task.getTypes(); - if (types.asElement(trees.getOriginalType((ErrorType)typeMirror)) != null) { + str1 = types.asElement(trees.getOriginalType((ErrorType)typeMirror)).toString(); + if (!str1.equals("FooBar")) { throw new AssertionError("Types.asElement() error!"); } foundError = true; diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/api/T6838467.java --- a/langtools/test/tools/javac/api/T6838467.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/api/T6838467.java Sat Mar 26 00:11:34 2011 -0700 @@ -178,12 +178,10 @@ return fm; } - JavacFileManager createFileManager(boolean useOptimedZipIndex) { + JavacFileManager createFileManager(boolean useOptimizedZip) { Context ctx = new Context(); - if (useOptimedZipIndex) { - Options options = Options.instance(ctx); - options.put("useOptimizedZip", "true"); - } + Options options = Options.instance(ctx); + options.put("useOptimizedZip", Boolean.toString(useOptimizedZip)); return new JavacFileManager(ctx, false, null); } diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/api/T6877206.java --- a/langtools/test/tools/javac/api/T6877206.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/api/T6877206.java Sat Mar 26 00:11:34 2011 -0700 @@ -168,9 +168,7 @@ JavacFileManager createFileManager(boolean useOptimizedZip, boolean useSymbolFile) { Context ctx = new Context(); Options options = Options.instance(ctx); - if (useOptimizedZip) { - options.put("useOptimizedZip", "true"); - } + options.put("useOptimizedZip", Boolean.toString(useOptimizedZip)); if (!useSymbolFile) { options.put("ignore.symbol.file", "true"); } diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/api/TestJavacTask_Lock.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/api/TestJavacTask_Lock.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,111 @@ +/* + * 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 7026509 + * @summary Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations + */ + +import java.io.*; +import java.util.*; +import javax.tools.*; +import javax.tools.JavaCompiler.CompilationTask; +import com.sun.source.util.*; + +public class TestJavacTask_Lock { + public static void main(String... args) throws Exception { + new TestJavacTask_Lock().run(); + } + + enum MethodKind { + CALL { + int test(CompilationTask t) { + boolean ok = t.call(); + if (!ok) + throw new Error("compilation failed"); + return 1; + } + }, + PARSE { + int test(CompilationTask t) { + try { + ((JavacTask) t).parse(); + return 1; + } catch (IOException ex) { + throw new Error(ex); + } + } + + }; + abstract int test(CompilationTask t); + } + + JavaCompiler comp; + StandardJavaFileManager fm; + + void run() throws Exception { + comp = ToolProvider.getSystemJavaCompiler(); + fm = comp.getStandardFileManager(null, null, null); + + for (MethodKind first: MethodKind.values()) { + for (MethodKind second: MethodKind.values()) { + test(first, second); + } + } + + if (errors > 0) + throw new Exception(errors + " errors found"); + } + + void test(MethodKind first, MethodKind second) { + System.err.println("test: " + first + ", " + second); + File testSrc = new File(System.getProperty("test.src")); + String thisClassName = TestJavacTask_Lock.class.getName(); + Iterable files = + fm.getJavaFileObjects(new File(testSrc, thisClassName + ".java")); + File tmpDir = new File(first + "_" + second); + tmpDir.mkdirs(); + List options = Arrays.asList( "-d", tmpDir.getPath() ); + CompilationTask t = comp.getTask(null, fm, null, options, null, files); + + try { + first.test(t); + second.test(t); + error("No exception thrown"); + } catch (IllegalStateException e) { + System.err.println("Expected exception caught: " + e); + } catch (Exception e) { + error("Unexpected exception caught: " + e); + e.printStackTrace(System.err); + } + + } + + void error(String msg) { + System.err.println("Error: " + msg); + errors++; + } + + int errors; +} diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/api/TestJavacTask_Multiple.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/api/TestJavacTask_Multiple.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,118 @@ +/* + * 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 7026509 + * @summary Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations + */ + +import java.io.*; +import java.util.*; +import javax.tools.*; +import javax.tools.JavaCompiler.CompilationTask; +import com.sun.source.util.*; + +public class TestJavacTask_Multiple { + public static void main(String... args) throws Exception { + new TestJavacTask_Multiple().run(); + } + + final int MAX_TASKS = 3; + + enum TestKind { + CALL { + int test(CompilationTask t) { + boolean ok = t.call(); + if (!ok) + throw new Error("compilation failed"); + return 1; + } + }, + PARSE { + int test(CompilationTask t) { + try { + ((JavacTask) t).parse(); + return 1; + } catch (IOException ex) { + throw new Error(ex); + } + } + + }; + abstract int test(CompilationTask t); + } + + int count; + + void run() throws Exception { + JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); + StandardJavaFileManager fm = comp.getStandardFileManager(null, null, null); + for (TestKind tk: TestKind.values()) { + test(comp, fm, tk); + } + + int expect = TestKind.values().length * MAX_TASKS; + if (count != expect) { + throw new Exception("Unexpected number of tests completed: " + count + + ", expected: " + expect); + } + + } + + void test(JavaCompiler comp, StandardJavaFileManager fm, TestKind tk) { + System.err.println("test " + tk); + File testSrc = new File(System.getProperty("test.src")); + String thisClassName = TestJavacTask_Multiple.class.getName(); + Iterable files = + fm.getJavaFileObjects(new File(testSrc, thisClassName + ".java")); + + List tasks = new ArrayList(); + for (int i = 1; i <= MAX_TASKS; i++) { + File tmpDir = new File(tk + "_" + i); + tmpDir.mkdirs(); + List options = Arrays.asList( "-d", tmpDir.getPath() ); + CompilationTask t = comp.getTask(null, fm, null, options, null, files); + ((JavacTask) t).setTaskListener(createTaskListener(tk, i)); + tasks.add(t); + } + + for (CompilationTask t: tasks) + count += tk.test(t); + + System.err.println(); + } + + TaskListener createTaskListener(final TestKind tk, final int i) { + return new TaskListener() { + + public void started(TaskEvent e) { + System.err.println(tk + "." + i + ": " + e + " started"); + } + + public void finished(TaskEvent e) { + System.err.println(tk + "." + i + ": " + e + " finished"); + } + }; + } +} diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/api/TestJavacTask_ParseAttrGen.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/api/TestJavacTask_ParseAttrGen.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,127 @@ +/* + * 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 7026509 + * @summary Cannot use JavaCompiler to create multiple CompilationTasks for partial compilations + */ + +import java.io.*; +import java.util.*; +import javax.lang.model.element.*; +import javax.tools.*; +import com.sun.source.tree.*; +import com.sun.source.util.*; + +public class TestJavacTask_ParseAttrGen { + public static void main(String... args) throws Exception { + new TestJavacTask_ParseAttrGen().run(); + } + + JavaCompiler comp; + StandardJavaFileManager fm; + + void run() throws Exception { + comp = ToolProvider.getSystemJavaCompiler(); + fm = comp.getStandardFileManager(null, null, null); + + final boolean[] booleanValues = { false, true }; + for (boolean pk: booleanValues) { + for (boolean ak: booleanValues) { + for (boolean gk: booleanValues) { + test(pk, ak, gk); + } + } + } + } + + void test(boolean pk, boolean ak, boolean gk) throws Exception { + if (!pk && !ak && !gk) // nothing to do + return; + + System.err.println("test: pk:" + pk + ", ak:" + ak + ", gk: " + gk); + File testSrc = new File(System.getProperty("test.src")); + String thisClassName = TestJavacTask_ParseAttrGen.class.getName(); + Iterable files = + fm.getJavaFileObjects(new File(testSrc, thisClassName + ".java")); + File tmpDir = new File((pk ? "p" : "") + (ak ? "a" : "") + (gk ? "g" : "")); + tmpDir.mkdirs(); + fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tmpDir)); + JavacTask t = (JavacTask) comp.getTask(null, fm, null, null, null, files); + //t.setTaskListener(createTaskListener()); + + try { + if (pk) { + Iterable trees = t.parse(); + System.err.println(count(trees) + " trees parsed"); + } + + if (ak) { + Iterable elems = t.analyze(); + System.err.println(count(elems) + " elements analyzed"); + } + + if (gk) { + Iterable classfiles = t.generate(); + System.err.println(count(classfiles) + " class files generated"); + } + } catch (IOException e) { + error("unexpected exception caught: " + e); + } + + File[] genFiles = tmpDir.listFiles(); + int expect = (gk ? 2 : 0); // main class and anon class for TaskListener + if (genFiles.length != expect) + error("unexpected number of files generated: " + genFiles.length + + ", expected: " + expect); + + System.err.println(); + } + + TaskListener createTaskListener() { + return new TaskListener() { + public void started(TaskEvent e) { + System.err.println(e + " started"); + } + + public void finished(TaskEvent e) { + System.err.println(e + " finished"); + } + }; + } + + int count(Iterable items) { + int count = 0; + for (T item: items) + count++; + return count; + } + + void error(String msg) { + System.err.println("Error: " + msg); + errors++; + } + + int errors; +} diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/diags/examples/CountError.java --- a/langtools/test/tools/javac/diags/examples/CountError.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/diags/examples/CountError.java Sat Mar 26 00:11:34 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -23,6 +23,7 @@ // key: compiler.misc.count.error // key: compiler.err.unreported.exception.need.to.catch.or.throw +// key: compiler.err.error // run: backdoor class CountError { diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/diags/examples/CountErrorPlural.java --- a/langtools/test/tools/javac/diags/examples/CountErrorPlural.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/diags/examples/CountErrorPlural.java Sat Mar 26 00:11:34 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -23,6 +23,7 @@ // key: compiler.misc.count.error.plural // key: compiler.err.unreported.exception.need.to.catch.or.throw +// key: compiler.err.error // run: backdoor class CountErrorPlural { diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/diags/examples/IdentifierExpected.java --- a/langtools/test/tools/javac/diags/examples/IdentifierExpected.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/diags/examples/IdentifierExpected.java Sat Mar 26 00:11:34 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -25,6 +25,7 @@ // key: compiler.err.expected // key: compiler.err.invalid.binary.number // key: compiler.misc.count.error.plural +// key: compiler.err.error // run: backdoor class IdentifierExpected { diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/diags/examples/KindnameClass.java --- a/langtools/test/tools/javac/diags/examples/KindnameClass.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/diags/examples/KindnameClass.java Sat Mar 26 00:11:34 2011 -0700 @@ -25,6 +25,7 @@ // key: compiler.err.cant.resolve.location // key: compiler.misc.location // key: compiler.misc.count.error +// key: compiler.err.error // run: backdoor class KindnameClass { diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/diags/examples/KindnameConstructor.java --- a/langtools/test/tools/javac/diags/examples/KindnameConstructor.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/diags/examples/KindnameConstructor.java Sat Mar 26 00:11:34 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -28,6 +28,7 @@ // key: compiler.misc.arg.length.mismatch // key: compiler.misc.no.conforming.assignment.exists // key: compiler.misc.count.error.plural +// key: compiler.err.error // run: backdoor class KindnameConstructor { diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/diags/examples/KindnameMethod.java --- a/langtools/test/tools/javac/diags/examples/KindnameMethod.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/diags/examples/KindnameMethod.java Sat Mar 26 00:11:34 2011 -0700 @@ -26,6 +26,7 @@ // key: compiler.err.cant.resolve.location.args // key: compiler.misc.location // key: compiler.misc.count.error +// key: compiler.err.error // run: backdoor class KindnameMethod { diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/diags/examples/KindnameVariable.java --- a/langtools/test/tools/javac/diags/examples/KindnameVariable.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/diags/examples/KindnameVariable.java Sat Mar 26 00:11:34 2011 -0700 @@ -26,6 +26,7 @@ // key: compiler.err.cant.resolve.location // key: compiler.misc.location // key: compiler.misc.count.error +// key: compiler.err.error // run: backdoor class KindnameVariable { diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/diags/examples/UnreachableCatch.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/diags/examples/UnreachableCatch.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,35 @@ +/* + * 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.warn.unreachable.catch + +class UnreachableCatch { + + void test() { + try { + throw new java.io.FileNotFoundException(); + } + catch(java.io.FileNotFoundException exc) { } + catch(java.io.IOException exc) { } //unreachable + } +} diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/diags/examples/UnreachableCatch1.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/diags/examples/UnreachableCatch1.java Sat Mar 26 00:11: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. + */ + +// key: compiler.warn.unreachable.catch.1 + +class UnreachableCatch1 { + + void test() { + try { + throw new IllegalArgumentException(); + } + catch(Error err) { } + catch(RuntimeException rex) { } + catch(Throwable t) { } //unreachable + } +} diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/file/zip/T6836682.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/file/zip/T6836682.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,241 @@ +/* + * 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 6836682 7025988 + * @summary JavacFileManager handling of zip64 archives (Scenario A and B) + * @compile -XDignore.symbol.file T6836682.java Utils.java + * @run main T6836682 + */ +/* + * This test consists of two scenarios: + * + * Scenario A: create a jar with entries exceeding 64K, and see if the javac + * can handle this large jar on the classpath. Generally this test completes + * within a minute + * + * Scenario B: create a jar with a large enough file exceeding 4GB, and + * similarly test javac. This test is known to be slow and problematic on + * certain operating systems, thus this test can be selected by passing a + * property through jtreg as follows: + * -javaoptions=-DT6836682.testScenarioB=true. + * Note this test will only run iff all the disk requirements are met at runtime. + */ +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.zip.CRC32; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +public class T6836682 { + + private static final long GIGA = 1024 * 1024 * 1024; + private static final int BUFFER_LEN = Short.MAX_VALUE * 2; + + static long getCount(long minlength) { + return (minlength / BUFFER_LEN) + 1; + } + + static long computeCRC(long minlength) { + CRC32 crc = new CRC32(); + byte[] buffer = new byte[BUFFER_LEN]; + long count = getCount(minlength); + for (long i = 0; i < count; i++) { + crc.update(buffer); + } + return crc.getValue(); + } + + static long computeCRC(File inFile) throws IOException { + byte[] buffer = new byte[8192]; + CRC32 crc = new CRC32(); + FileInputStream fis = null; + BufferedInputStream bis = null; + try { + fis = new FileInputStream(inFile); + bis = new BufferedInputStream(fis); + int n = bis.read(buffer); + while (n > 0) { + crc.update(buffer, 0, n); + n = bis.read(buffer); + } + } finally { + Utils.close(bis); + Utils.close(fis); + } + return crc.getValue(); + } + + static void createLargeFile(OutputStream os, long minlength) throws IOException { + byte[] buffer = new byte[BUFFER_LEN]; + long count = getCount(minlength); + for (long i = 0; i < count; i++) { + os.write(buffer); + } + os.flush(); + } + + static void createJarWithLargeFile(File jarFile, File javaFile, + long minlength) throws IOException { + Utils.createClassFile(javaFile, null, true); + File classFile = new File(Utils.getClassFileName(javaFile)); + ZipOutputStream zos = null; + BufferedOutputStream bos = null; + FileInputStream fis = null; + try { + zos = new ZipOutputStream(new FileOutputStream(jarFile)); + zos.setLevel(ZipOutputStream.STORED); + zos.setMethod(0); + bos = new BufferedOutputStream(zos); + + ZipEntry ze = new ZipEntry("large.data"); + ze.setCompressedSize(getCount(minlength) * BUFFER_LEN); + ze.setSize(getCount(minlength) * BUFFER_LEN); + ze.setCrc(computeCRC(minlength)); + ze.setMethod(ZipEntry.STORED); + zos.putNextEntry(ze); + createLargeFile(bos, minlength); + + ze = new ZipEntry(classFile.getName()); + ze.setCompressedSize(classFile.length()); + ze.setSize(classFile.length()); + ze.setCrc(computeCRC(classFile)); + ze.setMethod(ZipEntry.STORED); + zos.putNextEntry(ze); + fis = new FileInputStream(classFile); + Utils.copyStream(fis, bos); + bos.flush(); + zos.closeEntry(); + } finally { + Utils.close(bos); + Utils.close(zos); + Utils.close(fis); + } + // deleted to prevent accidental linkage + new File(Utils.getClassFileName(javaFile)).delete(); + } + + static void createLargeJar(File jarFile, File javaFile) throws IOException { + File classFile = new File(Utils.getClassFileName(javaFile)); + Utils.createClassFile(javaFile, null, true); + ZipOutputStream zos = null; + FileInputStream fis = null; + final int MAX = Short.MAX_VALUE * 2 + 10; + ZipEntry ze = null; + try { + zos = new ZipOutputStream(new FileOutputStream(jarFile)); + zos.setLevel(ZipOutputStream.STORED); + zos.setMethod(ZipOutputStream.STORED); + for (int i = 0; i < MAX ; i++) { + ze = new ZipEntry("X" + i + ".txt"); + ze.setSize(0); + ze.setCompressedSize(0); + ze.setCrc(0); + zos.putNextEntry(ze); + } + + // add a class file + ze = new ZipEntry(classFile.getName()); + ze.setCompressedSize(classFile.length()); + ze.setSize(classFile.length()); + ze.setCrc(computeCRC(classFile)); + zos.putNextEntry(ze); + fis = new FileInputStream(classFile); + Utils.copyStream(fis, zos); + } finally { + Utils.close(zos); + Utils.close(fis); + // deleted to prevent accidental linkage + new File(Utils.getClassFileName(javaFile)).delete(); + } + } + + // a jar with entries exceeding 64k + a class file for the existential test + public static void testScenarioA(String... args) throws IOException { + File largeJar = new File("large.jar"); + File javaFile = new File("Foo.java"); + createLargeJar(largeJar, javaFile); + + File testFile = new File("Bar.java"); + try { + Utils.createJavaFile(testFile, javaFile); + if (!Utils.compile("-doe", "-verbose", "-cp", + largeJar.getAbsolutePath(), testFile.getAbsolutePath())) { + throw new IOException("test failed"); + } + } finally { + Utils.deleteFile(largeJar); + } + } + + // a jar with an enormous file + a class file for the existential test + public static void testScenarioB(String... args) throws IOException { + final File largeJar = new File("huge.jar"); + final File javaFile = new File("Foo.java"); + + final Path path = largeJar.getAbsoluteFile().getParentFile().toPath(); + final long available = Files.getFileStore(path).getUsableSpace(); + final long MAX_VALUE = 0xFFFF_FFFFL; + + final long absolute = MAX_VALUE + 1L; + final long required = (long)(absolute * 1.1); // pad for sundries + System.out.println("\tavailable: " + available / GIGA + " GB"); + System.out.println("\trequired: " + required / GIGA + " GB"); + + if (available > required) { + createJarWithLargeFile(largeJar, javaFile, absolute); + File testFile = new File("Bar.java"); + Utils.createJavaFile(testFile, javaFile); + try { + if (!Utils.compile("-doe", "-verbose", "-cp", + largeJar.getAbsolutePath(), testFile.getAbsolutePath())) { + throw new IOException("test failed"); + } + } finally { + Utils.deleteFile(largeJar); + } + } else { + System.out.println("Warning: testScenarioB passes vacuously," + + " requirements exceeds available space"); + } + } + + public static void main(String... args) throws IOException { + testScenarioA(); + System.out.println("testScenarioA: PASS"); + if (Boolean.getBoolean("T6836682.testScenarioB")) { + testScenarioB(); + System.out.println("testScenarioB: PASS"); + } else { + System.out.println("Warning: testScenarioB, large file test skipped"); + } + } +} diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/file/zip/T6865530.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/file/zip/T6865530.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,66 @@ +/* + * 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 6865530 + * @summary ensure JavacFileManager handles non-standard zipfiles. + * @compile -XDignore.symbol.file T6865530.java + * @run main T6865530 + */ + + +import java.io.File; + + +public class T6865530 { + + public static void main(String... args) throws Exception { + File badFile = new File("bad.exe"); + File testJar = new File("test.jar"); + File fooJava = new File("Foo.java"); + File barJava = new File("Bar.java"); + + // create a jar by compiling a file, and append the jar to some + // arbitrary data to offset the start of the zip/jar archive + Utils.createJavaFile(fooJava); + Utils.compile("-doe", "-verbose", fooJava.getName()); + String[] jarArgs = { + "cvf", testJar.getAbsolutePath(), "Foo.class" + }; + Utils.jarTool.run(jarArgs); + Utils.cat(badFile, fooJava, testJar); + + // create test file and use the above file as a classpath + Utils.createJavaFile(barJava); + try { + if (!Utils.compile("-doe", "-verbose", "-cp", badFile.getAbsolutePath(), "Bar.java")) { + throw new RuntimeException("test fails javac did not compile"); + } + } finally { + Utils.deleteFile(badFile); + Utils.deleteFile(testJar); + } + } +} + diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/file/zip/Utils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/file/zip/Utils.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,131 @@ +/* + * 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. + */ + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.Closeable; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintStream; + +public class Utils { + + static final sun.tools.jar.Main jarTool = + new sun.tools.jar.Main(System.out, System.err, "jar-tool"); + + static final com.sun.tools.javac.Main javac = + new com.sun.tools.javac.Main(); + + private Utils(){} + + public static boolean compile(String... args) { + return javac.compile(args) == 0; + } + + public static void createClassFile(File javaFile, File superClass, + boolean delete) throws IOException { + createJavaFile(javaFile, superClass); + if (!compile(javaFile.getName())) { + throw new RuntimeException("compile failed unexpectedly"); + } + if (delete) javaFile.delete(); + } + + public static void createJavaFile(File outFile) throws IOException { + createJavaFile(outFile, null); + } + + public static void createJavaFile(File outFile, File superClass) throws IOException { + PrintStream ps = null; + String srcStr = "public class " + getSimpleName(outFile) + " "; + if (superClass != null) { + srcStr = srcStr.concat("extends " + getSimpleName(superClass) + " "); + } + srcStr = srcStr.concat("{}"); + try { + FileOutputStream fos = new FileOutputStream(outFile); + ps = new PrintStream(fos); + ps.println(srcStr); + } finally { + close(ps); + } + } + + static String getClassFileName(File javaFile) { + return javaFile.getName().endsWith(".java") + ? javaFile.getName().replace(".java", ".class") + : null; + } + + static String getSimpleName(File inFile) { + String fname = inFile.getName(); + return fname.substring(0, fname.indexOf(".")); + } + + public static void copyStream(InputStream in, OutputStream out) throws IOException { + byte[] buf = new byte[8192]; + int n = in.read(buf); + while (n > 0) { + out.write(buf, 0, n); + n = in.read(buf); + } + } + + public static void close(Closeable c) { + if (c != null) { + try { + c.close(); + } catch (IOException ignore) {} + } + } + + public static void deleteFile(File f) { + if (!f.delete()) { + throw new RuntimeException("could not delete file: " + f.getAbsolutePath()); + } + } + + public static void cat(File output, File... files) throws IOException { + BufferedInputStream bis = null; + BufferedOutputStream bos = null; + FileOutputStream fos = null; + try { + fos = new FileOutputStream(output); + bos = new BufferedOutputStream(fos); + for (File x : files) { + FileInputStream fis = new FileInputStream(x); + bis = new BufferedInputStream(fis); + copyStream(bis, bos); + Utils.close(bis); + } + } finally { + Utils.close(bis); + Utils.close(bos); + Utils.close(fos); + } + } +} diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/lib/JavacTestingAbstractProcessor.java --- a/langtools/test/tools/javac/lib/JavacTestingAbstractProcessor.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/lib/JavacTestingAbstractProcessor.java Sat Mar 26 00:11:34 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -24,8 +24,6 @@ import java.util.*; import javax.annotation.processing.*; import javax.lang.model.SourceVersion; -import static javax.lang.model.SourceVersion.*; -import javax.lang.model.element.*; import javax.lang.model.util.*; /** diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/processing/6430209/b6341534.java --- a/langtools/test/tools/javac/processing/6430209/b6341534.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/processing/6430209/b6341534.java Sat Mar 26 00:11:34 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 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 @@ -56,7 +56,9 @@ // on round 1, expect errorRaised == false && processingOver == false // on round 2, expect errorRaised == true && processingOver == true if( renv.errorRaised() != renv.processingOver()) { - messager.printMessage(ERROR, "FAILED"); + messager.printMessage(ERROR, "FAILED: round:" + r + + ", errorRaised:" + renv.errorRaised() + + ", processingOver:" + renv.processingOver()); } return true; } diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/processing/6994946/SemanticErrorTest.2.out --- a/langtools/test/tools/javac/processing/6994946/SemanticErrorTest.2.out Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/processing/6994946/SemanticErrorTest.2.out Sat Mar 26 00:11:34 2011 -0700 @@ -1,4 +1,4 @@ SemanticErrorTest.java:11:46: compiler.err.repeated.interface - compiler.err.proc.messager: Deliberate Error SemanticErrorTest.java:11:46: compiler.err.repeated.interface -1 error +2 errors diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/processing/environment/round/TestContext.java --- a/langtools/test/tools/javac/processing/environment/round/TestContext.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/processing/environment/round/TestContext.java Sat Mar 26 00:11:34 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -34,7 +34,6 @@ import java.util.*; import javax.annotation.processing.*; import javax.lang.model.element.*; -import javax.tools.*; import static javax.tools.Diagnostic.Kind.*; import com.sun.source.util.Trees; diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/processing/errors/TestErrorCount.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/processing/errors/TestErrorCount.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,46 @@ +/* + * 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 6988079 + * @summary Errors reported via Messager.printMessage(ERROR,"error message") are not tallied correctly + * @library ../../lib + * @build JavacTestingAbstractProcessor TestErrorCount + * @compile/fail/ref=TestErrorCount.out -XDrawDiagnostics -processor TestErrorCount TestErrorCount.java + */ + +import java.io.*; +import java.util.*; +import javax.annotation.processing.*; +import javax.lang.model.element.*; +import javax.tools.*; + +public class TestErrorCount extends JavacTestingAbstractProcessor { + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + messager.printMessage(Diagnostic.Kind.ERROR, "intentional error"); + return true; + } +} + diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/processing/errors/TestErrorCount.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/processing/errors/TestErrorCount.out Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,3 @@ +- compiler.err.proc.messager: intentional error +- compiler.err.proc.messager: intentional error +2 errors diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/processing/filer/TestPackageInfo.java --- a/langtools/test/tools/javac/processing/filer/TestPackageInfo.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/processing/filer/TestPackageInfo.java Sat Mar 26 00:11:34 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 6380018 6392177 + * @bug 6380018 6392177 6993311 * @summary Test the ability to create and process package-info.java files * @author Joseph D. Darcy * @library ../../lib @@ -60,7 +60,7 @@ // Verify annotations are as expected Set expectedAnnotations = new HashSet(); - expectedAnnotations.add(eltUtils.getTypeElement("java.lang.SuppressWarnings")); + expectedAnnotations.add(eltUtils.getTypeElement("java.lang.Deprecated")); if (!roundEnv.processingOver()) { System.out.println("\nRound " + round); @@ -90,7 +90,7 @@ } catch(FilerException fe) {} PrintWriter pw = new PrintWriter(filer.createSourceFile("foo.package-info").openWriter()); - pw.println("@SuppressWarnings(\"\")"); + pw.println("@Deprecated"); pw.println("package foo;"); pw.close(); diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/processing/filer/foo/bar/package-info.java --- a/langtools/test/tools/javac/processing/filer/foo/bar/package-info.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/processing/filer/foo/bar/package-info.java Sat Mar 26 00:11:34 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 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 @@ -24,5 +24,5 @@ /** * Javadoc for the foo.bar package! */ -@SuppressWarnings("deprecation") +@Deprecated package foo.bar; diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/processing/model/element/TestAnonClassNames.java --- a/langtools/test/tools/javac/processing/model/element/TestAnonClassNames.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/processing/model/element/TestAnonClassNames.java Sat Mar 26 00:11:34 2011 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 6449781 + * @bug 6449781 6930508 * @summary Test that reported names of anonymous classes are non-null. * @author Joseph D. Darcy * @library ../../../lib @@ -93,6 +93,7 @@ TestAnonClassNames.class, }; + List names = new ArrayList(); for(Class clazz : classes) { String name = clazz.getName(); Nesting anno = clazz.getAnnotation(Nesting.class); @@ -100,7 +101,14 @@ clazz.getName(), anno == null ? "(unset/ANONYMOUS)" : anno.value()); testClassName(name); + names.add(name); } + + // test all names together + testClassNames(names); + + if (errors > 0) + throw new RuntimeException(errors + " errors occurred"); } /** @@ -109,15 +117,23 @@ * input classes are modeled as elements. */ static void testClassName(String className) { - JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler(); - List classNames = new ArrayList(); - classNames.add(className); + testClassNames(Arrays.asList(className)); + } + + /** + * Perform annotation processing on a list of class file names and verify + * the existence of different flavors of class names when the + * input classes are modeled as elements. + */ + static void testClassNames(List classNames) { + System.out.println("test: " + classNames); List options = new ArrayList(); options.add("-proc:only"); options.add("-classpath"); options.add(System.getProperty("test.classes")); + JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler(); JavaCompiler.CompilationTask compileTask = javaCompiler.getTask(null, // Output null, // File manager @@ -130,9 +146,16 @@ compileTask.setProcessors(processors); Boolean goodResult = compileTask.call(); if (!goodResult) { - throw new RuntimeException("Errors found during compile."); + error("Errors found during compile."); } } + + static int errors = 0; + + static void error(String msg) { + System.out.println("Error: " + msg); + errors++; + } } @Retention(RUNTIME) diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java --- a/langtools/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java Thu Mar 24 11:20:59 2011 -0700 +++ b/langtools/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java Sat Mar 26 00:11:34 2011 -0700 @@ -24,7 +24,7 @@ /* * @test - * @bug 6639645 + * @bug 6639645 7026414 * @summary Modeling type implementing missing interfaces * @library ../../../../lib * @build JavacTestingAbstractProcessor TestMissingElement @@ -112,6 +112,7 @@ @Override public String visitDeclared(DeclaredType t, Void ignore) { + checkEqual(t.asElement(), types.asElement(t)); String s = asString(t.asElement()); List args = t.getTypeArguments(); if (!args.isEmpty()) @@ -179,6 +180,13 @@ return (e != null && e.getKind() == ElementKind.PACKAGE && ((PackageElement) e).isUnnamed()); } + + void checkEqual(Element e1, Element e2) { + if (e1 != e2) { + throw new AssertionError("elements not equal as expected: " + + e1 + ", " + e2); + } + } } diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/processing/options/testCommandLineClasses/Test.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/processing/options/testCommandLineClasses/Test.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,106 @@ +/* + * 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 6930508 + * @summary Passing nested class names on javac command line interfere with subsequent name -> class lookup + * @library ../../../lib + * @build JavacTestingAbstractProcessor p.NestedExamples Test + * @run main Test + */ + +import java.io.*; +import java.util.*; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.element.TypeElement; +import javax.lang.model.util.ElementFilter; +import javax.tools.*; + +import p.NestedExamples; + +public class Test extends JavacTestingAbstractProcessor { + public static void main(String... args) throws Exception { + new Test().run(); + } + + void run() throws Exception { + NestedExamples e = new NestedExamples(); + List names = getNames(e.getClasses()); + test(names); + test(reverse(names)); + names = Arrays.asList(e.getClassNames()); + test(names); + test(reverse(names)); + + if (errors > 0) + throw new RuntimeException(errors + " errors occurred"); + } + + List getNames(Class[] classes) { + List names = new ArrayList(); + for (Class c: classes) + names.add(c.getName()); + return names; + } + + void test(List names) throws Exception { + System.err.println("test: " + names); + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); + File testClasses = new File(System.getProperty("test.classes")); + fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(testClasses)); + JavaCompiler.CompilationTask task = compiler.getTask( + null, null, null, Arrays.asList("-proc:only"), names, null); + task.setProcessors(Arrays.asList(new Test())); + boolean ok = task.call(); + if (!ok) + error("compilation failed"); + System.err.println(); + } + + List reverse(List list) { + List newList = new ArrayList(list); + Collections.reverse(newList); + return newList; + } + + int errors = 0; + + void error(String msg) { + System.out.println("Error: " + msg); + errors++; + } + + //---------- + + public boolean process(Set annotations, + RoundEnvironment roundEnv) { + if (!roundEnv.processingOver()) { + for (TypeElement typeElt : ElementFilter.typesIn(roundEnv.getRootElements())) { + messager.printMessage(Diagnostic.Kind.NOTE, "processing " + typeElt); + } + } + return true; + } +} diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/processing/options/testCommandLineClasses/p/NestedExamples.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/processing/options/testCommandLineClasses/p/NestedExamples.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,63 @@ +/* + * 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; + +public class NestedExamples { + static class MemberClass1 { } + + class MemberClass2 { } + + class Win$$AtVegas { } // Class with funny name. + + public Class[] getClasses() { + class LocalClass { } + + Object o = new Object() { // An anonymous class + @Override + public String toString() { + return "I have no name!"; + } + }; + + return new Class[] { + NestedExamples.class, + MemberClass1.class, + MemberClass2.class, + Win$$AtVegas.class, + LocalClass.class, + o.getClass() + }; + } + + public String[] getClassNames() { + return new String[] { + "p.NestedExamples", + "p.NestedExamples.MemberClass1", + "p.NestedExamples.MemberClass2", + "p.NestedExamples.Win$$AtVegas" + }; + } +} + + diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/processing/options/testPrintProcessorInfo/Test.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/processing/options/testPrintProcessorInfo/Test.java Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,74 @@ +/* + * 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 6987384 + * @summary -XprintProcessorRoundsInfo message printed with different timing than previous + * @library ../../../lib + * @build JavacTestingAbstractProcessor Test + * @compile/fail/ref=Test.out -XDrawDiagnostics -XprintProcessorInfo -Werror -proc:only -processor Test Test.java + */ + +import java.io.*; +import java.util.*; +import javax.annotation.processing.*; +import javax.lang.model.*; +import javax.lang.model.element.*; +import javax.lang.model.util.*; +import javax.tools.*; + +public class Test extends JavacTestingAbstractProcessor { + final int MAX_ROUNDS = 3; + int round = 0; + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + round++; + messager.printMessage(Diagnostic.Kind.NOTE, "round " + round); + if (round <= MAX_ROUNDS) + generateSource("Gen" + round); + if (roundEnv.processingOver()) + messager.printMessage(Diagnostic.Kind.WARNING, "last round"); + return true; + } + + void generateSource(String name) { + String text = "class " + name + " { }\n"; + + // avoid try-with-resources so test can be run on older builds + try { + Writer out = filer.createSourceFile(name).openWriter(); + try { + out.write(text); + } finally { + out.close(); + } + } catch (IOException e) { + throw new Error(e); + } + } +} + + + diff -r 0b40da2d6908 -r 6aa795396cc8 langtools/test/tools/javac/processing/options/testPrintProcessorInfo/Test.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/processing/options/testPrintProcessorInfo/Test.out Sat Mar 26 00:11:34 2011 -0700 @@ -0,0 +1,13 @@ +Processor Test matches [java.lang.Override] and returns true. +- compiler.note.proc.messager: round 1 +Processor Test matches [] and returns true. +- compiler.note.proc.messager: round 2 +Processor Test matches [] and returns true. +- compiler.note.proc.messager: round 3 +Processor Test matches [] and returns true. +- compiler.note.proc.messager: round 4 +- compiler.note.proc.messager: round 5 +- compiler.warn.proc.messager: last round +- compiler.err.warnings.and.werror +1 error +1 warning