From 1d1fd8962dff94a0f6bcadff2b337178e741c430 Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Mon, 24 Jan 2011 16:17:33 -0800 Subject: [PATCH 01/73] 6963934: JCCompilationUnit.getImports does not report all imports Reviewed-by: mcimadamore --- .../com/sun/tools/javac/tree/JCTree.java | 5 +- langtools/test/tools/javac/tree/T6963934.java | 58 +++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 langtools/test/tools/javac/tree/T6963934.java diff --git a/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java b/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java index b061c1b8ccb..a461adb1d1b 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java +++ b/langtools/src/share/classes/com/sun/tools/javac/tree/JCTree.java @@ -465,9 +465,10 @@ public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition { public List getImports() { ListBuffer imports = new ListBuffer(); for (JCTree tree : defs) { - if (tree.getTag() == IMPORT) + int tag = tree.getTag(); + if (tag == IMPORT) imports.append((JCImport)tree); - else + else if (tag != SKIP) break; } return imports.toList(); diff --git a/langtools/test/tools/javac/tree/T6963934.java b/langtools/test/tools/javac/tree/T6963934.java new file mode 100644 index 00000000000..03efb29942d --- /dev/null +++ b/langtools/test/tools/javac/tree/T6963934.java @@ -0,0 +1,58 @@ +/* + * 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 6963934 + * @summary JCCompilationUnit.getImports does not report all imports + */ + +import java.io.File; +import javax.tools.JavaCompiler; +import javax.tools.StandardJavaFileManager; +import javax.tools.ToolProvider;; // NOTE: extra semicolon for test + +import com.sun.source.tree.CompilationUnitTree; +import com.sun.source.tree.ImportTree; +import com.sun.source.util.JavacTask; +; // NOTE: extra semicolon for test + +public class T6963934 { + public static void main(String[] args) throws Exception { + File testSrc = new File(System.getProperty("test.src")); + File thisSrc = new File(testSrc, T6963934.class.getSimpleName() + ".java"); + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); + JavacTask task = (JavacTask) compiler.getTask(null, fileManager, null, null, null, + fileManager.getJavaFileObjects(thisSrc)); + CompilationUnitTree tree = task.parse().iterator().next(); + int count = 0; + for (ImportTree importTree : tree.getImports()) { + System.out.println(importTree); + count++; + } + int expected = 7; + if (count != expected) + throw new Exception("unexpected number of imports found: " + count + ", expected: " + expected); + } +} From 1ab227adc49f17fa286fd0352968aadd8796e699 Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Mon, 24 Jan 2011 16:34:25 -0800 Subject: [PATCH 02/73] 6581775: Fix the white space problem in javac shell tests Reviewed-by: mcimadamore --- langtools/test/tools/javac/ClassPathTest/ClassPathTest.sh | 2 +- langtools/test/tools/javac/ExtDirs/ExtDirs.sh | 6 +++--- langtools/test/tools/javac/Paths/Help.sh | 4 ++-- langtools/test/tools/javac/javazip/Test.sh | 4 ++-- langtools/test/tools/javac/versions/check.sh | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/langtools/test/tools/javac/ClassPathTest/ClassPathTest.sh b/langtools/test/tools/javac/ClassPathTest/ClassPathTest.sh index f6484593289..9fcfa53a74d 100644 --- a/langtools/test/tools/javac/ClassPathTest/ClassPathTest.sh +++ b/langtools/test/tools/javac/ClassPathTest/ClassPathTest.sh @@ -100,7 +100,7 @@ testJavac() { expectedResult="$1"; shift cleanup echo $javac ${TESTTOOLVMOPTS} "$@" - $javac ${TESTTOOLVMOPTS} "$@" + "$javac" ${TESTTOOLVMOPTS} "$@" report $expectedResult $? } diff --git a/langtools/test/tools/javac/ExtDirs/ExtDirs.sh b/langtools/test/tools/javac/ExtDirs/ExtDirs.sh index 35c085bc31e..b42d4a5a647 100644 --- a/langtools/test/tools/javac/ExtDirs/ExtDirs.sh +++ b/langtools/test/tools/javac/ExtDirs/ExtDirs.sh @@ -85,15 +85,15 @@ for i in 1 2 3; do done echo "Test 1" -$javac ${TESTTOOLVMOPTS} -d . -extdirs ext1 "${TESTSRC}${FS}ExtDirTest_1.java" +"$javac" ${TESTTOOLVMOPTS} -d . -extdirs ext1 "${TESTSRC}${FS}ExtDirTest_1.java" if [ $? -ne 0 ] ; then fail ; fi echo "Test 2" -$javac ${TESTTOOLVMOPTS} -d . -extdirs ext1${PS}ext2 "${TESTSRC}${FS}ExtDirTest_2.java" +"$javac" ${TESTTOOLVMOPTS} -d . -extdirs ext1${PS}ext2 "${TESTSRC}${FS}ExtDirTest_2.java" if [ $? -ne 0 ] ; then fail ; fi echo "Test 3" -$javac ${TESTTOOLVMOPTS} -d . -extdirs ext3 "${TESTSRC}${FS}ExtDirTest_3.java" +"$javac" ${TESTTOOLVMOPTS} -d . -extdirs ext3 "${TESTSRC}${FS}ExtDirTest_3.java" if [ $? -ne 0 ] ; then fail ; fi echo PASS: all tests gave expected results diff --git a/langtools/test/tools/javac/Paths/Help.sh b/langtools/test/tools/javac/Paths/Help.sh index 711c437f2e9..7c3c376f0a0 100644 --- a/langtools/test/tools/javac/Paths/Help.sh +++ b/langtools/test/tools/javac/Paths/Help.sh @@ -40,8 +40,8 @@ set -u DiagnosticsInEnglishPlease -HELP="`$javac ${TESTTOOLVMOPTS} -help 2>&1`" -XHELP="`$javac ${TESTTOOLVMOPTS} -X 2>&1`" +HELP="`\"$javac\" ${TESTTOOLVMOPTS} -help 2>&1`" +XHELP="`\"$javac\" ${TESTTOOLVMOPTS} -X 2>&1`" #---------------------------------------------------------------- # Standard options diff --git a/langtools/test/tools/javac/javazip/Test.sh b/langtools/test/tools/javac/javazip/Test.sh index 40fa95ed6a7..95f3c7531d8 100644 --- a/langtools/test/tools/javac/javazip/Test.sh +++ b/langtools/test/tools/javac/javazip/Test.sh @@ -66,8 +66,8 @@ check() { # clean old classes rm -f ${TC}${FS}*.class - echo "$*" - if $* 2>&1 ; then + echo "$@" + if "$@" 2>&1 ; then actual=ok else actual=err diff --git a/langtools/test/tools/javac/versions/check.sh b/langtools/test/tools/javac/versions/check.sh index a3a31ef4181..d8693d47786 100644 --- a/langtools/test/tools/javac/versions/check.sh +++ b/langtools/test/tools/javac/versions/check.sh @@ -32,7 +32,7 @@ TC=${TESTCLASSES-.} J="$TESTJAVA/bin/java" JC="$TESTJAVA/bin/javac" -CFV="$J ${TESTVMOPTS} -cp $TC CheckClassFileVersion" +CFV="${TESTVMOPTS} -cp $TC CheckClassFileVersion" rm -f $TC/X.java $TC/X.java echo 'public class X { }' > $TC/X.java @@ -44,7 +44,7 @@ echo 'public enum Y { }' > $TC/Y.java check() { V=$1; shift echo "+ javac $* [$V]" - $JC ${TESTTOOLVMOPTS} -d $TC $* $TC/X.java && $CFV $TC/X.class $V || exit 2 + "$JC" ${TESTTOOLVMOPTS} -d $TC $* $TC/X.java && "$J" $CFV $TC/X.class $V || exit 2 } check 48.0 -source 1.4 @@ -73,7 +73,7 @@ check 51.0 -target 7 fail() { echo "+ javac $*" - if $JC ${TESTTOOLVMOPTS} -d $TC $*; then + if "$JC" ${TESTTOOLVMOPTS} -d $TC $*; then echo "-- did not fail as expected" exit 3 else @@ -83,7 +83,7 @@ fail() { pass() { echo "+ javac $*" - if $JC ${TESTTOOLVMOPTS} -d $TC $*; then + if "$JC" ${TESTTOOLVMOPTS} -d $TC $*; then echo "-- passed" else echo "-- failed" From bcf09ec04f893a7271e23f3640640d762251c3aa Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Mon, 24 Jan 2011 16:38:56 -0800 Subject: [PATCH 03/73] 6988106: javac report 'java.lang.IllegalMonitorStateException' Reviewed-by: ksrini --- .../com/sun/tools/javac/file/CacheFSInfo.java | 6 +- .../tools/javac/file/JavacFileManager.java | 15 +- .../sun/tools/javac/file/ZipFileIndex.java | 448 +++++------------- .../tools/javac/file/ZipFileIndexCache.java | 149 ++++++ langtools/test/tools/javac/T6725036.java | 7 +- 5 files changed, 286 insertions(+), 339 deletions(-) create mode 100644 langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndexCache.java diff --git a/langtools/src/share/classes/com/sun/tools/javac/file/CacheFSInfo.java b/langtools/src/share/classes/com/sun/tools/javac/file/CacheFSInfo.java index 473664d4668..03fe8a28234 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/file/CacheFSInfo.java +++ b/langtools/src/share/classes/com/sun/tools/javac/file/CacheFSInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2008, 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 @@ -28,11 +28,11 @@ package com.sun.tools.javac.file; import java.io.File; import java.io.IOException; import java.util.List; - -import com.sun.tools.javac.util.Context; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import com.sun.tools.javac.util.Context; + /** * Caching implementation of FSInfo. * diff --git a/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java b/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java index 335ded62e5d..e4f621a585c 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java +++ b/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java @@ -76,8 +76,6 @@ import static com.sun.tools.javac.main.OptionName.*; */ public class JavacFileManager extends BaseFileManager implements StandardJavaFileManager { - boolean useZipFileIndex; - public static char[] toArray(CharBuffer buffer) { if (buffer.hasArray()) return ((CharBuffer)buffer.compact().flip()).array(); @@ -91,6 +89,9 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil private FSInfo fsInfo; + private boolean useZipFileIndex; + private ZipFileIndexCache zipFileIndexCache; + private final File uninited = new File("U N I N I T E D"); private final Set sourceOrClass = @@ -163,7 +164,11 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil fsInfo = FSInfo.instance(context); - useZipFileIndex = System.getProperty("useJavaUtilZip") == null;// TODO: options.get("useJavaUtilZip") == null; + // retain check for system property for compatibility + useZipFileIndex = options.isUnset("useJavaUtilZip") + && System.getProperty("useJavaUtilZip") == null; + if (useZipFileIndex) + zipFileIndexCache = ZipFileIndexCache.getSharedInstance(); mmappedIO = options.isSet("mmappedIO"); ignoreSymbolFile = options.isSet("ignore.symbol.file"); @@ -526,7 +531,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil archive = new ZipArchive(this, zdir); } else { archive = new ZipFileIndexArchive(this, - ZipFileIndex.getZipFileIndex(zipFileName, + zipFileIndexCache.getZipFileIndex(zipFileName, null, usePreindexedCache, preindexCacheLocation, @@ -538,7 +543,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil } else { archive = new ZipFileIndexArchive(this, - ZipFileIndex.getZipFileIndex(zipFileName, + zipFileIndexCache.getZipFileIndex(zipFileName, symbolFilePrefix, usePreindexedCache, preindexCacheLocation, diff --git a/langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java b/langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java index 1234bfc8352..fc9d1b3789f 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java +++ b/langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 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 @@ -38,11 +38,9 @@ import java.util.Calendar; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.locks.ReentrantLock; import java.util.zip.DataFormatException; import java.util.zip.Inflater; import java.util.zip.ZipException; @@ -50,24 +48,28 @@ import java.util.zip.ZipException; import com.sun.tools.javac.file.RelativePath.RelativeDirectory; import com.sun.tools.javac.file.RelativePath.RelativeFile; -/** This class implements building of index of a zip archive and access to it's context. - * It also uses prebuild index if available. It supports invocations where it will - * serialize an optimized zip index file to disk. +/** + * This class implements the building of index of a zip archive and access to + * its context. It also uses a prebuilt index if available. + * It supports invocations where it will serialize an optimized zip index file + * to disk. * - * In oreder to use secondary index file make sure the option "usezipindex" is in the Options object, - * when JavacFileManager is invoked. (You can pass "-XDusezipindex" on the command line. + * In order to use a secondary index file, set "usezipindex" in the Options + * object when JavacFileManager is invoked. (You can pass "-XDusezipindex" on + * the command line.) * - * Location where to look for/generate optimized zip index files can be provided using - * "-XDcachezipindexdir=". If this flag is not provided, the dfault location is - * the value of the "java.io.tmpdir" system property. + * Location where to look for/generate optimized zip index files can be + * provided using "-XDcachezipindexdir=". If this flag is not + * provided, the default location is the value of the "java.io.tmpdir" system + * property. * - * If key "-XDwritezipindexfiles" is specified, there will be new optimized index file - * created for each archive, used by the compiler for compilation, at location, - * specified by "cachezipindexdir" option. + * If "-XDwritezipindexfiles" is specified, there will be new optimized index + * file created for each archive, used by the compiler for compilation, at the + * location specified by the "cachezipindexdir" option. * - * If nonBatchMode option is specified (-XDnonBatchMode) the compiler will use timestamp - * checking to reindex the zip files if it is needed. In batch mode the timestamps are not checked - * and the compiler uses the cached indexes. + * If system property nonBatchMode option is specified the compiler will use + * timestamp checking to reindex the zip files if it is needed. In batch mode + * the timestamps are not checked and the compiler uses the cached indexes. * *

This is NOT part of any supported API. * If you write code that depends on this, you do so at your own risk. @@ -80,18 +82,18 @@ public class ZipFileIndex { public final static long NOT_MODIFIED = Long.MIN_VALUE; - private static Map zipFileIndexCache = new HashMap(); - private static ReentrantLock lock = new ReentrantLock(); private static boolean NON_BATCH_MODE = System.getProperty("nonBatchMode") != null;// TODO: Use -XD compiler switch for this. - private Map directories = Collections.emptyMap(); - private Set allDirs = Collections.emptySet(); + private Map directories = + Collections.emptyMap(); + private Set allDirs = + Collections.emptySet(); // ZipFileIndex data entries - private File zipFile; + final File zipFile; private Reference absFileRef; - private long zipFileLastModified = NOT_MODIFIED; + long zipFileLastModified = NOT_MODIFIED; private RandomAccessFile zipRandomFile; private Entry[] entries; @@ -99,156 +101,24 @@ public class ZipFileIndex { private File zipIndexFile = null; private boolean triedToReadIndex = false; final RelativeDirectory symbolFilePrefix; - private int symbolFilePrefixLength = 0; + private final int symbolFilePrefixLength; private boolean hasPopulatedData = false; - private long lastReferenceTimeStamp = NOT_MODIFIED; + long lastReferenceTimeStamp = NOT_MODIFIED; - private boolean usePreindexedCache = false; - private String preindexedCacheLocation = null; + private final boolean usePreindexedCache; + private final String preindexedCacheLocation; private boolean writeIndex = false; - private Map > relativeDirectoryCache = + private Map> relativeDirectoryCache = new HashMap>(); - /** - * Returns a list of all ZipFileIndex entries - * - * @return A list of ZipFileIndex entries, or an empty list - */ - public static List getZipFileIndexes() { - return getZipFileIndexes(false); + + public synchronized boolean isOpen() { + return (zipRandomFile != null); } - /** - * Returns a list of all ZipFileIndex entries - * - * @param openedOnly If true it returns a list of only opened ZipFileIndex entries, otherwise - * all ZipFileEntry(s) are included into the list. - * @return A list of ZipFileIndex entries, or an empty list - */ - public static List getZipFileIndexes(boolean openedOnly) { - List zipFileIndexes = new ArrayList(); - lock.lock(); - try { - zipFileIndexes.addAll(zipFileIndexCache.values()); - - if (openedOnly) { - for(ZipFileIndex elem : zipFileIndexes) { - if (!elem.isOpen()) { - zipFileIndexes.remove(elem); - } - } - } - } - finally { - lock.unlock(); - } - return zipFileIndexes; - } - - public boolean isOpen() { - lock.lock(); - try { - return zipRandomFile != null; - } - finally { - lock.unlock(); - } - } - - public static ZipFileIndex getZipFileIndex(File zipFile, - RelativeDirectory symbolFilePrefix, - boolean useCache, String cacheLocation, - boolean writeIndex) throws IOException { - ZipFileIndex zi = null; - lock.lock(); - try { - zi = getExistingZipIndex(zipFile); - - if (zi == null || (zi != null && zipFile.lastModified() != zi.zipFileLastModified)) { - zi = new ZipFileIndex(zipFile, symbolFilePrefix, writeIndex, - useCache, cacheLocation); - zipFileIndexCache.put(zipFile, zi); - } - } - finally { - lock.unlock(); - } - return zi; - } - - public static ZipFileIndex getExistingZipIndex(File zipFile) { - lock.lock(); - try { - return zipFileIndexCache.get(zipFile); - } - finally { - lock.unlock(); - } - } - - public static void clearCache() { - lock.lock(); - try { - zipFileIndexCache.clear(); - } - finally { - lock.unlock(); - } - } - - public static void clearCache(long timeNotUsed) { - lock.lock(); - try { - Iterator cachedFileIterator = zipFileIndexCache.keySet().iterator(); - while (cachedFileIterator.hasNext()) { - File cachedFile = cachedFileIterator.next(); - ZipFileIndex cachedZipIndex = zipFileIndexCache.get(cachedFile); - if (cachedZipIndex != null) { - long timeToTest = cachedZipIndex.lastReferenceTimeStamp + timeNotUsed; - if (timeToTest < cachedZipIndex.lastReferenceTimeStamp || // Overflow... - System.currentTimeMillis() > timeToTest) { - zipFileIndexCache.remove(cachedFile); - } - } - } - } - finally { - lock.unlock(); - } - } - - public static void removeFromCache(File file) { - lock.lock(); - try { - zipFileIndexCache.remove(file); - } - finally { - lock.unlock(); - } - } - - /** Sets already opened list of ZipFileIndexes from an outside client - * of the compiler. This functionality should be used in a non-batch clients of the compiler. - */ - public static void setOpenedIndexes(Listindexes) throws IllegalStateException { - lock.lock(); - try { - if (zipFileIndexCache.isEmpty()) { - throw new IllegalStateException("Setting opened indexes should be called only when the ZipFileCache is empty. Call JavacFileManager.flush() before calling this method."); - } - - for (ZipFileIndex zfi : indexes) { - zipFileIndexCache.put(zfi.zipFile, zfi); - } - } - finally { - lock.unlock(); - } - } - - private ZipFileIndex(File zipFile, RelativeDirectory symbolFilePrefix, boolean writeIndex, + ZipFileIndex(File zipFile, RelativeDirectory symbolFilePrefix, boolean writeIndex, boolean useCache, String cacheLocation) throws IOException { this.zipFile = zipFile; this.symbolFilePrefix = symbolFilePrefix; @@ -266,19 +136,22 @@ public class ZipFileIndex { checkIndex(); } + @Override public String toString() { return "ZipFileIndex[" + zipFile + "]"; } // Just in case... - protected void finalize() { + @Override + protected void finalize() throws Throwable { closeFile(); + super.finalize(); } private boolean isUpToDate() { - if (zipFile != null && - ((!NON_BATCH_MODE) || zipFileLastModified == zipFile.lastModified()) && - hasPopulatedData) { + if (zipFile != null + && ((!NON_BATCH_MODE) || zipFileLastModified == zipFile.lastModified()) + && hasPopulatedData) { return true; } @@ -339,15 +212,9 @@ public class ZipFileIndex { allDirs = Collections.emptySet(); } - public void close() { - lock.lock(); - try { - writeIndex(); - closeFile(); - } - finally { - lock.unlock(); - } + public synchronized void close() { + writeIndex(); + closeFile(); } private void closeFile() { @@ -361,29 +228,24 @@ public class ZipFileIndex { } /** - * Returns the ZipFileIndexEntry for an absolute path, if there is one. + * Returns the ZipFileIndexEntry for a path, if there is one. */ - Entry getZipIndexEntry(RelativePath path) { - lock.lock(); + synchronized Entry getZipIndexEntry(RelativePath path) { try { checkIndex(); DirectoryEntry de = directories.get(path.dirname()); String lookFor = path.basename(); - return de == null ? null : de.getEntry(lookFor); + return (de == null) ? null : de.getEntry(lookFor); } catch (IOException e) { return null; } - finally { - lock.unlock(); - } } /** - * Returns a javac List of filenames within an absolute path in the ZipFileIndex. + * Returns a javac List of filenames within a directory in the ZipFileIndex. */ - public com.sun.tools.javac.util.List getFiles(RelativeDirectory path) { - lock.lock(); + public synchronized com.sun.tools.javac.util.List getFiles(RelativeDirectory path) { try { checkIndex(); @@ -398,13 +260,9 @@ public class ZipFileIndex { catch (IOException e) { return com.sun.tools.javac.util.List.nil(); } - finally { - lock.unlock(); - } } - public List getDirectories(RelativeDirectory path) { - lock.lock(); + public synchronized List getDirectories(RelativeDirectory path) { try { checkIndex(); @@ -420,13 +278,9 @@ public class ZipFileIndex { catch (IOException e) { return com.sun.tools.javac.util.List.nil(); } - finally { - lock.unlock(); - } } - public Set getAllDirectories() { - lock.lock(); + public synchronized Set getAllDirectories() { try { checkIndex(); if (allDirs == Collections.EMPTY_SET) { @@ -438,9 +292,6 @@ public class ZipFileIndex { catch (IOException e) { return Collections.emptySet(); } - finally { - lock.unlock(); - } } /** @@ -450,8 +301,7 @@ public class ZipFileIndex { * @param path A path within the zip. * @return True if the path is a file or dir, false otherwise. */ - public boolean contains(RelativePath path) { - lock.lock(); + public synchronized boolean contains(RelativePath path) { try { checkIndex(); return getZipIndexEntry(path) != null; @@ -459,114 +309,69 @@ public class ZipFileIndex { catch (IOException e) { return false; } - finally { - lock.unlock(); + } + + public synchronized boolean isDirectory(RelativePath path) throws IOException { + // The top level in a zip file is always a directory. + if (path.getPath().length() == 0) { + lastReferenceTimeStamp = System.currentTimeMillis(); + return true; + } + + checkIndex(); + return directories.get(path) != null; + } + + public synchronized long getLastModified(RelativeFile path) throws IOException { + Entry entry = getZipIndexEntry(path); + if (entry == null) + throw new FileNotFoundException(); + return entry.getLastModified(); + } + + public synchronized int length(RelativeFile path) throws IOException { + Entry entry = getZipIndexEntry(path); + if (entry == null) + throw new FileNotFoundException(); + + if (entry.isDir) { + return 0; + } + + byte[] header = getHeader(entry); + // entry is not compressed? + if (get2ByteLittleEndian(header, 8) == 0) { + return entry.compressedSize; + } else { + return entry.size; } } - public boolean isDirectory(RelativePath path) throws IOException { - lock.lock(); - try { - // The top level in a zip file is always a directory. - if (path.getPath().length() == 0) { - lastReferenceTimeStamp = System.currentTimeMillis(); - return true; - } - - checkIndex(); - return directories.get(path) != null; - } - finally { - lock.unlock(); - } + public synchronized byte[] read(RelativeFile path) throws IOException { + Entry entry = getZipIndexEntry(path); + if (entry == null) + throw new FileNotFoundException("Path not found in ZIP: " + path.path); + return read(entry); } - public long getLastModified(RelativeFile path) throws IOException { - lock.lock(); - try { - Entry entry = getZipIndexEntry(path); - if (entry == null) - throw new FileNotFoundException(); - return entry.getLastModified(); - } - finally { - lock.unlock(); - } + synchronized byte[] read(Entry entry) throws IOException { + openFile(); + byte[] result = readBytes(entry); + closeFile(); + return result; } - public int length(RelativeFile path) throws IOException { - lock.lock(); - try { - Entry entry = getZipIndexEntry(path); - if (entry == null) - throw new FileNotFoundException(); - - if (entry.isDir) { - return 0; - } - - byte[] header = getHeader(entry); - // entry is not compressed? - if (get2ByteLittleEndian(header, 8) == 0) { - return entry.compressedSize; - } else { - return entry.size; - } - } - finally { - lock.unlock(); - } + public synchronized int read(RelativeFile path, byte[] buffer) throws IOException { + Entry entry = getZipIndexEntry(path); + if (entry == null) + throw new FileNotFoundException(); + return read(entry, buffer); } - public byte[] read(RelativeFile path) throws IOException { - lock.lock(); - try { - Entry entry = getZipIndexEntry(path); - if (entry == null) - throw new FileNotFoundException("Path not found in ZIP: " + path.path); - return read(entry); - } - finally { - lock.unlock(); - } - } - - byte[] read(Entry entry) throws IOException { - lock.lock(); - try { - openFile(); - byte[] result = readBytes(entry); - closeFile(); - return result; - } - finally { - lock.unlock(); - } - } - - public int read(RelativeFile path, byte[] buffer) throws IOException { - lock.lock(); - try { - Entry entry = getZipIndexEntry(path); - if (entry == null) - throw new FileNotFoundException(); - return read(entry, buffer); - } - finally { - lock.unlock(); - } - } - - int read(Entry entry, byte[] buffer) + synchronized int read(Entry entry, byte[] buffer) throws IOException { - lock.lock(); - try { - int result = readBytes(entry, buffer); - return result; - } - finally { - lock.unlock(); - } + int result = readBytes(entry, buffer); + return result; } private byte[] readBytes(Entry entry) throws IOException { @@ -638,21 +443,20 @@ public class ZipFileIndex { /* * Inflate using the java.util.zip.Inflater class */ - private static Inflater inflater; + private SoftReference inflaterRef; private int inflate(byte[] src, byte[] dest) { + Inflater inflater = (inflaterRef == null ? null : inflaterRef.get()); // construct the inflater object or reuse an existing one if (inflater == null) - inflater = new Inflater(true); + inflaterRef = new SoftReference(inflater = new Inflater(true)); - synchronized (inflater) { - inflater.reset(); - inflater.setInput(src); - try { - return inflater.inflate(dest); - } catch (DataFormatException ex) { - return -1; - } + inflater.reset(); + inflater.setInput(src); + try { + return inflater.inflate(dest); + } catch (DataFormatException ex) { + return -1; } } @@ -855,14 +659,10 @@ public class ZipFileIndex { * @return long */ public long getZipFileLastModified() throws IOException { - lock.lock(); - try { + synchronized (this) { checkIndex(); return zipFileLastModified; } - finally { - lock.unlock(); - } } /** ------------------------------------------------------------------------ @@ -1028,8 +828,7 @@ public class ZipFileIndex { } boolean ret = false; - lock.lock(); - try { + synchronized (this) { triedToReadIndex = true; RandomAccessFile raf = null; try { @@ -1071,9 +870,6 @@ public class ZipFileIndex { readFromIndex = true; } } - finally { - lock.unlock(); - } return ret; } @@ -1144,8 +940,8 @@ public class ZipFileIndex { raf.seek(currFP); // Now write each of the files in the DirectoryEntry - List entries = de.getEntriesAsCollection(); - for (Entry zfie : entries) { + List list = de.getEntriesAsCollection(); + for (Entry zfie : list) { // Write the name bytes byte [] zfieNameBytes = zfie.name.getBytes("UTF-8"); int zfieNameBytesLen = zfieNameBytes.length; @@ -1191,13 +987,9 @@ public class ZipFileIndex { } public boolean writeZipIndex() { - lock.lock(); - try { + synchronized (this) { return writeIndex(); } - finally { - lock.unlock(); - } } private File getIndexFile() { @@ -1328,7 +1120,7 @@ public class ZipFileIndex { return hash; } - + @Override public String toString() { return isDir ? ("Dir:" + dir + " : " + name) : (dir + ":" + name); diff --git a/langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndexCache.java b/langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndexCache.java new file mode 100644 index 00000000000..3c878d71efa --- /dev/null +++ b/langtools/src/share/classes/com/sun/tools/javac/file/ZipFileIndexCache.java @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2007, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.tools.javac.file; + +import com.sun.tools.javac.file.RelativePath.RelativeDirectory; +import com.sun.tools.javac.util.Context; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + + +/** A cache for ZipFileIndex objects. */ +public class ZipFileIndexCache { + + private final Map map = + new HashMap(); + + /** Get a shared instance of the cache. */ + private static ZipFileIndexCache sharedInstance; + public synchronized static ZipFileIndexCache getSharedInstance() { + if (sharedInstance == null) + sharedInstance = new ZipFileIndexCache(); + return sharedInstance; + } + + /** Get a context-specific instance of a cache. */ + public static ZipFileIndexCache instance(Context context) { + ZipFileIndexCache instance = context.get(ZipFileIndexCache.class); + if (instance == null) + context.put(ZipFileIndexCache.class, instance = new ZipFileIndexCache()); + return instance; + } + + /** + * Returns a list of all ZipFileIndex entries + * + * @return A list of ZipFileIndex entries, or an empty list + */ + public List getZipFileIndexes() { + return getZipFileIndexes(false); + } + + /** + * Returns a list of all ZipFileIndex entries + * + * @param openedOnly If true it returns a list of only opened ZipFileIndex entries, otherwise + * all ZipFileEntry(s) are included into the list. + * @return A list of ZipFileIndex entries, or an empty list + */ + public synchronized List getZipFileIndexes(boolean openedOnly) { + List zipFileIndexes = new ArrayList(); + + zipFileIndexes.addAll(map.values()); + + if (openedOnly) { + for(ZipFileIndex elem : zipFileIndexes) { + if (!elem.isOpen()) { + zipFileIndexes.remove(elem); + } + } + } + + return zipFileIndexes; + } + + public synchronized ZipFileIndex getZipFileIndex(File zipFile, + RelativeDirectory symbolFilePrefix, + boolean useCache, String cacheLocation, + boolean writeIndex) throws IOException { + ZipFileIndex zi = getExistingZipIndex(zipFile); + + if (zi == null || (zi != null && zipFile.lastModified() != zi.zipFileLastModified)) { + zi = new ZipFileIndex(zipFile, symbolFilePrefix, writeIndex, + useCache, cacheLocation); + map.put(zipFile, zi); + } + return zi; + } + + public synchronized ZipFileIndex getExistingZipIndex(File zipFile) { + return map.get(zipFile); + } + + public synchronized void clearCache() { + map.clear(); + } + + public synchronized void clearCache(long timeNotUsed) { + Iterator cachedFileIterator = map.keySet().iterator(); + while (cachedFileIterator.hasNext()) { + File cachedFile = cachedFileIterator.next(); + ZipFileIndex cachedZipIndex = map.get(cachedFile); + if (cachedZipIndex != null) { + long timeToTest = cachedZipIndex.lastReferenceTimeStamp + timeNotUsed; + if (timeToTest < cachedZipIndex.lastReferenceTimeStamp || // Overflow... + System.currentTimeMillis() > timeToTest) { + map.remove(cachedFile); + } + } + } + } + + public synchronized void removeFromCache(File file) { + map.remove(file); + } + + /** Sets already opened list of ZipFileIndexes from an outside client + * of the compiler. This functionality should be used in a non-batch clients of the compiler. + */ + public synchronized void setOpenedIndexes(Listindexes) throws IllegalStateException { + if (map.isEmpty()) { + String msg = + "Setting opened indexes should be called only when the ZipFileCache is empty. " + + "Call JavacFileManager.flush() before calling this method."; + throw new IllegalStateException(msg); + } + + for (ZipFileIndex zfi : indexes) { + map.put(zfi.zipFile, zfi); + } + } +} diff --git a/langtools/test/tools/javac/T6725036.java b/langtools/test/tools/javac/T6725036.java index f320b53ffc5..b27ad886d13 100644 --- a/langtools/test/tools/javac/T6725036.java +++ b/langtools/test/tools/javac/T6725036.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 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 @@ -38,6 +38,7 @@ import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.file.RelativePath.RelativeFile; import com.sun.tools.javac.file.ZipFileIndex; import com.sun.tools.javac.file.ZipFileIndexArchive; +import com.sun.tools.javac.file.ZipFileIndexCache; import com.sun.tools.javac.util.Context; public class T6725036 { @@ -57,8 +58,8 @@ public class T6725036 { JarEntry je = j.getJarEntry(TEST_ENTRY_NAME.getPath()); long jarEntryTime = je.getTime(); - ZipFileIndex zfi = - ZipFileIndex.getZipFileIndex(rt_jar, null, false, null, false); + ZipFileIndexCache zfic = ZipFileIndexCache.getSharedInstance(); + ZipFileIndex zfi = zfic.getZipFileIndex(rt_jar, null, false, null, false); long zfiTime = zfi.getLastModified(TEST_ENTRY_NAME); check(je, jarEntryTime, zfi + ":" + TEST_ENTRY_NAME.getPath(), zfiTime); From fa97643b69e028e405596f09eec53e03b0f51902 Mon Sep 17 00:00:00 2001 From: Andrei Dmitriev Date: Tue, 25 Jan 2011 15:33:14 +0300 Subject: [PATCH 04/73] 6693961: cross-window focus transfer ability in the Focus Spec should be revised Reviewed-by: ant, art --- jdk/src/share/classes/java/awt/doc-files/FocusSpec.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jdk/src/share/classes/java/awt/doc-files/FocusSpec.html b/jdk/src/share/classes/java/awt/doc-files/FocusSpec.html index d233019cdd4..da27abe8ad0 100644 --- a/jdk/src/share/classes/java/awt/doc-files/FocusSpec.html +++ b/jdk/src/share/classes/java/awt/doc-files/FocusSpec.html @@ -894,8 +894,7 @@ not the focused Window and the platform does not support requesting focus across Windows. If the request is denied for this reason, the request is remembered and will be granted when the Window is later focused by the user. Otherwise, the focus change request changes the -focused Window as well. Currently, Microsoft Windows supports cross-Window -focus transfers while Solaris does not. +focused Window as well.

There is no way to determine synchronously whether a focus change request has been granted. Instead, client code must install a From 5c7903af7d978badb77ba2a5a5f287be2ecbb5bd Mon Sep 17 00:00:00 2001 From: Andrei Dmitriev Date: Tue, 25 Jan 2011 19:07:27 +0300 Subject: [PATCH 05/73] 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append Reviewed-by: art, anthony --- .../classes/sun/awt/X11/XComponentPeer.java | 16 +- .../sun/awt/X11/XGlobalCursorManager.java | 4 +- .../classes/sun/awt/X11/XTextAreaPeer.java | 39 +- .../MouseOverScrollbarWhenTyping/Test.java | 385 +++++++++++++++++ .../MouseOverScrollbarWhenTyping/Test1.java | 386 ++++++++++++++++++ 5 files changed, 822 insertions(+), 8 deletions(-) create mode 100644 jdk/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test.java create mode 100644 jdk/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test1.java diff --git a/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java b/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java index a369a7f6831..6e425513c1c 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java @@ -725,7 +725,21 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget XGlobalCursorManager.getCursorManager().updateCursorImmediately(); } - public void pSetCursor(Cursor cursor) { + public final void pSetCursor(Cursor cursor) { + this.pSetCursor(cursor, true); + } + + /* + * The method changes the cursor. + * @param cursor - a new cursor to change to. + * @param ignoreSubComponents - if {@code true} is passed then + * the new cursor will be installed on window. + * if {@code false} is passed then + * subsequent components will try to handle + * this request and install their cursor. + */ + //ignoreSubComponents not used here + public void pSetCursor(Cursor cursor, boolean ignoreSubComponents) { XToolkit.awtLock(); try { long xcursor = XGlobalCursorManager.getCursor(cursor); diff --git a/jdk/src/solaris/classes/sun/awt/X11/XGlobalCursorManager.java b/jdk/src/solaris/classes/sun/awt/X11/XGlobalCursorManager.java index 579586ae047..c28d9d03e11 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XGlobalCursorManager.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XGlobalCursorManager.java @@ -104,7 +104,9 @@ public final class XGlobalCursorManager extends GlobalCursorManager { nativeContainer = new WeakReference(nc); } - ((XComponentPeer)nc_peer).pSetCursor(cur); + //6431076. A subcomponents (a XTextArea in particular) + //may want to override the cursor over some of their parts. + ((XComponentPeer)nc_peer).pSetCursor(cur, false); // in case of grab we do for Swing we need to update keep cursor updated // (we don't need this in case of AWT menus). Window Manager consider // the grabber as a current window and use its cursor. So we need to diff --git a/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java b/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java index 4cbca44224d..d9cc3033a3b 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java @@ -175,6 +175,34 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { super.dispose(); } + + /* + * The method overrides one from XComponentPeer + * If ignoreSubComponents=={@code true} it calls super. + * If ignoreSubComponents=={@code false} it uses the XTextArea machinery + * to change cursor appropriately. In particular it changes the cursor to + * default if over scrollbars. + */ + @Override + public void pSetCursor(Cursor cursor, boolean ignoreSubComponents) { + Point onScreen = getLocationOnScreen(); + if (ignoreSubComponents || + javaMouseEventHandler == null || + onScreen == null) + { + super.pSetCursor(cursor, true); + return; + } + + Point cursorPos = new Point(); + ((XGlobalCursorManager)XGlobalCursorManager.getCursorManager()).getCursorPos(cursorPos); + + Point localPoint = new Point(cursorPos.x - onScreen.x, cursorPos.y - onScreen.y ); + + javaMouseEventHandler.setPointerToUnderPoint(localPoint); + javaMouseEventHandler.setCursor(); + } + void setScrollBarVisibility() { int visibility = ((TextArea)target).getScrollbarVisibility(); jtext.setLineWrap(false); @@ -1264,13 +1292,13 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { void handle( MouseEvent event ) { if ( ! grabbed ) { // dispatch() needs up-to-date pointer in ungrabbed case. - setPointerToUnderEventPoint( event ); + setPointerToUnderPoint( event.getPoint() ); } dispatch( event ); boolean wasGrabbed = grabbed; grabbed_update( event ); if ( wasGrabbed && ! grabbed ) { - setPointerToUnderEventPoint( event ); + setPointerToUnderPoint( event.getPoint() ); } setCursor(); } @@ -1338,7 +1366,7 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { // 'target.getCursor()' is also applied from elsewhere // (at least now), but only when mouse "entered", and // before 'XTextAreaPeer.handleJavaMouseEvent' is invoked. - outer.pSetCursor( outer.target.getCursor() ); + outer.pSetCursor( outer.target.getCursor(), true ); } else { // We can write here a more intelligent cursor selection @@ -1346,7 +1374,7 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { // However, I see no point in doing so now. But if you feel // like implementing it, you'll probably need to introduce // 'Pointer.Type.PANEL'. - outer.pSetCursor( outer.textPane.getCursor() ); + outer.pSetCursor( outer.textPane.getCursor(), true ); } } @@ -1391,8 +1419,7 @@ class XTextAreaPeer extends XComponentPeer implements TextAreaPeer { return l; } - private void setPointerToUnderEventPoint( MouseEvent event ) { - Point point = event.getPoint(); + private void setPointerToUnderPoint( Point point ) { if ( outer.textPane.getViewport().getBounds().contains( point ) ) { current.setText(); } diff --git a/jdk/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test.java b/jdk/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test.java new file mode 100644 index 00000000000..098fdac7e8c --- /dev/null +++ b/jdk/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test.java @@ -0,0 +1,385 @@ +/* + @test + @bug 6431076 + @summary Mouse cursor must remain DEFAULT over scrollbar when text is typed + @author Andrei Dmitriev: area=TextArea + @run main/manual Test +*/ + +import java.awt.*; +import java.awt.event.*; + +public class Test { + private static void init() { + Frame f = new Frame("Test for cursor"); + final int dim = 100; + String line = ""; + for( int i=0; i 0 ) + { + //if longer than max then chop off first max chars to print + if( remainingStr.length() >= maxStringLength ) + { + //Try to chop on a word boundary + int posOfSpace = remainingStr. + lastIndexOf( ' ', maxStringLength - 1 ); + + if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; + + printStr = remainingStr.substring( 0, posOfSpace + 1 ); + remainingStr = remainingStr.substring( posOfSpace + 1 ); + } + //else just print + else + { + printStr = remainingStr; + remainingStr = ""; + } + + instructionsText.append( printStr + "\n" ); + + }// while + + }// for + + }//printInstructions() + + //DO NOT call this directly, go through Sysout + public void displayMessage( String messageIn ) + { + messageText.append( messageIn + "\n" ); + System.out.println(messageIn); + } + + //catch presses of the passed and failed buttons. + //simply call the standard pass() or fail() static methods of + //ManualMainTest + public void actionPerformed( ActionEvent e ) + { + if( e.getActionCommand() == "pass" ) + { + Test.pass(); + } + else + { + Test.fail(); + } + } + +}// TestDialog class diff --git a/jdk/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test1.java b/jdk/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test1.java new file mode 100644 index 00000000000..24d0670b4c2 --- /dev/null +++ b/jdk/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test1.java @@ -0,0 +1,386 @@ +/* + @test + @bug 6431076 + @summary Mouse cursor must remain DEFAULT over scrollbar when text is typed + @author Andrei Dmitriev: area=TextArea + @run main/manual Test1 +*/ + +import java.awt.*; +import java.awt.event.*; + +public class Test1 { + private static void init() { + Frame f = new Frame("Test1 for cursor"); + final int dim = 100; + String line = ""; + for( int i=0; i 0 ) + { + //if longer than max then chop off first max chars to print + if( remainingStr.length() >= maxStringLength ) + { + //Try to chop on a word boundary + int posOfSpace = remainingStr. + lastIndexOf( ' ', maxStringLength - 1 ); + + if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; + + printStr = remainingStr.substring( 0, posOfSpace + 1 ); + remainingStr = remainingStr.substring( posOfSpace + 1 ); + } + //else just print + else + { + printStr = remainingStr; + remainingStr = ""; + } + + instructionsText.append( printStr + "\n" ); + + }// while + + }// for + + }//printInstructions() + + //DO NOT call this directly, go through Sysout + public void displayMessage( String messageIn ) + { + messageText.append( messageIn + "\n" ); + System.out.println(messageIn); + } + + //catch presses of the passed and failed buttons. + //simply call the standard pass() or fail() static methods of + //ManualMainTest + public void actionPerformed( ActionEvent e ) + { + if( e.getActionCommand() == "pass" ) + { + Test1.pass(); + } + else + { + Test1.fail(); + } + } + +}// TestDialog class From ec50779b72f236684ab2f58b2bdc302b499cd227 Mon Sep 17 00:00:00 2001 From: Joe Darcy Date: Tue, 25 Jan 2011 17:02:56 -0800 Subject: [PATCH 06/73] 7013420: Project Coin: remove general expression support from try-with-resources statement Reviewed-by: mcimadamore, jjg --- .../sun/tools/javac/parser/JavacParser.java | 26 ++++----- .../tools/javac/resources/compiler.properties | 2 + .../javac/TryWithResources/BadTwrSyntax.out | 2 +- .../TryWithResources/DuplicateResource.java | 10 ++-- .../javac/TryWithResources/ExplicitFinal.java | 56 +++++++++++++++++++ .../javac/TryWithResources/ImplicitFinal.java | 25 +++++++-- .../javac/TryWithResources/ImplicitFinal.out | 5 +- .../tools/javac/TryWithResources/TwrFlow.java | 18 ++---- .../tools/javac/TryWithResources/TwrFlow.out | 4 +- .../TryWithResources/TwrIntersection.java | 47 ---------------- .../TryWithResources/TwrIntersection02.java | 37 ------------ .../TryWithResources/TwrIntersection02.out | 3 - .../javac/TryWithResources/TwrMultiCatch.java | 12 ++-- .../TryWithResources/TwrOnNonResource.java | 14 +---- .../TryWithResources/TwrOnNonResource.out | 5 +- .../examples/TryResourceTrailingSemi.java} | 24 +++----- 16 files changed, 118 insertions(+), 172 deletions(-) create mode 100644 langtools/test/tools/javac/TryWithResources/ExplicitFinal.java delete mode 100644 langtools/test/tools/javac/TryWithResources/TwrIntersection.java delete mode 100644 langtools/test/tools/javac/TryWithResources/TwrIntersection02.java delete mode 100644 langtools/test/tools/javac/TryWithResources/TwrIntersection02.out rename langtools/test/tools/javac/{TryWithResources/TwrInference.java => diags/examples/TryResourceTrailingSemi.java} (67%) diff --git a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java index 913accf1998..25fa6c939da 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java +++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java @@ -142,7 +142,7 @@ public class JavacParser implements Parser { */ boolean allowAnnotations; - /** Switch: should we recognize automatic resource management? + /** Switch: should we recognize try-with-resources? */ boolean allowTWR; @@ -2184,29 +2184,23 @@ public class JavacParser implements Parser { while (S.token() == SEMI) { // All but last of multiple declarators subsume a semicolon storeEnd(defs.elems.last(), S.endPos()); + int semiColonPos = S.pos(); S.nextToken(); + if (S.token() == RPAREN) { // Illegal trailing semicolon + // after last resource + error(semiColonPos, "try.resource.trailing.semi"); + break; + } defs.append(resource()); } return defs.toList(); } - /** Resource = - * VariableModifiers Type VariableDeclaratorId = Expression - * | Expression + /** Resource = VariableModifiersOpt Type VariableDeclaratorId = Expression */ JCTree resource() { - int pos = S.pos(); - if (S.token() == FINAL || S.token() == MONKEYS_AT) { - return variableDeclaratorRest(pos, optFinal(0), parseType(), - ident(), true, null); - } else { - JCExpression t = term(EXPR | TYPE); - if ((lastmode & TYPE) != 0 && S.token() == IDENTIFIER) - return variableDeclaratorRest(pos, toP(F.at(pos).Modifiers(Flags.FINAL)), t, - ident(), true, null); - else - return t; - } + return variableDeclaratorRest(S.pos(), optFinal(Flags.FINAL), + parseType(), ident(), true, null); } /** CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration} diff --git a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties index ee4201a80b8..178d3669ff5 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -177,6 +177,8 @@ compiler.err.final.parameter.may.not.be.assigned=\ final parameter {0} may not be assigned compiler.err.try.resource.may.not.be.assigned=\ auto-closeable resource {0} may not be assigned +compiler.err.try.resource.trailing.semi=\ + illegal trailing semicolon in resources declaration compiler.err.multicatch.parameter.may.not.be.assigned=\ multi-catch parameter {0} may not be assigned compiler.err.finally.without.try=\ diff --git a/langtools/test/tools/javac/TryWithResources/BadTwrSyntax.out b/langtools/test/tools/javac/TryWithResources/BadTwrSyntax.out index df925e04eb9..74529acd0d8 100644 --- a/langtools/test/tools/javac/TryWithResources/BadTwrSyntax.out +++ b/langtools/test/tools/javac/TryWithResources/BadTwrSyntax.out @@ -1,2 +1,2 @@ -BadTwrSyntax.java:14:43: compiler.err.illegal.start.of.expr +BadTwrSyntax.java:14:42: compiler.err.try.resource.trailing.semi 1 error diff --git a/langtools/test/tools/javac/TryWithResources/DuplicateResource.java b/langtools/test/tools/javac/TryWithResources/DuplicateResource.java index ca2f554244f..78961abc906 100644 --- a/langtools/test/tools/javac/TryWithResources/DuplicateResource.java +++ b/langtools/test/tools/javac/TryWithResources/DuplicateResource.java @@ -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,9 +23,9 @@ /* * @test - * @bug 6911256 6964740 6965277 + * @bug 6911256 6964740 6965277 7013420 * @author Maurizio Cimadamore - * @summary Check that lowered arm block does not end up creating resource twice + * @summary Check that lowered try-with-resources block does not end up creating resource twice */ import java.util.ArrayList; @@ -45,7 +45,7 @@ public class DuplicateResource { static ArrayList resources = new ArrayList(); public static void main(String[] args) { - try(new TestResource()) { + try(TestResource tr = new TestResource()) { //do something } catch (Exception e) { throw new AssertionError("Shouldn't reach here", e); @@ -59,7 +59,7 @@ public class DuplicateResource { } TestResource resource = resources.get(0); if (!resource.isClosed) { - throw new AssertionError("Resource used in ARM block has not been automatically closed"); + throw new AssertionError("Resource used in try-with-resources block has not been automatically closed"); } } } diff --git a/langtools/test/tools/javac/TryWithResources/ExplicitFinal.java b/langtools/test/tools/javac/TryWithResources/ExplicitFinal.java new file mode 100644 index 00000000000..e77de854f47 --- /dev/null +++ b/langtools/test/tools/javac/TryWithResources/ExplicitFinal.java @@ -0,0 +1,56 @@ +/* + * 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 7013420 + * @author Joseph D. Darcy + * @summary Test that resource variables are accepted as explicitly final. + */ + +import java.io.IOException; + +public class ExplicitFinal implements AutoCloseable { + public static void main(String... args) { + try(final ExplicitFinal r2 = new ExplicitFinal()) { + r2.toString(); + } catch (IOException ioe) { + throw new AssertionError("Shouldn't reach here", ioe); + } + + try(final @SuppressWarnings("unchecked") ExplicitFinal r3 = new ExplicitFinal()) { + r3.toString(); + } catch (IOException ioe) { + throw new AssertionError("Shouldn't reach here", ioe); + } + + try(@SuppressWarnings("unchecked") ExplicitFinal r4 = new ExplicitFinal()) { + r4.toString(); + } catch (IOException ioe) { + throw new AssertionError("Shouldn't reach here", ioe); + } + } + public void close() throws IOException { + System.out.println("Calling close on " + this); + } +} diff --git a/langtools/test/tools/javac/TryWithResources/ImplicitFinal.java b/langtools/test/tools/javac/TryWithResources/ImplicitFinal.java index ebcf0aff3f2..33e80365c36 100644 --- a/langtools/test/tools/javac/TryWithResources/ImplicitFinal.java +++ b/langtools/test/tools/javac/TryWithResources/ImplicitFinal.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 6911256 6964740 6965277 + * @bug 6911256 6964740 6965277 7013420 * @author Maurizio Cimadamore * @summary Test that resource variables are implicitly final * @compile/fail/ref=ImplicitFinal.out -XDrawDiagnostics ImplicitFinal.java @@ -15,12 +15,25 @@ class ImplicitFinal implements AutoCloseable { } catch (IOException ioe) { // Not reachable throw new AssertionError("Shouldn't reach here", ioe); } + + try(@SuppressWarnings("unchecked") ImplicitFinal r1 = new ImplicitFinal()) { + r1 = null; //disallowed + } catch (IOException ioe) { // Not reachable + throw new AssertionError("Shouldn't reach here", ioe); + } + + try(final ImplicitFinal r2 = new ImplicitFinal()) { + r2 = null; //disallowed + } catch (IOException ioe) { // Not reachable + throw new AssertionError("Shouldn't reach here", ioe); + } + + try(final @SuppressWarnings("unchecked") ImplicitFinal r3 = new ImplicitFinal()) { + r3 = null; //disallowed + } catch (IOException ioe) { // Not reachable + throw new AssertionError("Shouldn't reach here", ioe); + } } - - - // A close method, but the class is not Closeable or - // AutoCloseable. - public void close() throws IOException { throw new IOException(); } diff --git a/langtools/test/tools/javac/TryWithResources/ImplicitFinal.out b/langtools/test/tools/javac/TryWithResources/ImplicitFinal.out index 062fd46b668..ef61fca045a 100644 --- a/langtools/test/tools/javac/TryWithResources/ImplicitFinal.out +++ b/langtools/test/tools/javac/TryWithResources/ImplicitFinal.out @@ -1,2 +1,5 @@ ImplicitFinal.java:14:13: compiler.err.try.resource.may.not.be.assigned: r -1 error +ImplicitFinal.java:20:13: compiler.err.try.resource.may.not.be.assigned: r1 +ImplicitFinal.java:26:13: compiler.err.try.resource.may.not.be.assigned: r2 +ImplicitFinal.java:32:13: compiler.err.try.resource.may.not.be.assigned: r3 +4 errors diff --git a/langtools/test/tools/javac/TryWithResources/TwrFlow.java b/langtools/test/tools/javac/TryWithResources/TwrFlow.java index 01f8b1aa2e9..eec9eb8e063 100644 --- a/langtools/test/tools/javac/TryWithResources/TwrFlow.java +++ b/langtools/test/tools/javac/TryWithResources/TwrFlow.java @@ -1,26 +1,16 @@ /* * @test /nodynamiccopyright/ - * @bug 6911256 6964740 + * @bug 6911256 6964740 7013420 * @author Joseph D. Darcy - * @summary Test exception analysis of ARM blocks + * @summary Test exception analysis of try-with-resources blocks * @compile/fail/ref=TwrFlow.out -XDrawDiagnostics TwrFlow.java */ import java.io.IOException; public class TwrFlow implements AutoCloseable { public static void main(String... args) { - try(TwrFlow armflow = new TwrFlow()) { - System.out.println(armflow.toString()); - } catch (IOException ioe) { // Not reachable - throw new AssertionError("Shouldn't reach here", ioe); - } - // CustomCloseException should be caught or added to throws clause - - // Also check behavior on a resource expression rather than a - // declaration. - TwrFlow armflowexpr = new TwrFlow(); - try(armflowexpr) { - System.out.println(armflowexpr.toString()); + try(TwrFlow twrFlow = new TwrFlow()) { + System.out.println(twrFlow.toString()); } catch (IOException ioe) { // Not reachable throw new AssertionError("Shouldn't reach here", ioe); } diff --git a/langtools/test/tools/javac/TryWithResources/TwrFlow.out b/langtools/test/tools/javac/TryWithResources/TwrFlow.out index dd0e61aebf4..a91ea1aceee 100644 --- a/langtools/test/tools/javac/TryWithResources/TwrFlow.out +++ b/langtools/test/tools/javac/TryWithResources/TwrFlow.out @@ -1,5 +1,3 @@ TwrFlow.java:14:11: compiler.err.except.never.thrown.in.try: java.io.IOException -TwrFlow.java:24:11: compiler.err.except.never.thrown.in.try: java.io.IOException TwrFlow.java:12:46: compiler.err.unreported.exception.need.to.catch.or.throw: CustomCloseException -TwrFlow.java:22:26: compiler.err.unreported.exception.need.to.catch.or.throw: CustomCloseException -4 errors +2 errors diff --git a/langtools/test/tools/javac/TryWithResources/TwrIntersection.java b/langtools/test/tools/javac/TryWithResources/TwrIntersection.java deleted file mode 100644 index 4e3a1303736..00000000000 --- a/langtools/test/tools/javac/TryWithResources/TwrIntersection.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * 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 6911256 6964740 6965277 - * @author Maurizio Cimadamore - * @summary Resource of an intersection type crashes Flow - * @compile TwrIntersection.java - */ - -interface MyCloseable extends AutoCloseable { - void close() throws java.io.IOException; -} - -class ResourceTypeVar { - - public void test() { - try(getX()) { - //do something - } catch (java.io.IOException e) { // Not reachable - throw new AssertionError("Shouldn't reach here", e); - } - } - - X getX() { return null; } -} diff --git a/langtools/test/tools/javac/TryWithResources/TwrIntersection02.java b/langtools/test/tools/javac/TryWithResources/TwrIntersection02.java deleted file mode 100644 index 3cefe6b505c..00000000000 --- a/langtools/test/tools/javac/TryWithResources/TwrIntersection02.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * @test /nodynamiccopyright/ - * @bug 6911256 6964740 6965277 - * @author Maurizio Cimadamore - * @summary Check that resources of an intersection type forces union of exception types - * to be caught outside twr block - * @compile/fail/ref=TwrIntersection02.out -XDrawDiagnostics TwrIntersection02.java - */ - -class TwrIntersection02 { - - static class Exception1 extends Exception {} - static class Exception2 extends Exception {} - - - interface MyResource1 extends AutoCloseable { - void close() throws Exception1; - } - - interface MyResource2 extends AutoCloseable { - void close() throws Exception2; - } - - public void test1() throws Exception1 { - try(getX()) { - //do something - } - } - - public void test2() throws Exception2 { - try(getX()) { - //do something - } - } - - X getX() { return null; } -} diff --git a/langtools/test/tools/javac/TryWithResources/TwrIntersection02.out b/langtools/test/tools/javac/TryWithResources/TwrIntersection02.out deleted file mode 100644 index 69a5f3f1c78..00000000000 --- a/langtools/test/tools/javac/TryWithResources/TwrIntersection02.out +++ /dev/null @@ -1,3 +0,0 @@ -TwrIntersection02.java:25:21: compiler.err.unreported.exception.need.to.catch.or.throw: TwrIntersection02.Exception2 -TwrIntersection02.java:31:21: compiler.err.unreported.exception.need.to.catch.or.throw: TwrIntersection02.Exception1 -2 errors diff --git a/langtools/test/tools/javac/TryWithResources/TwrMultiCatch.java b/langtools/test/tools/javac/TryWithResources/TwrMultiCatch.java index 8b49837d80e..dbbb633efe1 100644 --- a/langtools/test/tools/javac/TryWithResources/TwrMultiCatch.java +++ b/langtools/test/tools/javac/TryWithResources/TwrMultiCatch.java @@ -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 6911256 6964740 + * @bug 6911256 6964740 7013420 * @author Joseph D. Darcy * @summary Test that TWR and multi-catch play well together * @compile TwrMultiCatch.java @@ -48,9 +48,9 @@ public class TwrMultiCatch implements AutoCloseable { private static void test(TwrMultiCatch twrMultiCatch, Class expected) { - try(twrMultiCatch) { - System.out.println(twrMultiCatch.toString()); - } catch (final CustomCloseException1 | + try(TwrMultiCatch tmc = twrMultiCatch) { + System.out.println(tmc.toString()); + } catch (CustomCloseException1 | CustomCloseException2 exception) { if (!exception.getClass().equals(expected) ) { throw new RuntimeException("Unexpected catch!"); @@ -68,7 +68,7 @@ public class TwrMultiCatch implements AutoCloseable { try { throw t; - } catch (final CustomCloseException1 | + } catch (CustomCloseException1 | CustomCloseException2 exception) { throw exception; } catch (Throwable throwable) { diff --git a/langtools/test/tools/javac/TryWithResources/TwrOnNonResource.java b/langtools/test/tools/javac/TryWithResources/TwrOnNonResource.java index 5673243ae95..07027dcf314 100644 --- a/langtools/test/tools/javac/TryWithResources/TwrOnNonResource.java +++ b/langtools/test/tools/javac/TryWithResources/TwrOnNonResource.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 6911256 6964740 + * @bug 6911256 6964740 7013420 * @author Joseph D. Darcy * @summary Verify invalid TWR block is not accepted. * @compile/fail -source 6 TwrOnNonResource.java @@ -18,18 +18,6 @@ class TwrOnNonResource { try(TwrOnNonResource aonr = new TwrOnNonResource()) { System.out.println(aonr.toString()); } catch (Exception e) {;} - - // Also check expression form - TwrOnNonResource aonr = new TwrOnNonResource(); - try(aonr) { - System.out.println(aonr.toString()); - } - try(aonr) { - System.out.println(aonr.toString()); - } finally {;} - try(aonr) { - System.out.println(aonr.toString()); - } catch (Exception e) {;} } /* diff --git a/langtools/test/tools/javac/TryWithResources/TwrOnNonResource.out b/langtools/test/tools/javac/TryWithResources/TwrOnNonResource.out index eafdbfbf632..37c67ab5807 100644 --- a/langtools/test/tools/javac/TryWithResources/TwrOnNonResource.out +++ b/langtools/test/tools/javac/TryWithResources/TwrOnNonResource.out @@ -1,7 +1,4 @@ TwrOnNonResource.java:12:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable TwrOnNonResource.java:15:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable TwrOnNonResource.java:18:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable -TwrOnNonResource.java:24:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable -TwrOnNonResource.java:27:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable -TwrOnNonResource.java:30:13: compiler.err.prob.found.req: (compiler.misc.try.not.applicable.to.type), TwrOnNonResource, java.lang.AutoCloseable -6 errors +3 errors diff --git a/langtools/test/tools/javac/TryWithResources/TwrInference.java b/langtools/test/tools/javac/diags/examples/TryResourceTrailingSemi.java similarity index 67% rename from langtools/test/tools/javac/TryWithResources/TwrInference.java rename to langtools/test/tools/javac/diags/examples/TryResourceTrailingSemi.java index 87187e43ffe..3511e91f181 100644 --- a/langtools/test/tools/javac/TryWithResources/TwrInference.java +++ b/langtools/test/tools/javac/diags/examples/TryResourceTrailingSemi.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -21,23 +21,15 @@ * questions. */ -/* - * @test - * @bug 6911256 6964740 6965277 - * @author Maurizio Cimadamore - * @summary Verify that method type-inference works as expected in TWR context - * @compile TwrInference.java - */ +// key: compiler.err.try.resource.trailing.semi -class TwrInference { - - public void test() { - try(getX()) { - //do something - } catch (Exception e) { // Not reachable - throw new AssertionError("Shouldn't reach here", e); +class TryResoureTrailingSemi implements AutoCloseable { + public static void main(String... args) { + try(TryResoureTrailingSemi r = new TryResoureTrailingSemi();) { + System.out.println(r.toString()); } } - X getX() { return null; } + @Override + public void close() {return;} } From a184b53cecd00a473eeb95168bf549c7971af8f1 Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Wed, 26 Jan 2011 11:20:19 -0800 Subject: [PATCH 07/73] 6554097: "final" confuses @SuppressWarnings Reviewed-by: mcimadamore --- .../com/sun/tools/javac/code/Symbol.java | 13 ++----- .../com/sun/tools/javac/comp/Attr.java | 35 +++++++++++++++++++ .../com/sun/tools/javac/comp/MemberEnter.java | 2 +- langtools/test/tools/javac/T6554097.java | 26 ++++++++++++++ langtools/test/tools/javac/T6554097.out | 7 ++++ 5 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 langtools/test/tools/javac/T6554097.java create mode 100644 langtools/test/tools/javac/T6554097.out diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java b/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java index 8ef070de9d5..4d862bafa83 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java @@ -961,22 +961,12 @@ public abstract class Symbol implements Element { } public void setLazyConstValue(final Env env, - final Log log, final Attr attr, final JCTree.JCExpression initializer) { setData(new Callable() { public Object call() { - JavaFileObject source = log.useSource(env.toplevel.sourcefile); - try { - Type itype = attr.attribExpr(initializer, env, type); - if (itype.constValue() != null) - return attr.coerce(itype, type).constValue(); - else - return null; - } finally { - log.useSource(source); - } + return attr.attribLazyConstantValue(env, initializer, type); } }); } @@ -1010,6 +1000,7 @@ public abstract class Symbol implements Element { try { data = eval.call(); } catch (Exception ex) { + ex.printStackTrace(); throw new AssertionError(ex); } } diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java index 2c94bad474d..8da688c8a42 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java @@ -581,6 +581,41 @@ public class Attr extends JCTree.Visitor { } } + /** + * Attribute a "lazy constant value". + * @param env The env for the const value + * @param initializer The initializer for the const value + * @param type The expected type, or null + * @see VarSymbol#setlazyConstValue + */ + public Object attribLazyConstantValue(Env env, + JCTree.JCExpression initializer, + Type type) { + + // in case no lint value has been set up for this env, scan up + // env stack looking for smallest enclosing env for which it is set. + Env lintEnv = env; + while (lintEnv.info.lint == null) + lintEnv = lintEnv.next; + + // Having found the enclosing lint value, we can initialize the lint value for this class + env.info.lint = lintEnv.info.lint.augment(env.info.enclVar.attributes_field, env.info.enclVar.flags()); + + Lint prevLint = chk.setLint(env.info.lint); + JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile); + + try { + Type itype = attribExpr(initializer, env, type); + if (itype.constValue() != null) + return coerce(itype, type).constValue(); + else + return null; + } finally { + env.info.lint = prevLint; + log.useSource(prevSource); + } + } + /** Attribute type reference in an `extends' or `implements' clause. * Supertypes of anonymous inner classes are usually already attributed. * diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java index 53b3cf706c2..481e1cb4022 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java @@ -637,7 +637,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer { if ((v.flags_field & FINAL) != 0 && tree.init.getTag() != JCTree.NEWCLASS) { Env initEnv = getInitEnv(tree, env); initEnv.info.enclVar = v; - v.setLazyConstValue(initEnv(tree, initEnv), log, attr, tree.init); + v.setLazyConstValue(initEnv(tree, initEnv), attr, tree.init); } } if (chk.checkUnique(tree.pos(), v, enclScope)) { diff --git a/langtools/test/tools/javac/T6554097.java b/langtools/test/tools/javac/T6554097.java new file mode 100644 index 00000000000..4deb2e9b5a8 --- /dev/null +++ b/langtools/test/tools/javac/T6554097.java @@ -0,0 +1,26 @@ +/* + * @test /nodynamiccopyright/ + * @bug 6554097 + * @summary "final" confuses at-SuppressWarnings + * @compile T6554097.java + * @compile/fail/ref=T6554097.out -XDrawDiagnostics -Werror -Xlint:serial T6554097.java + */ + +class T6554097 { + @SuppressWarnings("serial") final Throwable[] v1 = { new Throwable() {} }; + @SuppressWarnings("serial") Throwable[] v2 = { new Throwable() {} }; + + public static void m1() throws Throwable { + @SuppressWarnings("serial") final Throwable[] v3 = { new Throwable() {} }; + @SuppressWarnings("serial") Throwable[] v4 = { new Throwable() {} }; + } + + final Throwable[] v5 = { new Throwable() {} }; + Throwable[] v6 = { new Throwable() {} }; + + public static void m2() throws Throwable { + final Throwable[] v7 = { new Throwable() {} }; + Throwable[] v8 = { new Throwable() {} }; + } +} + diff --git a/langtools/test/tools/javac/T6554097.out b/langtools/test/tools/javac/T6554097.out new file mode 100644 index 00000000000..aecbd999cf5 --- /dev/null +++ b/langtools/test/tools/javac/T6554097.out @@ -0,0 +1,7 @@ +T6554097.java:18:46: compiler.warn.missing.SVUID: compiler.misc.anonymous.class: T6554097$5 +T6554097.java:19:46: compiler.warn.missing.SVUID: compiler.misc.anonymous.class: T6554097$6 +T6554097.java:22:50: compiler.warn.missing.SVUID: compiler.misc.anonymous.class: T6554097$7 +T6554097.java:23:54: compiler.warn.missing.SVUID: compiler.misc.anonymous.class: T6554097$8 +- compiler.err.warnings.and.werror +1 error +4 warnings From e5079417fd2e994bfa81a9144d835841b117ebad Mon Sep 17 00:00:00 2001 From: Phil Race Date: Wed, 26 Jan 2011 11:46:40 -0800 Subject: [PATCH 08/73] 7014738: Update jdk repo application manifests with Windows 7 compatibility section Reviewed-by: bae, igor --- jdk/src/windows/resource/java.manifest | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/jdk/src/windows/resource/java.manifest b/jdk/src/windows/resource/java.manifest index e5b44609820..24b19c06334 100644 --- a/jdk/src/windows/resource/java.manifest +++ b/jdk/src/windows/resource/java.manifest @@ -41,4 +41,12 @@ + + + + + + + + From eef80dd156d5d507d3c0d63541095e34b2ed3c11 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Wed, 26 Jan 2011 13:26:57 -0800 Subject: [PATCH 09/73] 6940890: Java doesn't pick up the correct fontconfig files in latest Solaris Next builds Reviewed-by: bae, igor --- .../sun/java2d/SunGraphicsEnvironment.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java b/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java index 5316005c5fe..ba443ca2ef2 100644 --- a/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java +++ b/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java @@ -95,6 +95,22 @@ public abstract class SunGraphicsEnvironment extends GraphicsEnvironment String line = br.readLine(); if (line.indexOf("OpenSolaris") >= 0) { isOpenSolaris = true; + } else { + /* We are using isOpenSolaris as meaning + * we know the Solaris commercial fonts aren't + * present. "Solaris Next" (03/10) did not + * include these even though its was not + * OpenSolaris. Need to revisit how this is + * handled but for now as in 6ux, we'll use + * the test for a standard font resource as + * being an indicator as to whether we need + * to treat this as OpenSolaris from a font + * config perspective. + */ + String courierNew = + "/usr/openwin/lib/X11/fonts/TrueType/CourierNew.ttf"; + File courierFile = new File(courierNew); + isOpenSolaris = !courierFile.exists(); } fis.close(); } From de3bde6688f26f8f073e7a78dff382825d20ad59 Mon Sep 17 00:00:00 2001 From: Jonathan Gibbons Date: Wed, 26 Jan 2011 13:45:25 -0800 Subject: [PATCH 10/73] 7013272: Automatically generate info about how compiler resource keys are used Reviewed-by: mcimadamore --- langtools/make/build.xml | 4 +- .../com/sun/tools/javac/code/Printer.java | 4 +- .../tools/javac/resources/compiler.properties | 664 ++++++++++++++++-- .../javac/diags/ArgTypeCompilerFactory.java | 346 +++++++++ langtools/test/tools/javac/diags/Example.java | 23 +- .../test/tools/javac/diags/MessageFile.java | 463 ++++++++++++ .../test/tools/javac/diags/MessageInfo.java | 406 +++++++++++ .../test/tools/javac/diags/RunExamples.java | 14 +- 8 files changed, 1859 insertions(+), 65 deletions(-) create mode 100644 langtools/test/tools/javac/diags/ArgTypeCompilerFactory.java create mode 100644 langtools/test/tools/javac/diags/MessageFile.java create mode 100644 langtools/test/tools/javac/diags/MessageInfo.java diff --git a/langtools/make/build.xml b/langtools/make/build.xml index aaa4d728a4c..e2cc6547ef4 100644 --- a/langtools/make/build.xml +++ b/langtools/make/build.xml @@ -1,6 +1,6 @@