7117612: Miscellaneous warnings in java.lang
authoromajid
Thu, 08 Dec 2011 13:48:54 -0500
changeset 11275 7cb0861d512f
parent 11274 7e7196757acd
child 11276 6a7de6dddc18
7117612: Miscellaneous warnings in java.lang Reviewed-by: smarks, dholmes, alanb, darcy
jdk/src/share/classes/java/lang/Boolean.java
jdk/src/share/classes/java/lang/Byte.java
jdk/src/share/classes/java/lang/Character.java
jdk/src/share/classes/java/lang/CharacterName.java
jdk/src/share/classes/java/lang/Class.java
jdk/src/share/classes/java/lang/ClassLoader.java
jdk/src/share/classes/java/lang/ConditionalSpecialCasing.java
jdk/src/share/classes/java/lang/Double.java
jdk/src/share/classes/java/lang/EnumConstantNotPresentException.java
jdk/src/share/classes/java/lang/Float.java
jdk/src/share/classes/java/lang/Integer.java
jdk/src/share/classes/java/lang/Long.java
jdk/src/share/classes/java/lang/Short.java
jdk/src/share/classes/java/lang/System.java
jdk/src/share/classes/java/lang/ThreadLocal.java
jdk/src/share/classes/java/lang/Void.java
jdk/src/solaris/classes/java/lang/ProcessEnvironment.java
jdk/src/windows/classes/java/lang/ProcessEnvironment.java
--- a/jdk/src/share/classes/java/lang/Boolean.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/Boolean.java	Thu Dec 08 13:48:54 2011 -0500
@@ -60,7 +60,8 @@
      *
      * @since   JDK1.1
      */
-    public static final Class<Boolean> TYPE = Class.getPrimitiveClass("boolean");
+    @SuppressWarnings("unchecked")
+    public static final Class<Boolean> TYPE = (Class<Boolean>) Class.getPrimitiveClass("boolean");
 
     /**
      * The value of the Boolean.
--- a/jdk/src/share/classes/java/lang/Byte.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/Byte.java	Thu Dec 08 13:48:54 2011 -0500
@@ -59,6 +59,7 @@
      * The {@code Class} instance representing the primitive type
      * {@code byte}.
      */
+    @SuppressWarnings("unchecked")
     public static final Class<Byte>     TYPE = (Class<Byte>) Class.getPrimitiveClass("byte");
 
     /**
--- a/jdk/src/share/classes/java/lang/Character.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/Character.java	Thu Dec 08 13:48:54 2011 -0500
@@ -172,7 +172,7 @@
      * @since   1.1
      */
     @SuppressWarnings("unchecked")
-    public static final Class<Character> TYPE = Class.getPrimitiveClass("char");
+    public static final Class<Character> TYPE = (Class<Character>) Class.getPrimitiveClass("char");
 
     /*
      * Normative general types
--- a/jdk/src/share/classes/java/lang/CharacterName.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/CharacterName.java	Thu Dec 08 13:48:54 2011 -0500
@@ -101,6 +101,8 @@
         if (lookup[cp>>8] == null ||
             (off = lookup[cp>>8][cp&0xff]) == 0)
             return null;
-        return new String(strPool, 0, off >>> 8, off & 0xff);  // ASCII
+        @SuppressWarnings("deprecation")
+        String result = new String(strPool, 0, off >>> 8, off & 0xff);  // ASCII
+        return result;
     }
 }
--- a/jdk/src/share/classes/java/lang/Class.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/Class.java	Thu Dec 08 13:48:54 2011 -0500
@@ -631,6 +631,7 @@
      *     <cite>The Java&trade; Virtual Machine Specification</cite>
      * @since 1.5
      */
+    @SuppressWarnings("unchecked")
     public TypeVariable<Class<T>>[] getTypeParameters() {
         if (getGenericSignature() != null)
             return (TypeVariable<Class<T>>[])getGenericInfo().getTypeParameters();
@@ -1303,7 +1304,7 @@
 
         return java.security.AccessController.doPrivileged(
             new java.security.PrivilegedAction<Class<?>[]>() {
-                public Class[] run() {
+                public Class<?>[] run() {
                     List<Class<?>> list = new ArrayList<>();
                     Class<?> currentClass = Class.this;
                     while (currentClass != null) {
@@ -1315,7 +1316,7 @@
                         }
                         currentClass = currentClass.getSuperclass();
                     }
-                    return list.toArray(new Class[0]);
+                    return list.toArray(new Class<?>[0]);
                 }
             });
     }
@@ -2150,7 +2151,7 @@
      * Return the Virtual Machine's Class object for the named
      * primitive type.
      */
-    static native Class getPrimitiveClass(String name);
+    static native Class<?> getPrimitiveClass(String name);
 
 
     /*
@@ -2395,7 +2396,9 @@
         }
         // No cached value available; request value from VM
         if (isInterface()) {
-            res = new Constructor[0];
+            @SuppressWarnings("unchecked")
+            Constructor<T>[] temporaryRes = (Constructor<T>[]) new Constructor<?>[0];
+            res = temporaryRes;
         } else {
             res = getDeclaredConstructors0(publicOnly);
         }
@@ -2951,7 +2954,9 @@
                                 return null;
                             }
                         });
-                enumConstants = (T[])values.invoke(null);
+                @SuppressWarnings("unchecked")
+                T[] temporaryConstants = (T[])values.invoke(null);
+                enumConstants = temporaryConstants;
             }
             // These can happen when users concoct enum-like classes
             // that don't comply with the enum spec.
@@ -2996,6 +3001,7 @@
      *
      * @since 1.5
      */
+    @SuppressWarnings("unchecked")
     public T cast(Object obj) {
         if (obj != null && !isInstance(obj))
             throw new ClassCastException(cannotCastMsg(obj));
@@ -3026,6 +3032,7 @@
      *    the class itself).
      * @since 1.5
      */
+    @SuppressWarnings("unchecked")
     public <U> Class<? extends U> asSubclass(Class<U> clazz) {
         if (clazz.isAssignableFrom(this))
             return (Class<? extends U>) this;
@@ -3037,6 +3044,7 @@
      * @throws NullPointerException {@inheritDoc}
      * @since 1.5
      */
+    @SuppressWarnings("unchecked")
     public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
         if (annotationClass == null)
             throw new NullPointerException();
--- a/jdk/src/share/classes/java/lang/ClassLoader.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/ClassLoader.java	Thu Dec 08 13:48:54 2011 -0500
@@ -1167,7 +1167,8 @@
      * @since  1.2
      */
     public Enumeration<URL> getResources(String name) throws IOException {
-        Enumeration[] tmp = new Enumeration[2];
+        @SuppressWarnings("unchecked")
+        Enumeration<URL>[] tmp = (Enumeration<URL>[]) new Enumeration<?>[2];
         if (parent != null) {
             tmp[0] = parent.getResources(name);
         } else {
--- a/jdk/src/share/classes/java/lang/ConditionalSpecialCasing.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/ConditionalSpecialCasing.java	Thu Dec 08 13:48:54 2011 -0500
@@ -92,15 +92,15 @@
     };
 
     // A hash table that contains the above entries
-    static Hashtable entryTable = new Hashtable();
+    static Hashtable<Integer, HashSet<Entry>> entryTable = new Hashtable<>();
     static {
         // create hashtable from the entry
         for (int i = 0; i < entry.length; i ++) {
             Entry cur = entry[i];
             Integer cp = new Integer(cur.getCodePoint());
-            HashSet set = (HashSet)entryTable.get(cp);
+            HashSet<Entry> set = entryTable.get(cp);
             if (set == null) {
-                set = new HashSet();
+                set = new HashSet<Entry>();
             }
             set.add(cur);
             entryTable.put(cp, set);
@@ -151,13 +151,13 @@
     }
 
     private static char[] lookUpTable(String src, int index, Locale locale, boolean bLowerCasing) {
-        HashSet set = (HashSet)entryTable.get(new Integer(src.codePointAt(index)));
+        HashSet<Entry> set = entryTable.get(new Integer(src.codePointAt(index)));
 
         if (set != null) {
-            Iterator iter = set.iterator();
+            Iterator<Entry> iter = set.iterator();
             String currentLang = locale.getLanguage();
             while (iter.hasNext()) {
-                Entry entry = (Entry)iter.next();
+                Entry entry = iter.next();
                 String conditionLang= entry.getLanguage();
                 if (((conditionLang == null) || (conditionLang.equals(currentLang))) &&
                         isConditionMet(src, index, locale, entry.getCondition())) {
--- a/jdk/src/share/classes/java/lang/Double.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/Double.java	Thu Dec 08 13:48:54 2011 -0500
@@ -128,6 +128,7 @@
      *
      * @since JDK1.1
      */
+    @SuppressWarnings("unchecked")
     public static final Class<Double>   TYPE = (Class<Double>) Class.getPrimitiveClass("double");
 
     /**
@@ -715,7 +716,7 @@
      * @return the {@code double} value represented by this object
      */
     public double doubleValue() {
-        return (double)value;
+        return value;
     }
 
     /**
--- a/jdk/src/share/classes/java/lang/EnumConstantNotPresentException.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/EnumConstantNotPresentException.java	Thu Dec 08 13:48:54 2011 -0500
@@ -36,6 +36,7 @@
  * @see     java.lang.reflect.AnnotatedElement
  * @since   1.5
  */
+@SuppressWarnings("rawtypes") /* rawtypes are part of the public api */
 public class EnumConstantNotPresentException extends RuntimeException {
     private static final long serialVersionUID = -6046998521960521108L;
 
--- a/jdk/src/share/classes/java/lang/Float.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/Float.java	Thu Dec 08 13:48:54 2011 -0500
@@ -126,7 +126,8 @@
      *
      * @since JDK1.1
      */
-    public static final Class<Float> TYPE = Class.getPrimitiveClass("float");
+    @SuppressWarnings("unchecked")
+    public static final Class<Float> TYPE = (Class<Float>) Class.getPrimitiveClass("float");
 
     /**
      * Returns a string representation of the {@code float}
--- a/jdk/src/share/classes/java/lang/Integer.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/Integer.java	Thu Dec 08 13:48:54 2011 -0500
@@ -68,6 +68,7 @@
      *
      * @since   JDK1.1
      */
+    @SuppressWarnings("unchecked")
     public static final Class<Integer>  TYPE = (Class<Integer>) Class.getPrimitiveClass("int");
 
     /**
--- a/jdk/src/share/classes/java/lang/Long.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/Long.java	Thu Dec 08 13:48:54 2011 -0500
@@ -66,6 +66,7 @@
      *
      * @since   JDK1.1
      */
+    @SuppressWarnings("unchecked")
     public static final Class<Long>     TYPE = (Class<Long>) Class.getPrimitiveClass("long");
 
     /**
@@ -734,7 +735,7 @@
      * {@code long} value.
      */
     public long longValue() {
-        return (long)value;
+        return value;
     }
 
     /**
--- a/jdk/src/share/classes/java/lang/Short.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/Short.java	Thu Dec 08 13:48:54 2011 -0500
@@ -58,6 +58,7 @@
      * The {@code Class} instance representing the primitive type
      * {@code short}.
      */
+    @SuppressWarnings("unchecked")
     public static final Class<Short>    TYPE = (Class<Short>) Class.getPrimitiveClass("short");
 
     /**
--- a/jdk/src/share/classes/java/lang/System.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/System.java	Thu Dec 08 13:48:54 2011 -0500
@@ -1032,7 +1032,7 @@
      */
     @Deprecated
     public static void runFinalizersOnExit(boolean value) {
-        Runtime.getRuntime().runFinalizersOnExit(value);
+        Runtime.runFinalizersOnExit(value);
     }
 
     /**
--- a/jdk/src/share/classes/java/lang/ThreadLocal.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/ThreadLocal.java	Thu Dec 08 13:48:54 2011 -0500
@@ -144,8 +144,11 @@
         ThreadLocalMap map = getMap(t);
         if (map != null) {
             ThreadLocalMap.Entry e = map.getEntry(this);
-            if (e != null)
-                return (T)e.value;
+            if (e != null) {
+                @SuppressWarnings("unchecked")
+                T result = (T)e.value;
+                return result;
+            }
         }
         return setInitialValue();
     }
@@ -268,11 +271,11 @@
          * entry can be expunged from table.  Such entries are referred to
          * as "stale entries" in the code that follows.
          */
-        static class Entry extends WeakReference<ThreadLocal> {
+        static class Entry extends WeakReference<ThreadLocal<?>> {
             /** The value associated with this ThreadLocal. */
             Object value;
 
-            Entry(ThreadLocal k, Object v) {
+            Entry(ThreadLocal<?> k, Object v) {
                 super(k);
                 value = v;
             }
@@ -325,7 +328,7 @@
          * ThreadLocalMaps are constructed lazily, so we only create
          * one when we have at least one entry to put in it.
          */
-        ThreadLocalMap(ThreadLocal firstKey, Object firstValue) {
+        ThreadLocalMap(ThreadLocal<?> firstKey, Object firstValue) {
             table = new Entry[INITIAL_CAPACITY];
             int i = firstKey.threadLocalHashCode & (INITIAL_CAPACITY - 1);
             table[i] = new Entry(firstKey, firstValue);
@@ -348,7 +351,8 @@
             for (int j = 0; j < len; j++) {
                 Entry e = parentTable[j];
                 if (e != null) {
-                    ThreadLocal key = e.get();
+                    @SuppressWarnings("unchecked")
+                    ThreadLocal<Object> key = (ThreadLocal<Object>) e.get();
                     if (key != null) {
                         Object value = key.childValue(e.value);
                         Entry c = new Entry(key, value);
@@ -372,7 +376,7 @@
          * @param  key the thread local object
          * @return the entry associated with key, or null if no such
          */
-        private Entry getEntry(ThreadLocal key) {
+        private Entry getEntry(ThreadLocal<?> key) {
             int i = key.threadLocalHashCode & (table.length - 1);
             Entry e = table[i];
             if (e != null && e.get() == key)
@@ -390,12 +394,12 @@
          * @param  e the entry at table[i]
          * @return the entry associated with key, or null if no such
          */
-        private Entry getEntryAfterMiss(ThreadLocal key, int i, Entry e) {
+        private Entry getEntryAfterMiss(ThreadLocal<?> key, int i, Entry e) {
             Entry[] tab = table;
             int len = tab.length;
 
             while (e != null) {
-                ThreadLocal k = e.get();
+                ThreadLocal<?> k = e.get();
                 if (k == key)
                     return e;
                 if (k == null)
@@ -413,7 +417,7 @@
          * @param key the thread local object
          * @param value the value to be set
          */
-        private void set(ThreadLocal key, Object value) {
+        private void set(ThreadLocal<?> key, Object value) {
 
             // We don't use a fast path as with get() because it is at
             // least as common to use set() to create new entries as
@@ -427,7 +431,7 @@
             for (Entry e = tab[i];
                  e != null;
                  e = tab[i = nextIndex(i, len)]) {
-                ThreadLocal k = e.get();
+                ThreadLocal<?> k = e.get();
 
                 if (k == key) {
                     e.value = value;
@@ -449,7 +453,7 @@
         /**
          * Remove the entry for key.
          */
-        private void remove(ThreadLocal key) {
+        private void remove(ThreadLocal<?> key) {
             Entry[] tab = table;
             int len = tab.length;
             int i = key.threadLocalHashCode & (len-1);
@@ -479,7 +483,7 @@
          * @param  staleSlot index of the first stale entry encountered while
          *         searching for key.
          */
-        private void replaceStaleEntry(ThreadLocal key, Object value,
+        private void replaceStaleEntry(ThreadLocal<?> key, Object value,
                                        int staleSlot) {
             Entry[] tab = table;
             int len = tab.length;
@@ -501,7 +505,7 @@
             for (int i = nextIndex(staleSlot, len);
                  (e = tab[i]) != null;
                  i = nextIndex(i, len)) {
-                ThreadLocal k = e.get();
+                ThreadLocal<?> k = e.get();
 
                 // If we find key, then we need to swap it
                 // with the stale entry to maintain hash table order.
@@ -563,7 +567,7 @@
             for (i = nextIndex(staleSlot, len);
                  (e = tab[i]) != null;
                  i = nextIndex(i, len)) {
-                ThreadLocal k = e.get();
+                ThreadLocal<?> k = e.get();
                 if (k == null) {
                     e.value = null;
                     tab[i] = null;
@@ -650,7 +654,7 @@
             for (int j = 0; j < oldLen; ++j) {
                 Entry e = oldTab[j];
                 if (e != null) {
-                    ThreadLocal k = e.get();
+                    ThreadLocal<?> k = e.get();
                     if (k == null) {
                         e.value = null; // Help the GC
                     } else {
--- a/jdk/src/share/classes/java/lang/Void.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/share/classes/java/lang/Void.java	Thu Dec 08 13:48:54 2011 -0500
@@ -40,7 +40,8 @@
      * The {@code Class} object representing the pseudo-type corresponding to
      * the keyword {@code void}.
      */
-    public static final Class<Void> TYPE = Class.getPrimitiveClass("void");
+    @SuppressWarnings("unchecked")
+    public static final Class<Void> TYPE = (Class<Void>) Class.getPrimitiveClass("void");
 
     /*
      * The Void class cannot be instantiated.
--- a/jdk/src/solaris/classes/java/lang/ProcessEnvironment.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/solaris/classes/java/lang/ProcessEnvironment.java	Thu Dec 08 13:48:54 2011 -0500
@@ -91,6 +91,7 @@
     }
 
     /* Only for use by ProcessBuilder.environment() */
+    @SuppressWarnings("unchecked")
     static Map<String,String> environment() {
         return new StringEnvironment
             ((Map<Variable,Value>)(theEnvironment.clone()));
--- a/jdk/src/windows/classes/java/lang/ProcessEnvironment.java	Wed Dec 07 12:12:50 2011 -0800
+++ b/jdk/src/windows/classes/java/lang/ProcessEnvironment.java	Thu Dec 08 13:48:54 2011 -0500
@@ -68,6 +68,9 @@
 
 final class ProcessEnvironment extends HashMap<String,String>
 {
+
+    private static final long serialVersionUID = -8017839552603542824L;
+
     private static String validateName(String name) {
         // An initial `=' indicates a magic Windows variable name -- OK
         if (name.indexOf('=', 1)   != -1 ||
@@ -144,6 +147,7 @@
             };
         }
         private static Map.Entry<String,String> checkedEntry(Object o) {
+            @SuppressWarnings("unchecked")
             Map.Entry<String,String> e = (Map.Entry<String,String>) o;
             nonNullString(e.getKey());
             nonNullString(e.getValue());
@@ -281,6 +285,7 @@
     }
 
     // Only for use by ProcessBuilder.environment()
+    @SuppressWarnings("unchecked")
     static Map<String,String> environment() {
         return (Map<String,String>) theEnvironment.clone();
     }