# HG changeset patch # User bae # Date 1241783853 -14400 # Node ID 1ccef37a150f9d9e2e7d84d4f5f277df1221b910 # Parent 7d593a13099402ccb76c431482be3defb40721e0 6657133: Mutable statics in imageio plugins (findbugs) Reviewed-by: prr diff -r 7d593a130994 -r 1ccef37a150f jdk/src/share/classes/com/sun/imageio/stream/StreamCloser.java --- a/jdk/src/share/classes/com/sun/imageio/stream/StreamCloser.java Fri May 08 15:38:21 2009 +0400 +++ b/jdk/src/share/classes/com/sun/imageio/stream/StreamCloser.java Fri May 08 15:57:33 2009 +0400 @@ -43,35 +43,35 @@ */ public class StreamCloser { - private static WeakHashMap toCloseQueue; + private static WeakHashMap toCloseQueue; private static Thread streamCloser; - public static void addToQueue(ImageInputStream iis) { + public static void addToQueue(CloseAction ca) { synchronized (StreamCloser.class) { if (toCloseQueue == null) { toCloseQueue = - new WeakHashMap(); + new WeakHashMap(); } - toCloseQueue.put(iis, null); + toCloseQueue.put(ca, null); if (streamCloser == null) { final Runnable streamCloserRunnable = new Runnable() { public void run() { if (toCloseQueue != null) { synchronized (StreamCloser.class) { - Set set = + Set set = toCloseQueue.keySet(); // Make a copy of the set in order to avoid // concurrent modification (the is.close() // will in turn call removeFromQueue()) - ImageInputStream[] streams = - new ImageInputStream[set.size()]; - streams = set.toArray(streams); - for (ImageInputStream is : streams) { - if (is != null) { + CloseAction[] actions = + new CloseAction[set.size()]; + actions = set.toArray(actions); + for (CloseAction ca : actions) { + if (ca != null) { try { - is.close(); + ca.performAction(); } catch (IOException e) { } } @@ -106,10 +106,28 @@ } } - public static void removeFromQueue(ImageInputStream iis) { + public static void removeFromQueue(CloseAction ca) { synchronized (StreamCloser.class) { if (toCloseQueue != null) { - toCloseQueue.remove(iis); + toCloseQueue.remove(ca); + } + } + } + + public static CloseAction createCloseAction(ImageInputStream iis) { + return new CloseAction(iis); + } + + public static final class CloseAction { + private ImageInputStream iis; + + private CloseAction(ImageInputStream iis) { + this.iis = iis; + } + + public void performAction() throws IOException { + if (iis != null) { + iis.close(); } } } diff -r 7d593a130994 -r 1ccef37a150f jdk/src/share/classes/javax/imageio/plugins/bmp/BMPImageWriteParam.java --- a/jdk/src/share/classes/javax/imageio/plugins/bmp/BMPImageWriteParam.java Fri May 08 15:38:21 2009 +0400 +++ b/jdk/src/share/classes/javax/imageio/plugins/bmp/BMPImageWriteParam.java Fri May 08 15:57:33 2009 +0400 @@ -78,7 +78,7 @@ super(locale); // Set compression types ("BI_RGB" denotes uncompressed). - compressionTypes = BMPConstants.compressionTypeNames; + compressionTypes = BMPConstants.compressionTypeNames.clone(); // Set compression flag. canWriteCompressed = true; diff -r 7d593a130994 -r 1ccef37a150f jdk/src/share/classes/javax/imageio/stream/FileCacheImageInputStream.java --- a/jdk/src/share/classes/javax/imageio/stream/FileCacheImageInputStream.java Fri May 08 15:38:21 2009 +0400 +++ b/jdk/src/share/classes/javax/imageio/stream/FileCacheImageInputStream.java Fri May 08 15:57:33 2009 +0400 @@ -62,6 +62,10 @@ /** The DisposerRecord that closes the underlying cache. */ private final DisposerRecord disposerRecord; + /** The CloseAction that closes the stream in + * the StreamCloser's shutdown hook */ + private final StreamCloser.CloseAction closeAction; + /** * Constructs a FileCacheImageInputStream that will read * from a given InputStream. @@ -96,7 +100,9 @@ this.cacheFile = File.createTempFile("imageio", ".tmp", cacheDir); this.cache = new RandomAccessFile(cacheFile, "rw"); - StreamCloser.addToQueue(this); + + this.closeAction = StreamCloser.createCloseAction(this); + StreamCloser.addToQueue(closeAction); disposerRecord = new StreamDisposerRecord(cacheFile, cache); if (getClass() == FileCacheImageInputStream.class) { @@ -242,7 +248,7 @@ stream = null; cache = null; cacheFile = null; - StreamCloser.removeFromQueue(this); + StreamCloser.removeFromQueue(closeAction); } /** diff -r 7d593a130994 -r 1ccef37a150f jdk/src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java --- a/jdk/src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java Fri May 08 15:38:21 2009 +0400 +++ b/jdk/src/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java Fri May 08 15:57:33 2009 +0400 @@ -48,6 +48,10 @@ // Pos after last (rightmost) byte written private long maxStreamPos = 0L; + /** The CloseAction that closes the stream in + * the StreamCloser's shutdown hook */ + private final StreamCloser.CloseAction closeAction; + /** * Constructs a FileCacheImageOutputStream that will write * to a given outputStream. @@ -82,7 +86,9 @@ this.cacheFile = File.createTempFile("imageio", ".tmp", cacheDir); this.cache = new RandomAccessFile(cacheFile, "rw"); - StreamCloser.addToQueue(this); + + this.closeAction = StreamCloser.createCloseAction(this); + StreamCloser.addToQueue(closeAction); } public int read() throws IOException { @@ -227,7 +233,7 @@ cacheFile = null; stream.flush(); stream = null; - StreamCloser.removeFromQueue(this); + StreamCloser.removeFromQueue(closeAction); } public void flushBefore(long pos) throws IOException { diff -r 7d593a130994 -r 1ccef37a150f jdk/src/share/lib/security/java.security --- a/jdk/src/share/lib/security/java.security Fri May 08 15:38:21 2009 +0400 +++ b/jdk/src/share/lib/security/java.security Fri May 08 15:57:33 2009 +0400 @@ -127,7 +127,7 @@ # passed to checkPackageAccess unless the # corresponding RuntimePermission ("accessClassInPackage."+package) has # been granted. -package.access=sun. +package.access=sun.,com.sun.imageio. # # List of comma-separated packages that start with or equal this string diff -r 7d593a130994 -r 1ccef37a150f jdk/src/share/lib/security/java.security-solaris --- a/jdk/src/share/lib/security/java.security-solaris Fri May 08 15:38:21 2009 +0400 +++ b/jdk/src/share/lib/security/java.security-solaris Fri May 08 15:57:33 2009 +0400 @@ -128,7 +128,7 @@ # passed to checkPackageAccess unless the # corresponding RuntimePermission ("accessClassInPackage."+package) has # been granted. -package.access=sun. +package.access=sun.,com.sun.imageio. # # List of comma-separated packages that start with or equal this string diff -r 7d593a130994 -r 1ccef37a150f jdk/src/share/lib/security/java.security-windows --- a/jdk/src/share/lib/security/java.security-windows Fri May 08 15:38:21 2009 +0400 +++ b/jdk/src/share/lib/security/java.security-windows Fri May 08 15:57:33 2009 +0400 @@ -128,7 +128,7 @@ # passed to checkPackageAccess unless the # corresponding RuntimePermission ("accessClassInPackage."+package) has # been granted. -package.access=sun. +package.access=sun.,com.sun.imageio. # # List of comma-separated packages that start with or equal this string