changeset 13543:45ae2c3e1d52

8147862: Null check too late in sun.net.httpserver.ServerImpl Reviewed-by: chegar
author msheppar
date Sun, 24 Jan 2016 22:27:16 +0000
parents afa1a4e34c20
children f5178601929b
files src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java
diffstat 1 files changed, 15 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java	Fri Jan 08 19:53:36 2016 -0800
+++ b/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);
+                            // 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);
                             }
-
-                            if (chan == null) {
-                                continue; /* cancel something ? */
-                            }
-                            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()) {