tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1212118 - /tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java
Date Thu, 08 Dec 2011 20:54:46 GMT
Author: markt
Date: Thu Dec  8 20:54:46 2011
New Revision: 1212118

URL: http://svn.apache.org/viewvc?rev=1212118&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=52208
Avoid possible NPEs if stopListening is called in a different thread

Modified:
    tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java

Modified: tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java?rev=1212118&r1=1212117&r2=1212118&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java (original)
+++ tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java Thu Dec  8
20:54:46 2011
@@ -236,6 +236,10 @@ public class NioReceiver extends Receive
         }
 
         setListen(true);
+
+        // Avoid NPEs if selector is set to null on stop.
+        Selector selector = this.selector;
+
         if (selector!=null && datagramChannel!=null) {
             ObjectReader oreader = new ObjectReader(MAX_UDP_SIZE); //max size for a datagram
packet
             datagramChannel.socket().setSendBufferSize(getUdpTxBufSize());
@@ -267,7 +271,7 @@ public class NioReceiver extends Receive
                     continue; // nothing to do
                 }
                 // get an iterator over the set of selected keys
-                Iterator<SelectionKey> it = (selector!=null)?selector.selectedKeys().iterator():null;
+                Iterator<SelectionKey> it = selector.selectedKeys().iterator();
                 // look at each key in the selected set
                 while (it!=null && it.hasNext()) {
                     SelectionKey key = it.next();
@@ -298,7 +302,7 @@ public class NioReceiver extends Receive
                     }
 
                     // remove key from selected set, it's been handled
-                    if (selector!=null) it.remove();
+                    it.remove();
                 }
             } catch (java.nio.channels.ClosedSelectorException cse) {
                 // ignore is normal at shutdown or stop listen socket



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message