8066130: com.sun.net.httpserver stop() throws NullPointerException if it is not started
authormsheppar
Mon, 01 Dec 2014 17:20:06 +0000
changeset 27779 e269428daa22
parent 27778 f3e0156f99d7
child 27782 5b202512698a
8066130: com.sun.net.httpserver stop() throws NullPointerException if it is not started Summary: added null check on dispatcherThread variable in stop method Reviewed-by: chegar
jdk/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java
jdk/test/com/sun/net/httpserver/StopNoStartTest.java
--- a/jdk/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java	Mon Dec 01 11:34:44 2014 -0500
+++ b/jdk/src/jdk.httpserver/share/classes/sun/net/httpserver/ServerImpl.java	Mon Dec 01 17:20:06 2014 +0000
@@ -206,11 +206,13 @@
         if (timer1Enabled) {
             timer1.cancel();
         }
-        try {
-            dispatcherThread.join();
-        } catch (InterruptedException e) {
-            Thread.currentThread().interrupt();
-            logger.log(Level.FINER, "ServerImpl.stop: ", e);
+        if (dispatcherThread != null) {
+            try {
+                dispatcherThread.join();
+            } catch (InterruptedException e) {
+                Thread.currentThread().interrupt();
+                logger.log(Level.FINER, "ServerImpl.stop: ", e);
+            }
         }
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/com/sun/net/httpserver/StopNoStartTest.java	Mon Dec 01 17:20:06 2014 +0000
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8066130
+ * @summary  Test HttpServer stop method invocation before a start has been called
+ */
+
+import java.net.InetSocketAddress;
+import com.sun.net.httpserver.HttpServer;
+
+
+public class StopNoStartTest {
+
+    public static void main(String[] args) throws Exception {
+
+        InetSocketAddress serverAddr = new InetSocketAddress(0);
+        HttpServer server = HttpServer.create(serverAddr, 0);
+        server.stop(0);
+    }
+}