changeset 438:8bb706922a08

6726309: Compiler warnings in nio code Reviewed-by: sherman, iris
author alanb
date Thu, 24 Jul 2008 12:46:41 +0100
parents 2140be21d6e1
children d01e7cae7b3e
files src/share/classes/java/nio/channels/spi/AbstractSelector.java src/share/classes/java/nio/charset/Charset-X-Coder.java src/share/classes/java/nio/charset/Charset.java src/share/classes/java/nio/charset/CoderResult.java src/share/classes/sun/nio/ch/SelectorImpl.java src/share/classes/sun/nio/ch/Util.java src/share/native/java/nio/Bits.c src/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java src/solaris/classes/sun/nio/ch/EPollSelectorImpl.java src/solaris/native/java/nio/MappedByteBuffer.c src/solaris/native/sun/nio/ch/DatagramChannelImpl.c src/solaris/native/sun/nio/ch/InheritedChannel.c src/solaris/native/sun/nio/ch/Net.c src/solaris/native/sun/nio/ch/ServerSocketChannelImpl.c src/solaris/native/sun/nio/ch/SocketChannelImpl.c src/windows/classes/sun/nio/ch/PipeImpl.java src/windows/classes/sun/nio/ch/WindowsSelectorImpl.java
diffstat 17 files changed, 64 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/nio/channels/spi/AbstractSelector.java	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/share/classes/java/nio/channels/spi/AbstractSelector.java	Thu Jul 24 12:46:41 2008 +0100
@@ -82,7 +82,7 @@
         this.provider = provider;
     }
 
-    private final Set cancelledKeys = new HashSet();
+    private final Set<SelectionKey> cancelledKeys = new HashSet<SelectionKey>();
 
     void cancel(SelectionKey k) {                       // package-private
         synchronized (cancelledKeys) {
--- a/src/share/classes/java/nio/charset/Charset-X-Coder.java	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/share/classes/java/nio/charset/Charset-X-Coder.java	Thu Jul 24 12:46:41 2008 +0100
@@ -303,7 +303,7 @@
 
 #if[encoder]
 
-    private WeakReference cachedDecoder = null;
+    private WeakReference<CharsetDecoder> cachedDecoder = null;
 
     /**
      * Tells whether or not the given byte array is a legal replacement value
@@ -322,13 +322,13 @@
      *          is a legal replacement value for this encoder
      */
     public boolean isLegalReplacement(byte[] repl) {
-        WeakReference wr = cachedDecoder;
+        WeakReference<CharsetDecoder> wr = cachedDecoder;
         CharsetDecoder dec = null;
-        if ((wr == null) || ((dec = (CharsetDecoder)wr.get()) == null)) {
+        if ((wr == null) || ((dec = wr.get()) == null)) {
             dec = charset().newDecoder();
             dec.onMalformedInput(CodingErrorAction.REPORT);
             dec.onUnmappableCharacter(CodingErrorAction.REPORT);
-            cachedDecoder = new WeakReference(dec);
+            cachedDecoder = new WeakReference<CharsetDecoder>(dec);
         } else {
             dec.reset();
         }
--- a/src/share/classes/java/nio/charset/Charset.java	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/share/classes/java/nio/charset/Charset.java	Thu Jul 24 12:46:41 2008 +0100
@@ -379,7 +379,7 @@
     }
 
     // Thread-local gate to prevent recursive provider lookups
-    private static ThreadLocal gate = new ThreadLocal();
+    private static ThreadLocal<ThreadLocal> gate = new ThreadLocal<ThreadLocal>();
 
     private static Charset lookupViaProviders(final String charsetName) {
 
@@ -539,9 +539,9 @@
     // Fold charsets from the given iterator into the given map, ignoring
     // charsets whose names already have entries in the map.
     //
-    private static void put(Iterator i, Map m) {
+    private static void put(Iterator<Charset> i, Map<String,Charset> m) {
         while (i.hasNext()) {
-            Charset cs = (Charset)i.next();
+            Charset cs = i.next();
             if (!m.containsKey(cs.name()))
                 m.put(cs.name(), cs);
         }
@@ -623,7 +623,7 @@
 
     private final String name;          // tickles a bug in oldjavac
     private final String[] aliases;     // tickles a bug in oldjavac
-    private Set aliasSet = null;
+    private Set<String> aliasSet = null;
 
     /**
      * Initializes a new charset with the given canonical name and alias
@@ -665,7 +665,7 @@
         if (aliasSet != null)
             return aliasSet;
         int n = aliases.length;
-        HashSet hs = new HashSet(n);
+        HashSet<String> hs = new HashSet<String>(n);
         for (int i = 0; i < n; i++)
             hs.add(aliases[i]);
         aliasSet = Collections.unmodifiableSet(hs);
--- a/src/share/classes/java/nio/charset/CoderResult.java	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/share/classes/java/nio/charset/CoderResult.java	Thu Jul 24 12:46:41 2008 +0100
@@ -194,7 +194,7 @@
 
     private static abstract class Cache {
 
-        private Map cache = null;
+        private Map<Integer,WeakReference<CoderResult>> cache = null;
 
         protected abstract CoderResult create(int len);
 
@@ -202,16 +202,16 @@
             if (len <= 0)
                 throw new IllegalArgumentException("Non-positive length");
             Integer k = new Integer(len);
-            WeakReference w;
+            WeakReference<CoderResult> w;
             CoderResult e = null;
             if (cache == null) {
-                cache = new HashMap();
-            } else if ((w = (WeakReference)cache.get(k)) != null) {
-                e = (CoderResult)w.get();
+                cache = new HashMap<Integer,WeakReference<CoderResult>>();
+            } else if ((w = cache.get(k)) != null) {
+                e = w.get();
             }
             if (e == null) {
                 e = create(len);
-                cache.put(k, new WeakReference(e));
+                cache.put(k, new WeakReference<CoderResult>(e));
             }
             return e;
         }
--- a/src/share/classes/sun/nio/ch/SelectorImpl.java	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/share/classes/sun/nio/ch/SelectorImpl.java	Thu Jul 24 12:46:41 2008 +0100
@@ -42,19 +42,19 @@
 {
 
     // The set of keys with data ready for an operation
-    protected Set selectedKeys;
+    protected Set<SelectionKey> selectedKeys;
 
     // The set of keys registered with this Selector
-    protected HashSet keys;
+    protected HashSet<SelectionKey> keys;
 
     // Public views of the key sets
-    private Set publicKeys;             // Immutable
-    private Set publicSelectedKeys;     // Removal allowed, but not addition
+    private Set<SelectionKey> publicKeys;             // Immutable
+    private Set<SelectionKey> publicSelectedKeys;     // Removal allowed, but not addition
 
     protected SelectorImpl(SelectorProvider sp) {
         super(sp);
-        keys = new HashSet();
-        selectedKeys = new HashSet();
+        keys = new HashSet<SelectionKey>();
+        selectedKeys = new HashSet<SelectionKey>();
         if (Util.atBugLevel("1.4")) {
             publicKeys = keys;
             publicSelectedKeys = selectedKeys;
@@ -64,13 +64,13 @@
         }
     }
 
-    public Set keys() {
+    public Set<SelectionKey> keys() {
         if (!isOpen() && !Util.atBugLevel("1.4"))
             throw new ClosedSelectorException();
         return publicKeys;
     }
 
-    public Set selectedKeys() {
+    public Set<SelectionKey> selectedKeys() {
         if (!isOpen() && !Util.atBugLevel("1.4"))
             throw new ClosedSelectorException();
         return publicSelectedKeys;
--- a/src/share/classes/sun/nio/ch/Util.java	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/share/classes/sun/nio/ch/Util.java	Thu Jul 24 12:46:41 2008 +0100
@@ -51,9 +51,13 @@
     // Per-thread soft cache of the last temporary direct buffer
     private static ThreadLocal<SoftReference<ByteBuffer>>[] bufferPool;
 
+    @SuppressWarnings("unchecked")
+    static ThreadLocal<SoftReference<ByteBuffer>>[] createThreadLocalBufferPool() {
+        return new ThreadLocal[TEMP_BUF_POOL_SIZE];
+    }
+
     static {
-        bufferPool = (ThreadLocal<SoftReference<ByteBuffer>>[])
-            new ThreadLocal[TEMP_BUF_POOL_SIZE];
+        bufferPool = createThreadLocalBufferPool();
         for (int i=0; i<TEMP_BUF_POOL_SIZE; i++)
             bufferPool[i] = new ThreadLocal<SoftReference<ByteBuffer>>();
     }
--- a/src/share/native/java/nio/Bits.c	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/share/native/java/nio/Bits.c	Thu Jul 24 12:46:41 2008 +0100
@@ -116,7 +116,7 @@
     jshort *srcShort, *dstShort, *endShort;
     jshort tmpShort;
 
-    dstShort = (jshort *)dstAddr;
+    dstShort = (jshort *)jlong_to_ptr(dstAddr);
 
     while (length > 0) {
         /* do not change this if-else statement, see WARNING above */
@@ -151,7 +151,7 @@
     jshort *srcShort, *dstShort, *endShort;
     jshort tmpShort;
 
-    srcShort = (jshort *)srcAddr;
+    srcShort = (jshort *)jlong_to_ptr(srcAddr);
 
     while (length > 0) {
         /* do not change this if-else statement, see WARNING above */
@@ -186,7 +186,7 @@
     jint *srcInt, *dstInt, *endInt;
     jint tmpInt;
 
-    dstInt = (jint *)dstAddr;
+    dstInt = (jint *)jlong_to_ptr(dstAddr);
 
     while (length > 0) {
         /* do not change this code, see WARNING above */
@@ -221,7 +221,7 @@
     jint *srcInt, *dstInt, *endInt;
     jint tmpInt;
 
-    srcInt = (jint *)srcAddr;
+    srcInt = (jint *)jlong_to_ptr(srcAddr);
 
     while (length > 0) {
         /* do not change this code, see WARNING above */
@@ -256,7 +256,7 @@
     jlong *srcLong, *dstLong, *endLong;
     jlong tmpLong;
 
-    dstLong = (jlong *)dstAddr;
+    dstLong = (jlong *)jlong_to_ptr(dstAddr);
 
     while (length > 0) {
         /* do not change this code, see WARNING above */
@@ -291,7 +291,7 @@
     jlong *srcLong, *dstLong, *endLong;
     jlong tmpLong;
 
-    srcLong = (jlong *)srcAddr;
+    srcLong = (jlong *)jlong_to_ptr(srcAddr);
 
     while (length > 0) {
         /* do not change this code, see WARNING above */
--- a/src/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/solaris/classes/sun/nio/ch/DevPollSelectorImpl.java	Thu Jul 24 12:46:41 2008 +0100
@@ -50,7 +50,7 @@
     private int totalChannels;
 
     // Maps from file descriptors to keys
-    private HashMap fdToKey;
+    private Map<Integer,SelectionKeyImpl> fdToKey;
 
     // True if this Selector has been closed
     private boolean closed = false;
@@ -71,7 +71,7 @@
         fd1 = fdes[1];
         pollWrapper = new DevPollArrayWrapper();
         pollWrapper.initInterrupt(fd0, fd1);
-        fdToKey = new HashMap();
+        fdToKey = new HashMap<Integer,SelectionKeyImpl>();
         totalChannels = 1;
     }
 
@@ -110,8 +110,7 @@
         int numKeysUpdated = 0;
         for (int i=0; i<entries; i++) {
             int nextFD = pollWrapper.getDescriptor(i);
-            SelectionKeyImpl ski = (SelectionKeyImpl) fdToKey.get(
-                new Integer(nextFD));
+            SelectionKeyImpl ski = fdToKey.get(Integer.valueOf(nextFD));
             // ski is null in the case of an interrupt
             if (ski != null) {
                 int rOps = pollWrapper.getReventOps(i);
@@ -169,7 +168,7 @@
 
     protected void implRegister(SelectionKeyImpl ski) {
         int fd = IOUtil.fdVal(ski.channel.getFD());
-        fdToKey.put(new Integer(fd), ski);
+        fdToKey.put(Integer.valueOf(fd), ski);
         totalChannels++;
         keys.add(ski);
     }
@@ -178,7 +177,7 @@
         int i = ski.getIndex();
         assert (i >= 0);
         int fd = ski.channel.getFDVal();
-        fdToKey.remove(new Integer(fd));
+        fdToKey.remove(Integer.valueOf(fd));
         pollWrapper.release(fd);
         totalChannels--;
         ski.setIndex(-1);
--- a/src/solaris/classes/sun/nio/ch/EPollSelectorImpl.java	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/solaris/classes/sun/nio/ch/EPollSelectorImpl.java	Thu Jul 24 12:46:41 2008 +0100
@@ -48,7 +48,7 @@
     EPollArrayWrapper pollWrapper;
 
     // Maps from file descriptors to keys
-    private HashMap fdToKey;
+    private Map<Integer,SelectionKeyImpl> fdToKey;
 
     // True if this Selector has been closed
     private boolean closed = false;
@@ -69,7 +69,7 @@
         fd1 = fdes[1];
         pollWrapper = new EPollArrayWrapper();
         pollWrapper.initInterrupt(fd0, fd1);
-        fdToKey = new HashMap();
+        fdToKey = new HashMap<Integer,SelectionKeyImpl>();
     }
 
     protected int doSelect(long timeout)
@@ -107,8 +107,7 @@
         int numKeysUpdated = 0;
         for (int i=0; i<entries; i++) {
             int nextFD = pollWrapper.getDescriptor(i);
-            SelectionKeyImpl ski = (SelectionKeyImpl) fdToKey.get(
-                new Integer(nextFD));
+            SelectionKeyImpl ski = fdToKey.get(Integer.valueOf(nextFD));
             // ski is null in the case of an interrupt
             if (ski != null) {
                 int rOps = pollWrapper.getEventOps(i);
@@ -164,7 +163,7 @@
 
     protected void implRegister(SelectionKeyImpl ski) {
         int fd = IOUtil.fdVal(ski.channel.getFD());
-        fdToKey.put(new Integer(fd), ski);
+        fdToKey.put(Integer.valueOf(fd), ski);
         pollWrapper.add(fd);
         keys.add(ski);
     }
@@ -172,7 +171,7 @@
     protected void implDereg(SelectionKeyImpl ski) throws IOException {
         assert (ski.getIndex() >= 0);
         int fd = ski.channel.getFDVal();
-        fdToKey.remove(new Integer(fd));
+        fdToKey.remove(Integer.valueOf(fd));
         pollWrapper.release(fd);
         ski.setIndex(-1);
         keys.remove(ski);
--- a/src/solaris/native/java/nio/MappedByteBuffer.c	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/solaris/native/java/nio/MappedByteBuffer.c	Thu Jul 24 12:46:41 2008 +0100
@@ -43,7 +43,11 @@
     int result = 0;
     int i = 0;
     void *a = (void *) jlong_to_ptr(address);
-    char * vec = (char *)malloc(numPages * sizeof(char));
+#ifdef __linux__
+    unsigned char *vec = (unsigned char *)malloc(numPages * sizeof(char));
+#else
+    char *vec = (char *)malloc(numPages * sizeof(char));
+#endif
 
     if (vec == NULL) {
         JNU_ThrowOutOfMemoryError(env, NULL);
--- a/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c	Thu Jul 24 12:46:41 2008 +0100
@@ -123,7 +123,7 @@
     jint fd = fdval(env, fdo);
     void *buf = (void *)jlong_to_ptr(address);
     SOCKADDR sa;
-    int sa_len = SOCKADDR_LEN;
+    socklen_t sa_len = SOCKADDR_LEN;
     jboolean retry = JNI_FALSE;
     jint n = 0;
     jobject senderAddr;
--- a/src/solaris/native/sun/nio/ch/InheritedChannel.c	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/solaris/native/sun/nio/ch/InheritedChannel.c	Thu Jul 24 12:46:41 2008 +0100
@@ -88,7 +88,8 @@
 JNIEXPORT jint JNICALL
 Java_sun_nio_ch_InheritedChannel_soType0(JNIEnv *env, jclass cla, jint fd)
 {
-    int sotype, arglen=sizeof(sotype);
+    int sotype;
+    socklen_t arglen=sizeof(sotype);
     if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) == 0) {
         if (sotype == SOCK_STREAM)
             return sun_nio_ch_InheritedChannel_SOCK_STREAM;
--- a/src/solaris/native/sun/nio/ch/Net.c	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/solaris/native/sun/nio/ch/Net.c	Thu Jul 24 12:46:41 2008 +0100
@@ -138,7 +138,7 @@
 Java_sun_nio_ch_Net_localPort(JNIEnv *env, jclass clazz, jobject fdo)
 {
     SOCKADDR sa;
-    int sa_len = SOCKADDR_LEN;
+    socklen_t sa_len = SOCKADDR_LEN;
     if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
         handleSocketError(env, errno);
         return -1;
@@ -150,7 +150,7 @@
 Java_sun_nio_ch_Net_localInetAddress(JNIEnv *env, jclass clazz, jobject fdo)
 {
     SOCKADDR sa;
-    int sa_len = SOCKADDR_LEN;
+    socklen_t sa_len = SOCKADDR_LEN;
     int port;
     if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
         handleSocketError(env, errno);
--- a/src/solaris/native/sun/nio/ch/ServerSocketChannelImpl.c	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/solaris/native/sun/nio/ch/ServerSocketChannelImpl.c	Thu Jul 24 12:46:41 2008 +0100
@@ -81,12 +81,12 @@
     jint ssfd = (*env)->GetIntField(env, ssfdo, fd_fdID);
     jint newfd;
     struct sockaddr *sa;
-    int sa_len;
+    int alloc_len;
     jobject remote_ia = 0;
     jobject isa;
     jint remote_port;
 
-    NET_AllocSockaddr(&sa, &sa_len);
+    NET_AllocSockaddr(&sa, &alloc_len);
 
     /*
      * accept connection but ignore ECONNABORTED indicating that
@@ -94,6 +94,7 @@
      * accept() was called.
      */
     for (;;) {
+        socklen_t sa_len = alloc_len;
         newfd = accept(ssfd, sa, &sa_len);
         if (newfd >= 0) {
             break;
--- a/src/solaris/native/sun/nio/ch/SocketChannelImpl.c	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/solaris/native/sun/nio/ch/SocketChannelImpl.c	Thu Jul 24 12:46:41 2008 +0100
@@ -55,7 +55,7 @@
                                                jboolean ready)
 {
     int error = 0;
-    int n = sizeof(int);
+    socklen_t n = sizeof(int);
     jint fd = fdval(env, fdo);
     int result = 0;
     struct pollfd poller;
--- a/src/windows/classes/sun/nio/ch/PipeImpl.java	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/windows/classes/sun/nio/ch/PipeImpl.java	Thu Jul 24 12:46:41 2008 +0100
@@ -67,7 +67,7 @@
     }
 
     private class Initializer
-        implements PrivilegedExceptionAction
+        implements PrivilegedExceptionAction<Void>
     {
 
         private final SelectorProvider sp;
@@ -76,7 +76,7 @@
             this.sp = sp;
         }
 
-        public Object run() throws IOException {
+        public Void run() throws IOException {
             ServerSocketChannel ssc = null;
             SocketChannel sc1 = null;
             SocketChannel sc2 = null;
--- a/src/windows/classes/sun/nio/ch/WindowsSelectorImpl.java	Thu Jul 24 12:40:30 2008 +0100
+++ b/src/windows/classes/sun/nio/ch/WindowsSelectorImpl.java	Thu Jul 24 12:46:41 2008 +0100
@@ -72,7 +72,7 @@
     private int threadsCount = 0;
 
     // A list of helper threads for select.
-    private final List threads = new ArrayList();
+    private final List<Thread> threads = new ArrayList<Thread>();
 
     //Pipe used as a wakeup object.
     private final Pipe wakeupPipe;
@@ -82,6 +82,7 @@
 
     // Maps file descriptors to their indices in  pollArray
     private final static class FdMap extends HashMap<Integer, MapEntry> {
+        static final long serialVersionUID = 0L;
         private MapEntry get(int desc) {
             return get(new Integer(desc));
         }