changeset 2116:7dadd2951a8b

6921740: Eliminate warnings from sun.io converters and allow compiling with JAVAC_MAX_WARNINGS=true Summary: Fix sun.io converters unchecked and cast warnings produced by -Xlint:all Reviewed-by: alanb, sherman
author andrew
date Tue, 02 Feb 2010 10:55:07 +0000
parents 946b30073247
children e6ab5fabaf7e
files make/java/sun_nio/Makefile src/share/classes/sun/io/ByteToCharUTF8.java src/share/classes/sun/io/CharToByteUnicode.java src/share/classes/sun/io/CharacterEncoding.java src/share/classes/sun/io/Converters.java src/share/classes/sun/nio/cs/AbstractCharsetProvider.java
diffstat 6 files changed, 71 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/make/java/sun_nio/Makefile	Wed Jan 27 19:39:55 2010 -0800
+++ b/make/java/sun_nio/Makefile	Tue Feb 02 10:55:07 2010 +0000
@@ -31,7 +31,7 @@
 PACKAGE = sun.nio
 PRODUCT = sun
 
-OTHER_JAVACFLAGS += -Xlint:serial -Werror
+OTHER_JAVACFLAGS += -Xlint:serial,-deprecation -Werror
 include $(BUILDDIR)/common/Defs.gmk
 
 #
--- a/src/share/classes/sun/io/ByteToCharUTF8.java	Wed Jan 27 19:39:55 2010 -0800
+++ b/src/share/classes/sun/io/ByteToCharUTF8.java	Tue Feb 02 10:55:07 2010 +0000
@@ -113,7 +113,7 @@
                         savedSize = 1;
                     } else {
                         savedSize = 2;
-                        savedBytes[1] = (byte)input[byteOff++];
+                        savedBytes[1] = input[byteOff++];
                     }
                     break;
                 }
@@ -135,11 +135,11 @@
                         savedSize = 1;
                     } else if (byteOff + 1 >= inEnd) {
                         savedSize = 2;
-                        savedBytes[1] = (byte)input[byteOff++];
+                        savedBytes[1] = input[byteOff++];
                     } else {
                         savedSize = 3;
-                        savedBytes[1] = (byte)input[byteOff++];
-                        savedBytes[2] = (byte)input[byteOff++];
+                        savedBytes[1] = input[byteOff++];
+                        savedBytes[2] = input[byteOff++];
                     }
                     break;
                 }
@@ -154,10 +154,10 @@
                     throw new MalformedInputException();
                 }
                 // this byte sequence is UTF16 character
-                int ucs4 = (int)(0x07 & byte1) << 18 |
-                           (int)(0x3f & byte2) << 12 |
-                           (int)(0x3f & byte3) <<  6 |
-                           (int)(0x3f & byte4);
+                int ucs4 = (0x07 & byte1) << 18 |
+                           (0x3f & byte2) << 12 |
+                           (0x3f & byte3) <<  6 |
+                           (0x3f & byte4);
                 outputChar[0] = (char)((ucs4 - 0x10000) / 0x400 + 0xd800);
                 outputChar[1] = (char)((ucs4 - 0x10000) % 0x400 + 0xdc00);
                 outputSize = 2;
--- a/src/share/classes/sun/io/CharToByteUnicode.java	Wed Jan 27 19:39:55 2010 -0800
+++ b/src/share/classes/sun/io/CharToByteUnicode.java	Tue Feb 02 10:55:07 2010 +0000
@@ -46,7 +46,7 @@
     protected int byteOrder = UNKNOWN;
 
     public CharToByteUnicode() {
-        String enc = (String) java.security.AccessController.doPrivileged(
+        String enc = java.security.AccessController.doPrivileged(
            new sun.security.action.GetPropertyAction("sun.io.unicode.encoding",
                                                           "UnicodeBig"));
         if (enc.equals("UnicodeBig"))
--- a/src/share/classes/sun/io/CharacterEncoding.java	Wed Jan 27 19:39:55 2010 -0800
+++ b/src/share/classes/sun/io/CharacterEncoding.java	Tue Feb 02 10:55:07 2010 +0000
@@ -50,11 +50,11 @@
 
     private static boolean sjisIsMS932;
 
-    private static Map aliasTable;
+    private static Map<String,String> aliasTable;
     private static volatile boolean installedAll;
 
     static {
-        aliasTable = new HashMap(460, 1.0f);                    /* MDA */
+        aliasTable = new HashMap<>(460, 1.0f);                    /* MDA */
 
         aliasTable.put("us-ascii",              "ASCII");
         aliasTable.put("ascii",                 "ASCII");
@@ -119,11 +119,11 @@
         }
         // need to use Locale.US so we can load ISO converters in tr_TR locale
         String lower = name.toLowerCase(Locale.US);
-        String val = (String) aliasTable.get(lower);
+        String val = aliasTable.get(lower);
 
         if (val == null && !installedAll) {
             installAll();
-            val = (String) aliasTable.get(lower);
+            val = aliasTable.get(lower);
         }
         return val;
     }
@@ -131,7 +131,7 @@
     private static synchronized void installAll() {
         if (!installedAll) {
             GetPropertyAction a = new GetPropertyAction("sun.nio.cs.map");
-            String map = ((String)AccessController.doPrivileged(a));
+            String map = AccessController.doPrivileged(a);
             if (map != null) {
                 sjisIsMS932 = map.equalsIgnoreCase("Windows-31J/Shift_JIS");
             } else {
@@ -857,9 +857,9 @@
      * Auto Detect converter.
      */
     static String getSJISName() {
-        String encodeName = (String) AccessController.doPrivileged(
-                                                new PrivilegedAction() {
-            public Object run() {
+        String encodeName = AccessController.doPrivileged(
+                                               new PrivilegedAction<String>() {
+            public String run() {
                 String osName = System.getProperty("os.name");
                 if (osName.equals("Solaris") || osName.equals("SunOS")){
                     return "PCK";
@@ -880,9 +880,9 @@
 
 
     static String getEUCJPName() {
-      String encodeName = (String) AccessController.doPrivileged(
-                                              new PrivilegedAction() {
-          public Object run() {
+      String encodeName = AccessController.doPrivileged(
+                                              new PrivilegedAction<String>() {
+          public String run() {
               String osName = System.getProperty("os.name");
               if (osName.equals("Solaris") || osName.equals("SunOS"))
                   return "eucJP-open";
--- a/src/share/classes/sun/io/Converters.java	Wed Jan 27 19:39:55 2010 -0800
+++ b/src/share/classes/sun/io/Converters.java	Tue Feb 02 10:55:07 2010 +0000
@@ -85,10 +85,11 @@
      * this code can be involved in the startup sequence it's important to keep
      * the footprint down.
      */
-    private static SoftReference[][] classCache
-        = new SoftReference[][] {
-            new SoftReference[CACHE_SIZE],
-            new SoftReference[CACHE_SIZE]
+    @SuppressWarnings("unchecked")
+    private static SoftReference<Object[]>[][] classCache
+        = (SoftReference<Object[]>[][]) new SoftReference<?>[][] {
+            new SoftReference<?>[CACHE_SIZE],
+            new SoftReference<?>[CACHE_SIZE]
         };
 
     private static void moveToFront(Object[] oa, int i) {
@@ -98,28 +99,28 @@
         oa[0] = ob;
     }
 
-    private static Class cache(int type, Object encoding) {
-        SoftReference[] srs = classCache[type];
+    private static Class<?> cache(int type, Object encoding) {
+        SoftReference<Object[]>[] srs = classCache[type];
         for (int i = 0; i < CACHE_SIZE; i++) {
-            SoftReference sr = srs[i];
+            SoftReference<Object[]> sr = srs[i];
             if (sr == null)
                 continue;
-            Object[] oa = (Object[])sr.get();
+            Object[] oa = sr.get();
             if (oa == null) {
                 srs[i] = null;
                 continue;
             }
             if (oa[1].equals(encoding)) {
                 moveToFront(srs, i);
-                return (Class)oa[0];
+                return (Class<?>)oa[0];
             }
         }
         return null;
     }
 
-    private static Class cache(int type, Object encoding, Class c) {
-        SoftReference[] srs = classCache[type];
-        srs[CACHE_SIZE - 1] = new SoftReference(new Object[] { c, encoding });
+    private static Class<?> cache(int type, Object encoding, Class<?> c) {
+        SoftReference<Object[]>[] srs = classCache[type];
+        srs[CACHE_SIZE - 1] = new SoftReference<Object[]>(new Object[] { c, encoding });
         moveToFront(srs, CACHE_SIZE - 1);
         return c;
     }
@@ -129,12 +130,12 @@
      */
     public static boolean isCached(int type, String encoding) {
         synchronized (lock) {
-            SoftReference[] srs = classCache[type];
+            SoftReference<Object[]>[] srs = classCache[type];
             for (int i = 0; i < CACHE_SIZE; i++) {
-                SoftReference sr = srs[i];
+                SoftReference<Object[]> sr = srs[i];
                 if (sr == null)
                     continue;
-                Object[] oa = (Object[])sr.get();
+                Object[] oa = sr.get();
                 if (oa == null) {
                     srs[i] = null;
                     continue;
@@ -152,9 +153,9 @@
     private static String getConverterPackageName() {
         String cp = converterPackageName;
         if (cp != null) return cp;
-        java.security.PrivilegedAction pa =
+        java.security.PrivilegedAction<String> pa =
             new sun.security.action.GetPropertyAction("file.encoding.pkg");
-        cp = (String)java.security.AccessController.doPrivileged(pa);
+        cp = java.security.AccessController.doPrivileged(pa);
         if (cp != null) {
             /* Property is set, so take it as the true converter package */
             converterPackageName = cp;
@@ -168,9 +169,9 @@
     public static String getDefaultEncodingName() {
         synchronized (lock) {
             if (defaultEncoding == null) {
-                java.security.PrivilegedAction pa =
+                java.security.PrivilegedAction<String> pa =
                     new sun.security.action.GetPropertyAction("file.encoding");
-                defaultEncoding = (String)java.security.AccessController.doPrivileged(pa);
+                defaultEncoding = java.security.AccessController.doPrivileged(pa);
             }
         }
         return defaultEncoding;
@@ -194,7 +195,7 @@
      * encoding, or throw an UnsupportedEncodingException if no such class can
      * be found
      */
-    private static Class getConverterClass(int type, String encoding)
+    private static Class<?> getConverterClass(int type, String encoding)
         throws UnsupportedEncodingException
     {
         String enc = null;
@@ -241,7 +242,7 @@
      * Instantiate the given converter class, or throw an
      * UnsupportedEncodingException if it cannot be instantiated
      */
-    private static Object newConverter(String enc, Class c)
+    private static Object newConverter(String enc, Class<?> c)
         throws UnsupportedEncodingException
     {
         try {
@@ -261,7 +262,7 @@
     static Object newConverter(int type, String enc)
         throws UnsupportedEncodingException
     {
-        Class c;
+        Class<?> c;
         synchronized (lock) {
             c = cache(type, enc);
             if (c == null) {
@@ -279,9 +280,9 @@
      * not yet defined, return a class that implements the fallback default
      * encoding, which is just ISO 8859-1.
      */
-    private static Class getDefaultConverterClass(int type) {
+    private static Class<?> getDefaultConverterClass(int type) {
         boolean fillCache = false;
-        Class c;
+        Class<?> c;
 
         /* First check the class cache */
         c = cache(type, DEFAULT_NAME);
@@ -325,7 +326,7 @@
      * encoding cannot be determined.
      */
     static Object newDefaultConverter(int type) {
-        Class c;
+        Class<?> c;
         synchronized (lock) {
             c = getDefaultConverterClass(type);
         }
--- a/src/share/classes/sun/nio/cs/AbstractCharsetProvider.java	Wed Jan 27 19:39:55 2010 -0800
+++ b/src/share/classes/sun/nio/cs/AbstractCharsetProvider.java	Tue Feb 02 10:55:07 2010 +0000
@@ -48,23 +48,23 @@
 
     /* Maps canonical names to class names
      */
-    private Map classMap
-        = new TreeMap(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
+    private Map<String,String> classMap
+        = new TreeMap<>(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
 
     /* Maps alias names to canonical names
      */
-    private Map aliasMap
-        = new TreeMap(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
+    private Map<String,String> aliasMap
+        = new TreeMap<>(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
 
     /* Maps canonical names to alias-name arrays
      */
-    private Map aliasNameMap
-        = new TreeMap(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
+    private Map<String,String[]> aliasNameMap
+        = new TreeMap<>(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
 
     /* Maps canonical names to soft references that hold cached instances
      */
-    private Map cache
-        = new TreeMap(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
+    private Map<String,SoftReference<Charset>> cache
+        = new TreeMap<>(ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
 
     private String packagePrefix;
 
@@ -79,13 +79,13 @@
     /* Add an entry to the given map, but only if no mapping yet exists
      * for the given name.
      */
-    private static void put(Map m, String name, Object value) {
+    private static <K,V> void put(Map<K,V> m, K name, V value) {
         if (!m.containsKey(name))
             m.put(name, value);
     }
 
-    private static void remove(Map m, String name) {
-        Object x  = m.remove(name);
+    private static <K,V> void remove(Map<K,V> m, K name) {
+        V x  = m.remove(name);
         assert (x != null);
     }
 
@@ -116,22 +116,22 @@
     protected void init() { }
 
     private String canonicalize(String charsetName) {
-        String acn = (String)aliasMap.get(charsetName);
+        String acn = aliasMap.get(charsetName);
         return (acn != null) ? acn : charsetName;
     }
 
     private Charset lookup(String csn) {
 
         // Check cache first
-        SoftReference sr = (SoftReference)cache.get(csn);
+        SoftReference<Charset> sr = cache.get(csn);
         if (sr != null) {
-            Charset cs = (Charset)sr.get();
+            Charset cs = sr.get();
             if (cs != null)
                 return cs;
         }
 
         // Do we even support this charset?
-        String cln = (String)classMap.get(csn);
+        String cln = classMap.get(csn);
 
         if (cln == null)
             return null;
@@ -139,12 +139,12 @@
         // Instantiate the charset and cache it
         try {
 
-            Class c = Class.forName(packagePrefix + "." + cln,
-                                    true,
-                                    this.getClass().getClassLoader());
+            Class<?> c = Class.forName(packagePrefix + "." + cln,
+                                       true,
+                                       this.getClass().getClassLoader());
 
             Charset cs = (Charset)c.newInstance();
-            cache.put(csn, new SoftReference(cs));
+            cache.put(csn, new SoftReference<Charset>(cs));
             return cs;
         } catch (ClassNotFoundException x) {
             return null;
@@ -164,21 +164,21 @@
 
     public final Iterator<Charset> charsets() {
 
-        final ArrayList ks;
+        final ArrayList<String> ks;
         synchronized (this) {
             init();
-            ks = new ArrayList(classMap.keySet());
+            ks = new ArrayList<>(classMap.keySet());
         }
 
         return new Iterator<Charset>() {
-                Iterator i = ks.iterator();
+                Iterator<String> i = ks.iterator();
 
                 public boolean hasNext() {
                     return i.hasNext();
                 }
 
                 public Charset next() {
-                    String csn = (String)i.next();
+                    String csn = i.next();
                     return lookup(csn);
                 }
 
@@ -191,7 +191,7 @@
     public final String[] aliases(String charsetName) {
         synchronized (this) {
             init();
-            return (String[])aliasNameMap.get(charsetName);
+            return aliasNameMap.get(charsetName);
         }
     }