8001119: [fingbugs] Evaluate necessity to make some arrays package protected
authorvadim
Mon, 30 Sep 2013 12:50:52 +0400
changeset 20415 a88fd521ef00
parent 20414 c43f5228a1f9
child 20416 c09e67746b08
8001119: [fingbugs] Evaluate necessity to make some arrays package protected Reviewed-by: prr, bae
jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPCompressionTypes.java
jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPConstants.java
jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPImageWriter.java
jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPMetadata.java
jdk/src/share/classes/com/sun/imageio/plugins/gif/GIFStreamMetadata.java
jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEG.java
jdk/src/share/classes/com/sun/imageio/plugins/png/PNGMetadata.java
jdk/src/share/classes/javax/imageio/plugins/bmp/BMPImageWriteParam.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPCompressionTypes.java	Mon Sep 30 12:50:52 2013 +0400
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  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.imageio.plugins.bmp;
+
+public class BMPCompressionTypes {
+
+    private static final String[] compressionTypeNames =
+        {"BI_RGB", "BI_RLE8", "BI_RLE4", "BI_BITFIELDS", "BI_JPEG", "BI_PNG"};
+
+    static int getType(String typeString) {
+        for (int i = 0; i < compressionTypeNames.length; i++)
+            if (compressionTypeNames[i].equals(typeString))
+                return i;
+        return 0;
+    }
+
+    static String getName(int type) {
+        return compressionTypeNames[type];
+    }
+
+    public static String[] getCompressionTypes() {
+        return compressionTypeNames.clone();
+    }
+}
--- a/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPConstants.java	Fri Sep 27 13:06:47 2013 -0700
+++ b/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPConstants.java	Mon Sep 30 12:50:52 2013 +0400
@@ -47,7 +47,4 @@
     static final int BI_BITFIELDS = 3;
     static final int BI_JPEG = 4;
     static final int BI_PNG = 5;
-
-    static final String[] compressionTypeNames =
-        {"BI_RGB", "BI_RLE8", "BI_RLE4", "BI_BITFIELDS", "BI_JPEG", "BI_PNG"};
 }
--- a/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPImageWriter.java	Fri Sep 27 13:06:47 2013 -0700
+++ b/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPImageWriter.java	Mon Sep 30 12:50:52 2013 +0400
@@ -25,7 +25,6 @@
 
 package com.sun.imageio.plugins.bmp;
 
-import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.image.ColorModel;
 import java.awt.image.ComponentSampleModel;
@@ -42,7 +41,6 @@
 import java.awt.image.RenderedImage;
 import java.awt.image.SampleModel;
 import java.awt.image.SinglePixelPackedSampleModel;
-import java.awt.image.WritableRaster;
 import java.awt.image.BufferedImage;
 
 import java.io.IOException;
@@ -51,22 +49,16 @@
 import java.util.Iterator;
 
 import javax.imageio.IIOImage;
-import javax.imageio.IIOException;
 import javax.imageio.ImageIO;
 import javax.imageio.ImageTypeSpecifier;
 import javax.imageio.ImageWriteParam;
 import javax.imageio.ImageWriter;
 import javax.imageio.metadata.IIOMetadata;
-import javax.imageio.metadata.IIOMetadataNode;
-import javax.imageio.metadata.IIOMetadataFormatImpl;
-import javax.imageio.metadata.IIOInvalidTreeException;
 import javax.imageio.spi.ImageWriterSpi;
 import javax.imageio.stream.ImageOutputStream;
 import javax.imageio.event.IIOWriteProgressListener;
 import javax.imageio.event.IIOWriteWarningListener;
 
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 
 import javax.imageio.plugins.bmp.BMPImageWriteParam;
 import com.sun.imageio.plugins.common.ImageUtil;
@@ -129,7 +121,7 @@
         meta.compression = getPreferredCompressionType(imageType);
         if (param != null
             && param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
-            meta.compression = getCompressionType(param.getCompressionType());
+            meta.compression = BMPCompressionTypes.getType(param.getCompressionType());
         }
         meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize();
         return meta;
@@ -308,7 +300,7 @@
 
         switch(bmpParam.getCompressionMode()) {
         case ImageWriteParam.MODE_EXPLICIT:
-            compressionType = getCompressionType(bmpParam.getCompressionType());
+            compressionType = BMPCompressionTypes.getType(bmpParam.getCompressionType());
             break;
         case ImageWriteParam.MODE_COPY_FROM_METADATA:
             compressionType = bmpImageMetadata.compression;
@@ -323,12 +315,12 @@
 
         if (!canEncodeImage(compressionType, colorModel, sampleModel)) {
             throw new IOException("Image can not be encoded with compression type "
-                                  + compressionTypeNames[compressionType]);
+                                  + BMPCompressionTypes.getName(compressionType));
         }
 
         byte r[] = null, g[] = null, b[] = null, a[] = null;
 
-        if (compressionType == BMPConstants.BI_BITFIELDS) {
+        if (compressionType == BI_BITFIELDS) {
             bitsPerPixel =
                 DataBuffer.getDataTypeSize(sampleModel.getDataType());
 
@@ -372,7 +364,7 @@
                     // an exception related to unsupported image format
                     throw new IOException("Image can not be encoded with " +
                                           "compression type " +
-                                          compressionTypeNames[compressionType]);
+                                          BMPCompressionTypes.getName(compressionType));
                 }
             }
             writeMaskToPalette(rmask, 0, r, g, b, a);
@@ -511,8 +503,8 @@
          * Images with any other compression type must be wrote in the
          * bottom-up layout.
          */
-        if (compressionType == BMPConstants.BI_RGB ||
-            compressionType == BMPConstants.BI_BITFIELDS)
+        if (compressionType == BI_RGB ||
+            compressionType == BI_BITFIELDS)
         {
             isTopDown = bmpParam.isTopDown();
         } else {
@@ -543,7 +535,7 @@
         if (isPalette == true) {
 
             // write palette
-            if (compressionType == BMPConstants.BI_BITFIELDS) {
+            if (compressionType == BI_BITFIELDS) {
                 // write masks for red, green and blue components.
                 for (int i=0; i<3; i++) {
                     int mask = (a[i]&0xFF) + ((r[i]&0xFF)*0x100) + ((g[i]&0xFF)*0x10000) + ((b[i]&0xFF)*0x1000000);
@@ -571,8 +563,8 @@
 
         int l;
 
-        if (compressionType == BMPConstants.BI_JPEG ||
-            compressionType == BMPConstants.BI_PNG) {
+        if (compressionType == BI_JPEG ||
+            compressionType == BI_PNG) {
 
             // prepare embedded buffer
             embedded_stream = new ByteArrayOutputStream();
@@ -657,7 +649,7 @@
                     pos = sppsm.getOffset(startX, startY);
                 }
 
-                if (compressionType == BMPConstants.BI_RGB || compressionType == BMPConstants.BI_BITFIELDS){
+                if (compressionType == BI_RGB || compressionType == BI_BITFIELDS){
                     switch(dataType) {
                     case DataBuffer.TYPE_BYTE:
                         byte[] bdata =
@@ -687,7 +679,7 @@
                     for(int k=0; k<padding; k++) {
                         stream.writeByte(0);
                     }
-                } else if (compressionType == BMPConstants.BI_RLE4) {
+                } else if (compressionType == BI_RLE4) {
                     if (bpixels == null || bpixels.length < scanlineBytes)
                         bpixels = new byte[scanlineBytes];
                     src.getPixels(srcRect.x, srcRect.y,
@@ -696,7 +688,7 @@
                         bpixels[h] = (byte)pixels[h];
                     }
                     encodeRLE4(bpixels, scanlineBytes);
-                } else if (compressionType == BMPConstants.BI_RLE8) {
+                } else if (compressionType == BI_RLE8) {
                     //byte[] bdata =
                     //    ((DataBufferByte)src.getDataBuffer()).getData();
                     //System.out.println("bdata.length="+bdata.length);
@@ -734,8 +726,8 @@
             processImageProgress(100.0f * (((float)i) / ((float)h)));
         }
 
-        if (compressionType == BMPConstants.BI_RLE4 ||
-            compressionType == BMPConstants.BI_RLE8) {
+        if (compressionType == BI_RLE4 ||
+            compressionType == BI_RLE8) {
             // Write the RLE EOF marker and
             stream.writeByte(0);
             stream.writeByte(1);
@@ -793,7 +785,7 @@
             break;
 
         case 4:
-            if (compressionType == BMPConstants.BI_RLE4){
+            if (compressionType == BI_RLE4){
                 byte[] bipixels = new byte[scanlineBytes];
                 for (int h=0; h<scanlineBytes; h++) {
                     bipixels[h] = (byte)pixels[l++];
@@ -814,7 +806,7 @@
             break;
 
         case 8:
-            if(compressionType == BMPConstants.BI_RLE8) {
+            if(compressionType == BI_RLE8) {
                 for (int h=0; h<scanlineBytes; h++) {
                     bpixels[h] = (byte)pixels[l++];
                 }
@@ -841,7 +833,7 @@
              */
             for (int j = 0, m = 0; j < scanlineBytes; m++) {
                 spixels[m] = 0;
-                if (compressionType == BMPConstants.BI_RGB) {
+                if (compressionType == BI_RGB) {
                     /*
                      * please note that despite other cases,
                      * the 16bpp BI_RGB requires the RGB data order
@@ -910,7 +902,7 @@
                  */
                 for (int j = 0, m = 0; j < scanlineBytes; m++) {
                     ipixels[m] = 0;
-                    if (compressionType == BMPConstants.BI_RGB) {
+                    if (compressionType == BI_RGB) {
                         ipixels[m] =
                             ((0xff & pixels[j + 2]) << 16) |
                             ((0xff & pixels[j + 1]) <<  8) |
@@ -945,8 +937,8 @@
         }
 
         // Write out the padding
-        if (compressionType == BMPConstants.BI_RGB ||
-            compressionType == BMPConstants.BI_BITFIELDS)
+        if (compressionType == BI_RGB ||
+            compressionType == BI_BITFIELDS)
         {
             for(k=0; k<padding; k++) {
                 stream.writeByte(0);
@@ -1329,17 +1321,10 @@
         stream = null;
     }
 
-    private int getCompressionType(String typeString) {
-        for (int i = 0; i < BMPConstants.compressionTypeNames.length; i++)
-            if (BMPConstants.compressionTypeNames[i].equals(typeString))
-                return i;
-        return 0;
-    }
-
     private void writeEmbedded(IIOImage image,
                                ImageWriteParam bmpParam) throws IOException {
         String format =
-            compressionType == BMPConstants.BI_JPEG ? "jpeg" : "png";
+            compressionType == BI_JPEG ? "jpeg" : "png";
         Iterator iterator = ImageIO.getImageWritersByFormatName(format);
         ImageWriter writer = null;
         if (iterator.hasNext())
--- a/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPMetadata.java	Fri Sep 27 13:06:47 2013 -0700
+++ b/jdk/src/share/classes/com/sun/imageio/plugins/bmp/BMPMetadata.java	Mon Sep 30 12:50:52 2013 +0400
@@ -219,7 +219,7 @@
 
         // CompressionTypeName
         IIOMetadataNode subNode = new IIOMetadataNode("CompressionTypeName");
-        subNode.setAttribute("value", compressionTypeNames[compression]);
+        subNode.setAttribute("value", BMPCompressionTypes.getName(compression));
         node.appendChild(subNode);
         return node;
     }
--- a/jdk/src/share/classes/com/sun/imageio/plugins/gif/GIFStreamMetadata.java	Fri Sep 27 13:06:47 2013 -0700
+++ b/jdk/src/share/classes/com/sun/imageio/plugins/gif/GIFStreamMetadata.java	Mon Sep 30 12:50:52 2013 +0400
@@ -25,11 +25,8 @@
 
 package com.sun.imageio.plugins.gif;
 
-import javax.imageio.ImageTypeSpecifier;
 import javax.imageio.metadata.IIOInvalidTreeException;
-import javax.imageio.metadata.IIOMetadata;
 import javax.imageio.metadata.IIOMetadataNode;
-import javax.imageio.metadata.IIOMetadataFormat;
 import javax.imageio.metadata.IIOMetadataFormatImpl;
 import org.w3c.dom.Node;
 
@@ -41,7 +38,7 @@
     static final String
         nativeMetadataFormatName = "javax_imageio_gif_stream_1.0";
 
-    public static final String[] versionStrings = { "87a", "89a" };
+    static final String[] versionStrings = { "87a", "89a" };
 
     public String version; // 87a or 89a
     public int logicalScreenWidth;
@@ -52,7 +49,7 @@
     public int backgroundColorIndex; // Valid if globalColorTable != null
     public boolean sortFlag; // Valid if globalColorTable != null
 
-    public static final String[] colorTableSizes = {
+    static final String[] colorTableSizes = {
         "2", "4", "8", "16", "32", "64", "128", "256"
     };
 
--- a/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEG.java	Fri Sep 27 13:06:47 2013 -0700
+++ b/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEG.java	Mon Sep 30 12:50:52 2013 +0400
@@ -25,14 +25,11 @@
 
 package com.sun.imageio.plugins.jpeg;
 
-import javax.imageio.metadata.IIOMetadataFormatImpl;
 import javax.imageio.ImageTypeSpecifier;
 import javax.imageio.plugins.jpeg.JPEGQTable;
 import javax.imageio.plugins.jpeg.JPEGHuffmanTable;
 
 import java.awt.image.ColorModel;
-import java.awt.image.BufferedImage;
-import java.awt.image.DataBuffer;
 import java.awt.color.ColorSpace;
 import java.awt.color.ICC_ColorSpace;
 
@@ -172,9 +169,9 @@
     public static final String vendor = "Oracle Corporation";
     public static final String version = "0.5";
     // Names of the formats we can read or write
-    public static final String [] names = {"JPEG", "jpeg", "JPG", "jpg"};
-    public static final String [] suffixes = {"jpg", "jpeg"};
-    public static final String [] MIMETypes = {"image/jpeg"};
+    static final String [] names = {"JPEG", "jpeg", "JPG", "jpg"};
+    static final String [] suffixes = {"jpg", "jpeg"};
+    static final String [] MIMETypes = {"image/jpeg"};
     public static final String nativeImageMetadataFormatName =
         "javax_imageio_jpeg_image_1.0";
     public static final String nativeImageMetadataFormatClassName =
@@ -201,12 +198,12 @@
     public static final int NUM_JCS_CODES = JCS_YCCK+1;
 
     /** IJG can handle up to 4-channel JPEGs */
-    public static final int [] [] bandOffsets = {{0},
+    static final int [] [] bandOffsets = {{0},
                                           {0, 1},
                                           {0, 1, 2},
                                           {0, 1, 2, 3}};
 
-    public static final int [] bOffsRGB = { 2, 1, 0 };
+    static final int [] bOffsRGB = { 2, 1, 0 };
 
     /* These are kept in the inner class to avoid static initialization
      * of the CMM class until someone actually needs it.
--- a/jdk/src/share/classes/com/sun/imageio/plugins/png/PNGMetadata.java	Fri Sep 27 13:06:47 2013 -0700
+++ b/jdk/src/share/classes/com/sun/imageio/plugins/png/PNGMetadata.java	Mon Sep 30 12:50:52 2013 +0400
@@ -29,12 +29,10 @@
 import java.awt.image.IndexColorModel;
 import java.awt.image.SampleModel;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.StringTokenizer;
 import javax.imageio.ImageTypeSpecifier;
 import javax.imageio.metadata.IIOInvalidTreeException;
 import javax.imageio.metadata.IIOMetadata;
-import javax.imageio.metadata.IIOMetadataFormat;
 import javax.imageio.metadata.IIOMetadataFormatImpl;
 import javax.imageio.metadata.IIOMetadataNode;
 import org.w3c.dom.Node;
@@ -49,42 +47,42 @@
         = "com.sun.imageio.plugins.png.PNGMetadataFormat";
 
     // Color types for IHDR chunk
-    public static final String[] IHDR_colorTypeNames = {
+    static final String[] IHDR_colorTypeNames = {
         "Grayscale", null, "RGB", "Palette",
         "GrayAlpha", null, "RGBAlpha"
     };
 
-    public static final int[] IHDR_numChannels = {
+    static final int[] IHDR_numChannels = {
         1, 0, 3, 3, 2, 0, 4
     };
 
     // Bit depths for IHDR chunk
-    public static final String[] IHDR_bitDepths = {
+    static final String[] IHDR_bitDepths = {
         "1", "2", "4", "8", "16"
     };
 
     // Compression methods for IHDR chunk
-    public static final String[] IHDR_compressionMethodNames = {
+    static final String[] IHDR_compressionMethodNames = {
         "deflate"
     };
 
     // Filter methods for IHDR chunk
-    public static final String[] IHDR_filterMethodNames = {
+    static final String[] IHDR_filterMethodNames = {
         "adaptive"
     };
 
     // Interlace methods for IHDR chunk
-    public static final String[] IHDR_interlaceMethodNames = {
+    static final String[] IHDR_interlaceMethodNames = {
         "none", "adam7"
     };
 
     // Compression methods for iCCP chunk
-    public static final String[] iCCP_compressionMethodNames = {
+    static final String[] iCCP_compressionMethodNames = {
         "deflate"
     };
 
     // Compression methods for zTXt chunk
-    public static final String[] zTXt_compressionMethodNames = {
+    static final String[] zTXt_compressionMethodNames = {
         "deflate"
     };
 
@@ -95,12 +93,12 @@
     public static final int PHYS_UNIT_METER = 1;
 
     // Unit specifiers for pHYs chunk
-    public static final String[] unitSpecifierNames = {
+    static final String[] unitSpecifierNames = {
         "unknown", "meter"
     };
 
     // Rendering intents for sRGB chunk
-    public static final String[] renderingIntentNames = {
+    static final String[] renderingIntentNames = {
         "Perceptual", // 0
         "Relative colorimetric", // 1
         "Saturation", // 2
@@ -109,7 +107,7 @@
     };
 
     // Color space types for Chroma->ColorSpaceType node
-    public static final String[] colorSpaceTypeNames = {
+    static final String[] colorSpaceTypeNames = {
         "GRAY", null, "RGB", "RGB",
         "GRAY", null, "RGB"
     };
--- a/jdk/src/share/classes/javax/imageio/plugins/bmp/BMPImageWriteParam.java	Fri Sep 27 13:06:47 2013 -0700
+++ b/jdk/src/share/classes/javax/imageio/plugins/bmp/BMPImageWriteParam.java	Mon Sep 30 12:50:52 2013 +0400
@@ -29,6 +29,7 @@
 import javax.imageio.ImageWriteParam;
 
 import com.sun.imageio.plugins.bmp.BMPConstants;
+import com.sun.imageio.plugins.bmp.BMPCompressionTypes;
 
 /**
  * A subclass of <code>ImageWriteParam</code> for encoding images in
@@ -78,7 +79,7 @@
         super(locale);
 
         // Set compression types ("BI_RGB" denotes uncompressed).
-        compressionTypes = BMPConstants.compressionTypeNames.clone();
+        compressionTypes = BMPCompressionTypes.getCompressionTypes();
 
         // Set compression flag.
         canWriteCompressed = true;