8147862: Null check too late in sun.net.httpserver.ServerImpl
authormsheppar
Sun, 24 Jan 2016 22:27:16 +0000
changeset 35313 9e703c485544
parent 35312 4fbe776d28c5
child 35314 a7e13065a7a0
8147862: Null check too late in sun.net.httpserver.ServerImpl Reviewed-by: chegar
jdk/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java
--- a/jdk/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java	Fri Jan 08 19:53:36 2016 -0800
+++ b/jdk/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java	Sun Jan 24 22:27:16 2016 +0000
@@ -373,22 +373,22 @@
                             }
                             SocketChannel chan = schan.accept();
 
-                            // Set TCP_NODELAY, if appropriate
-                            if (ServerConfig.noDelay()) {
-                                chan.socket().setTcpNoDelay(true);
-                            }
-
-                            if (chan == null) {
-                                continue; /* cancel something ? */
+                            // optimist there's a channel
+                            if (chan != null) {
+                                // Set TCP_NODELAY, if appropriate
+                                if (ServerConfig.noDelay()) {
+                                    chan.socket().setTcpNoDelay(true);
+                                }
+                                chan.configureBlocking (false);
+                                SelectionKey newkey =
+                                    chan.register (selector, SelectionKey.OP_READ);
+                                HttpConnection c = new HttpConnection ();
+                                c.selectionKey = newkey;
+                                c.setChannel (chan);
+                                newkey.attach (c);
+                                requestStarted (c);
+                                allConnections.add (c);
                             }
-                            chan.configureBlocking (false);
-                            SelectionKey newkey = chan.register (selector, SelectionKey.OP_READ);
-                            HttpConnection c = new HttpConnection ();
-                            c.selectionKey = newkey;
-                            c.setChannel (chan);
-                            newkey.attach (c);
-                            requestStarted (c);
-                            allConnections.add (c);
                         } else {
                             try {
                                 if (key.isReadable()) {