7116857: Warnings in javax.security and some sun.misc
authorweijun
Mon, 05 Dec 2011 10:19:13 +0800
changeset 11131 27747ee5a62a
parent 11130 c7093e306a34
child 11133 e05aee7c8611
7116857: Warnings in javax.security and some sun.misc Reviewed-by: smarks
jdk/src/share/classes/javax/security/auth/kerberos/ServicePermission.java
jdk/src/share/classes/sun/misc/CEFormatException.java
jdk/src/share/classes/sun/misc/CEStreamExhausted.java
jdk/src/share/classes/sun/misc/ClassLoaderUtil.java
jdk/src/share/classes/sun/misc/CompoundEnumeration.java
jdk/src/share/classes/sun/misc/ExtensionInstallationException.java
jdk/src/share/classes/sun/misc/FloatingDecimal.java
jdk/src/share/classes/sun/misc/FormattedFloatingDecimal.java
jdk/src/share/classes/sun/misc/InvalidJarIndexException.java
jdk/src/share/classes/sun/misc/LRUCache.java
jdk/src/share/classes/sun/misc/Queue.java
jdk/src/share/classes/sun/misc/RequestProcessor.java
jdk/src/share/classes/sun/misc/ServiceConfigurationError.java
jdk/src/share/classes/sun/misc/URLClassPath.java
--- a/jdk/src/share/classes/javax/security/auth/kerberos/ServicePermission.java	Sat Dec 03 10:58:19 2011 +0900
+++ b/jdk/src/share/classes/javax/security/auth/kerberos/ServicePermission.java	Mon Dec 05 10:19:13 2011 +0800
@@ -369,7 +369,7 @@
                 switch(a[i-matchlen]) {
                 case ',':
                     seencomma = true;
-                    /*FALLTHROUGH*/
+                    break;
                 case ' ': case '\r': case '\n':
                 case '\f': case '\t':
                     break;
--- a/jdk/src/share/classes/sun/misc/CEFormatException.java	Sat Dec 03 10:58:19 2011 +0900
+++ b/jdk/src/share/classes/sun/misc/CEFormatException.java	Mon Dec 05 10:19:13 2011 +0800
@@ -28,7 +28,9 @@
 import java.io.IOException;
 
 public class CEFormatException extends IOException {
-        public CEFormatException(String s) {
-                super(s);
-        }
+    static final long serialVersionUID = -7139121221067081482L;
+    public CEFormatException(String s) {
+        super(s);
+    }
 }
+
--- a/jdk/src/share/classes/sun/misc/CEStreamExhausted.java	Sat Dec 03 10:58:19 2011 +0900
+++ b/jdk/src/share/classes/sun/misc/CEStreamExhausted.java	Mon Dec 05 10:19:13 2011 +0800
@@ -27,4 +27,7 @@
 import java.io.IOException;
 
 /** This exception is thrown when EOF is reached */
-public class CEStreamExhausted extends IOException { };
+public class CEStreamExhausted extends IOException {
+    static final long serialVersionUID = -5889118049525891904L;
+}
+
--- a/jdk/src/share/classes/sun/misc/ClassLoaderUtil.java	Sat Dec 03 10:58:19 2011 +0900
+++ b/jdk/src/share/classes/sun/misc/ClassLoaderUtil.java	Mon Dec 05 10:19:13 2011 +0800
@@ -79,9 +79,9 @@
 
             URLClassPath ucp = SharedSecrets.getJavaNetAccess()
                                                 .getURLClassPath(classLoader);
-            ArrayList loaders = ucp.loaders;
-            Stack urls = ucp.urls;
-            HashMap lmap = ucp.lmap;
+            ArrayList<?> loaders = ucp.loaders;
+            Stack<?> urls = ucp.urls;
+            HashMap<?,?> lmap = ucp.lmap;
 
             /*
              *The urls variable in the URLClassPath object holds URLs that have not yet
--- a/jdk/src/share/classes/sun/misc/CompoundEnumeration.java	Sat Dec 03 10:58:19 2011 +0900
+++ b/jdk/src/share/classes/sun/misc/CompoundEnumeration.java	Mon Dec 05 10:19:13 2011 +0800
@@ -33,10 +33,10 @@
  * enumerations.
  */
 public class CompoundEnumeration<E> implements Enumeration<E> {
-    private Enumeration[] enums;
+    private Enumeration<E>[] enums;
     private int index = 0;
 
-    public CompoundEnumeration(Enumeration[] enums) {
+    public CompoundEnumeration(Enumeration<E>[] enums) {
         this.enums = enums;
     }
 
@@ -58,6 +58,6 @@
         if (!next()) {
             throw new NoSuchElementException();
         }
-        return (E)enums[index].nextElement();
+        return enums[index].nextElement();
     }
 }
--- a/jdk/src/share/classes/sun/misc/ExtensionInstallationException.java	Sat Dec 03 10:58:19 2011 +0900
+++ b/jdk/src/share/classes/sun/misc/ExtensionInstallationException.java	Mon Dec 05 10:19:13 2011 +0800
@@ -34,6 +34,8 @@
 
 public class ExtensionInstallationException extends Exception {
 
+    static final long serialVersionUID = 3139688306909345924L;
+
     /*
      * <p>
      * Construct a new exception with an exception reason
--- a/jdk/src/share/classes/sun/misc/FloatingDecimal.java	Sat Dec 03 10:58:19 2011 +0900
+++ b/jdk/src/share/classes/sun/misc/FloatingDecimal.java	Mon Dec 05 10:19:13 2011 +0800
@@ -325,7 +325,7 @@
             // can do int arithmetic rather than long!
             int  ivalue = (int)lvalue;
             ndigits = 10;
-            digits = (char[])(perThreadBuffer.get());
+            digits = perThreadBuffer.get();
             digitno = ndigits-1;
             c = ivalue%10;
             ivalue /= 10;
@@ -345,7 +345,7 @@
             // same algorithm as above (same bugs, too )
             // but using long arithmetic.
             ndigits = 20;
-            digits = (char[])(perThreadBuffer.get());
+            digits = perThreadBuffer.get();
             digitno = ndigits-1;
             c = (int)(lvalue%10L);
             lvalue /= 10L;
@@ -477,9 +477,9 @@
         }
         // Begin to unpack
         // Discover obvious special cases of NaN and Infinity.
-        binExp = (int)( (fBits&singleExpMask) >> singleExpShift );
+        binExp = (fBits&singleExpMask) >> singleExpShift;
         fractBits = fBits&singleFractMask;
-        if ( binExp == (int)(singleExpMask>>singleExpShift) ) {
+        if ( binExp == (singleExpMask>>singleExpShift) ) {
             isExceptional = true;
             if ( fractBits == 0L ){
                 digits =  infinity;
@@ -900,7 +900,7 @@
     }
 
     public String toJavaFormatString() {
-        char result[] = (char[])(perThreadBuffer.get());
+        char result[] = perThreadBuffer.get();
         int i = getChars(result);
         return new String(result, 0, i);
     }
@@ -978,14 +978,14 @@
     }
 
     // Per-thread buffer for string/stringbuffer conversion
-    private static ThreadLocal perThreadBuffer = new ThreadLocal() {
-            protected synchronized Object initialValue() {
+    private static ThreadLocal<char[]> perThreadBuffer = new ThreadLocal<char[]>() {
+            protected synchronized char[] initialValue() {
                 return new char[26];
             }
         };
 
     public void appendTo(Appendable buf) {
-          char result[] = (char[])(perThreadBuffer.get());
+          char result[] = perThreadBuffer.get();
           int i = getChars(result);
         if (buf instanceof StringBuilder)
             ((StringBuilder) buf).append(result, 0, i);
@@ -995,6 +995,7 @@
             assert false;
     }
 
+    @SuppressWarnings("fallthrough")
     public static FloatingDecimal
     readJavaFormatString( String in ) throws NumberFormatException {
         boolean isNegative = false;
@@ -2209,7 +2210,7 @@
                     // exponent correctly, even in the case of
                     // Double.MAX_VALUE overflowing to infinity.
 
-                    significand = (( ((long)exponent +
+                    significand = (( (exponent +
                                      (long)DoubleConsts.EXP_BIAS) <<
                                      (DoubleConsts.SIGNIFICAND_WIDTH-1))
                                    & DoubleConsts.EXP_BIT_MASK) |
--- a/jdk/src/share/classes/sun/misc/FormattedFloatingDecimal.java	Sat Dec 03 10:58:19 2011 +0900
+++ b/jdk/src/share/classes/sun/misc/FormattedFloatingDecimal.java	Mon Dec 05 10:19:13 2011 +0800
@@ -333,7 +333,7 @@
             // can do int arithmetic rather than long!
             int  ivalue = (int)lvalue;
             ndigits = 10;
-            digits = (char[])(perThreadBuffer.get());
+            digits = perThreadBuffer.get();
             digitno = ndigits-1;
             c = ivalue%10;
             ivalue /= 10;
@@ -353,7 +353,7 @@
             // same algorithm as above (same bugs, too )
             // but using long arithmetic.
             ndigits = 20;
-            digits = (char[])(perThreadBuffer.get());
+            digits = perThreadBuffer.get();
             digitno = ndigits-1;
             c = (int)(lvalue%10L);
             lvalue /= 10L;
@@ -554,9 +554,9 @@
         }
         // Begin to unpack
         // Discover obvious special cases of NaN and Infinity.
-        binExp = (int)( (fBits&singleExpMask) >> singleExpShift );
+        binExp = (fBits&singleExpMask) >> singleExpShift;
         fractBits = fBits&singleFractMask;
-        if ( binExp == (int)(singleExpMask>>singleExpShift) ) {
+        if ( binExp == (singleExpMask>>singleExpShift) ) {
             isExceptional = true;
             if ( fractBits == 0L ){
                 digits =  infinity;
@@ -1140,8 +1140,8 @@
     }
 
     // Per-thread buffer for string/stringbuffer conversion
-    private static ThreadLocal perThreadBuffer = new ThreadLocal() {
-            protected synchronized Object initialValue() {
+    private static ThreadLocal<char[]> perThreadBuffer = new ThreadLocal<char[]>() {
+            protected synchronized char[] initialValue() {
                 return new char[26];
             }
         };
--- a/jdk/src/share/classes/sun/misc/InvalidJarIndexException.java	Sat Dec 03 10:58:19 2011 +0900
+++ b/jdk/src/share/classes/sun/misc/InvalidJarIndexException.java	Mon Dec 05 10:19:13 2011 +0800
@@ -38,6 +38,8 @@
 public
 class InvalidJarIndexException extends RuntimeException {
 
+    static final long serialVersionUID = -6159797516569680148L;
+
     /**
      * Constructs an <code>InvalidJarIndexException</code> with no
      * detail message.
--- a/jdk/src/share/classes/sun/misc/LRUCache.java	Sat Dec 03 10:58:19 2011 +0900
+++ b/jdk/src/share/classes/sun/misc/LRUCache.java	Mon Dec 05 10:19:13 2011 +0800
@@ -52,7 +52,9 @@
 
     public V forName(N name) {
         if (oa == null) {
-            oa = (V[])new Object[size];
+            @SuppressWarnings("unchecked")
+            V[] temp = (V[])new Object[size];
+            oa = temp;
         } else {
             for (int i = 0; i < oa.length; i++) {
                 V ob = oa[i];
--- a/jdk/src/share/classes/sun/misc/Queue.java	Sat Dec 03 10:58:19 2011 +0900
+++ b/jdk/src/share/classes/sun/misc/Queue.java	Mon Dec 05 10:19:13 2011 +0800
@@ -35,12 +35,12 @@
  * @author Herb Jellinek
  */
 
-public class Queue {
+public class Queue<T> {
 
     int length = 0;
 
-    QueueElement head = null;
-    QueueElement tail = null;
+    QueueElement<T> head = null;
+    QueueElement<T> tail = null;
 
     public Queue() {
     }
@@ -48,9 +48,9 @@
     /**
      * Enqueue an object.
      */
-    public synchronized void enqueue(Object obj) {
+    public synchronized void enqueue(T obj) {
 
-        QueueElement newElt = new QueueElement(obj);
+        QueueElement<T> newElt = new QueueElement<>(obj);
 
         if (head == null) {
             head = newElt;
@@ -72,7 +72,7 @@
      * @exception java.lang.InterruptedException if any thread has
      *              interrupted this thread.
      */
-    public Object dequeue() throws InterruptedException {
+    public T dequeue() throws InterruptedException {
         return dequeue(0L);
     }
 
@@ -85,13 +85,13 @@
      * @exception java.lang.InterruptedException if any thread has
      *              interrupted this thread.
      */
-    public synchronized Object dequeue(long timeOut)
+    public synchronized T dequeue(long timeOut)
         throws InterruptedException {
 
         while (tail == null) {
             wait(timeOut);
         }
-        QueueElement elt = tail;
+        QueueElement<T> elt = tail;
         tail = elt.prev;
         if (tail == null) {
             head = null;
@@ -115,8 +115,8 @@
      * order. Use the Enumeration methods on the returned object to
      * fetch the elements sequentially.
      */
-    public final synchronized Enumeration elements() {
-        return new LIFOQueueEnumerator(this);
+    public final synchronized Enumeration<T> elements() {
+        return new LIFOQueueEnumerator<>(this);
     }
 
     /**
@@ -124,8 +124,8 @@
      * order. Use the Enumeration methods on the returned object to
      * fetch the elements sequentially.
      */
-    public final synchronized Enumeration reverseElements() {
-        return new FIFOQueueEnumerator(this);
+    public final synchronized Enumeration<T> reverseElements() {
+        return new FIFOQueueEnumerator<>(this);
     }
 
     public synchronized void dump(String msg) {
@@ -133,8 +133,8 @@
         System.err.println("["+length+" elt(s); head = "+
                            (head == null ? "null" : (head.obj)+"")+
                            " tail = "+(tail == null ? "null" : (tail.obj)+""));
-        QueueElement cursor = head;
-        QueueElement last = null;
+        QueueElement<T> cursor = head;
+        QueueElement<T> last = null;
         while (cursor != null) {
             System.err.println("  "+cursor);
             last = cursor;
@@ -147,11 +147,11 @@
     }
 }
 
-final class FIFOQueueEnumerator implements Enumeration {
-    Queue queue;
-    QueueElement cursor;
+final class FIFOQueueEnumerator<T> implements Enumeration<T> {
+    Queue<T> queue;
+    QueueElement<T> cursor;
 
-    FIFOQueueEnumerator(Queue q) {
+    FIFOQueueEnumerator(Queue<T> q) {
         queue = q;
         cursor = q.tail;
     }
@@ -160,10 +160,10 @@
         return (cursor != null);
     }
 
-    public Object nextElement() {
+    public T nextElement() {
         synchronized (queue) {
             if (cursor != null) {
-                QueueElement result = cursor;
+                QueueElement<T> result = cursor;
                 cursor = cursor.prev;
                 return result.obj;
             }
@@ -172,11 +172,11 @@
     }
 }
 
-final class LIFOQueueEnumerator implements Enumeration {
-    Queue queue;
-    QueueElement cursor;
+final class LIFOQueueEnumerator<T> implements Enumeration<T> {
+    Queue<T> queue;
+    QueueElement<T> cursor;
 
-    LIFOQueueEnumerator(Queue q) {
+    LIFOQueueEnumerator(Queue<T> q) {
         queue = q;
         cursor = q.head;
     }
@@ -185,10 +185,10 @@
         return (cursor != null);
     }
 
-    public Object nextElement() {
+    public T nextElement() {
         synchronized (queue) {
             if (cursor != null) {
-                QueueElement result = cursor;
+                QueueElement<T> result = cursor;
                 cursor = cursor.next;
                 return result.obj;
             }
@@ -197,13 +197,13 @@
     }
 }
 
-class QueueElement {
-    QueueElement next = null;
-    QueueElement prev = null;
+class QueueElement<T> {
+    QueueElement<T> next = null;
+    QueueElement<T> prev = null;
 
-    Object obj = null;
+    T obj = null;
 
-    QueueElement(Object obj) {
+    QueueElement(T obj) {
         this.obj = obj;
     }
 
--- a/jdk/src/share/classes/sun/misc/RequestProcessor.java	Sat Dec 03 10:58:19 2011 +0900
+++ b/jdk/src/share/classes/sun/misc/RequestProcessor.java	Mon Dec 05 10:19:13 2011 +0800
@@ -36,7 +36,7 @@
 
 public class RequestProcessor implements Runnable {
 
-    private static Queue requestQueue;
+    private static Queue<Request> requestQueue;
     private static Thread dispatcher;
 
     /**
@@ -55,15 +55,12 @@
         lazyInitialize();
         while (true) {
             try {
-                Object obj = requestQueue.dequeue();
-                if (obj instanceof Request) { // ignore bogons
-                    Request req = (Request)obj;
-                    try {
-                        req.execute();
-                    } catch (Throwable t) {
-                        // do nothing at the moment...maybe report an error
-                        // in the future
-                    }
+                Request req = requestQueue.dequeue();
+                try {
+                    req.execute();
+                } catch (Throwable t) {
+                    // do nothing at the moment...maybe report an error
+                    // in the future
                 }
             } catch (InterruptedException e) {
                 // do nothing at the present time.
@@ -92,7 +89,7 @@
      */
     private static synchronized void lazyInitialize() {
         if (requestQueue == null) {
-            requestQueue = new Queue();
+            requestQueue = new Queue<Request>();
         }
     }
 
--- a/jdk/src/share/classes/sun/misc/ServiceConfigurationError.java	Sat Dec 03 10:58:19 2011 +0900
+++ b/jdk/src/share/classes/sun/misc/ServiceConfigurationError.java	Mon Dec 05 10:19:13 2011 +0800
@@ -43,6 +43,8 @@
 
 public class ServiceConfigurationError extends Error {
 
+    static final long serialVersionUID = 8769866263384244465L;
+
     /**
      * Constructs a new instance with the specified detail string.
      */
--- a/jdk/src/share/classes/sun/misc/URLClassPath.java	Sat Dec 03 10:58:19 2011 +0900
+++ b/jdk/src/share/classes/sun/misc/URLClassPath.java	Mon Dec 05 10:19:13 2011 +0800
@@ -836,10 +836,9 @@
                              Set<String> visited) {
 
             Resource res;
-            Object[] jarFiles;
-            boolean done = false;
+            String[] jarFiles;
             int count = 0;
-            LinkedList jarFilesList = null;
+            LinkedList<String> jarFilesList = null;
 
             /* If there no jar files in the index that can potential contain
              * this resource then return immediately.
@@ -848,11 +847,11 @@
                 return null;
 
             do {
-                jarFiles = jarFilesList.toArray();
                 int size = jarFilesList.size();
+                jarFiles = jarFilesList.toArray(new String[size]);
                 /* loop through the mapped jar file list */
                 while(count < size) {
-                    String jarName = (String)jarFiles[count++];
+                    String jarName = jarFiles[count++];
                     JarLoader newLoader;
                     final URL url;