logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1490141 - /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/UDPSocketServer.java
Date Thu, 06 Jun 2013 05:08:16 GMT
Author: ggregory
Date: Thu Jun  6 05:08:15 2013
New Revision: 1490141

URL: http://svn.apache.org/r1490141
Log:
Avoid unlikely but possible NPE when readLine() returns null.

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/UDPSocketServer.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/UDPSocketServer.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/UDPSocketServer.java?rev=1490141&r1=1490140&r2=1490141&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/UDPSocketServer.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/UDPSocketServer.java
Thu Jun  6 05:08:15 2013
@@ -49,7 +49,7 @@ import org.apache.logging.log4j.core.con
  */
 public class UDPSocketServer extends AbstractServer implements Runnable {
 
-    private static Logger logger;
+    private final Logger logger;
 
     private static final int MAX_PORT = 65534;
 
@@ -69,11 +69,8 @@ public class UDPSocketServer extends Abs
      *             If an error occurs.
      */
     public UDPSocketServer(final int port) throws IOException {
-        server = new DatagramSocket(port);
-        if (logger == null) {
-            logger = LogManager.getLogger(this);
-            // logger = LogManager.getLogger(getClass().getName() + '.' + port);
-        }
+        this.server = new DatagramSocket(port);
+        this.logger = LogManager.getLogger(this.getClass().getName() + '.' + port);
     }
 
     /**
@@ -99,14 +96,13 @@ public class UDPSocketServer extends Abs
         if (args.length == 2 && args[1].length() > 0) {
             ConfigurationFactory.setConfigurationFactory(new ServerConfigurationFactory(args[1]));
         }
-        logger = LogManager.getLogger(UDPSocketServer.class.getName());
         final UDPSocketServer sserver = new UDPSocketServer(port);
         final Thread server = new Thread(sserver);
         server.start();
         final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
         while (true) {
             final String line = reader.readLine();
-            if (line.equalsIgnoreCase("Quit") || line.equalsIgnoreCase("Stop") || line.equalsIgnoreCase("Exit"))
{
+            if (line == null || line.equalsIgnoreCase("Quit") || line.equalsIgnoreCase("Stop")
|| line.equalsIgnoreCase("Exit")) {
                 sserver.shutdown();
                 server.join();
                 break;



Mime
View raw message