This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new b7384c2  Port NPE prevention fix from NIO
b7384c2 is described below

commit b7384c2f3444a31d5bdd97ad985c9a952d906220
Author: remm <r...@apache.org>
AuthorDate: Fri May 31 10:56:33 2019 +0200

    Port NPE prevention fix from NIO
---
 java/org/apache/tomcat/util/net/Nio2Endpoint.java | 118 +++++++++++++---------
 1 file changed, 68 insertions(+), 50 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/Nio2Endpoint.java 
b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
index 767253a..66f9e20 100644
--- a/java/org/apache/tomcat/util/net/Nio2Endpoint.java
+++ b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
@@ -1467,30 +1467,36 @@ public class Nio2Endpoint extends 
AbstractJsseEndpoint<Nio2Channel,AsynchronousS
 
         @Override
         protected void populateRemoteAddr() {
-            SocketAddress socketAddress = null;
-            try {
-                socketAddress = getSocket().getIOChannel().getRemoteAddress();
-            } catch (IOException e) {
-                // Ignore
-            }
-            if (socketAddress instanceof InetSocketAddress) {
-                remoteAddr = ((InetSocketAddress) 
socketAddress).getAddress().getHostAddress();
+            AsynchronousSocketChannel sc = getSocket().getIOChannel();
+            if (sc != null) {
+                SocketAddress socketAddress = null;
+                try {
+                    socketAddress = sc.getRemoteAddress();
+                } catch (IOException e) {
+                    // Ignore
+                }
+                if (socketAddress instanceof InetSocketAddress) {
+                    remoteAddr = ((InetSocketAddress) 
socketAddress).getAddress().getHostAddress();
+                }
             }
         }
 
 
         @Override
         protected void populateRemoteHost() {
-            SocketAddress socketAddress = null;
-            try {
-                socketAddress = getSocket().getIOChannel().getRemoteAddress();
-            } catch (IOException e) {
-                log.warn(sm.getString("endpoint.warn.noRemoteHost", 
getSocket()), e);
-            }
-            if (socketAddress instanceof InetSocketAddress) {
-                remoteHost = ((InetSocketAddress) 
socketAddress).getAddress().getHostName();
-                if (remoteAddr == null) {
-                    remoteAddr = ((InetSocketAddress) 
socketAddress).getAddress().getHostAddress();
+            AsynchronousSocketChannel sc = getSocket().getIOChannel();
+            if (sc != null) {
+                SocketAddress socketAddress = null;
+                try {
+                    socketAddress = sc.getRemoteAddress();
+                } catch (IOException e) {
+                    log.warn(sm.getString("endpoint.warn.noRemoteHost", 
getSocket()), e);
+                }
+                if (socketAddress instanceof InetSocketAddress) {
+                    remoteHost = ((InetSocketAddress) 
socketAddress).getAddress().getHostName();
+                    if (remoteAddr == null) {
+                        remoteAddr = ((InetSocketAddress) 
socketAddress).getAddress().getHostAddress();
+                    }
                 }
             }
         }
@@ -1498,56 +1504,68 @@ public class Nio2Endpoint extends 
AbstractJsseEndpoint<Nio2Channel,AsynchronousS
 
         @Override
         protected void populateRemotePort() {
-            SocketAddress socketAddress = null;
-            try {
-                socketAddress = getSocket().getIOChannel().getRemoteAddress();
-            } catch (IOException e) {
-                log.warn(sm.getString("endpoint.warn.noRemotePort", 
getSocket()), e);
-            }
-            if (socketAddress instanceof InetSocketAddress) {
-                remotePort = ((InetSocketAddress) socketAddress).getPort();
+            AsynchronousSocketChannel sc = getSocket().getIOChannel();
+            if (sc != null) {
+                SocketAddress socketAddress = null;
+                try {
+                    socketAddress = sc.getRemoteAddress();
+                } catch (IOException e) {
+                    log.warn(sm.getString("endpoint.warn.noRemotePort", 
getSocket()), e);
+                }
+                if (socketAddress instanceof InetSocketAddress) {
+                    remotePort = ((InetSocketAddress) socketAddress).getPort();
+                }
             }
         }
 
 
         @Override
         protected void populateLocalName() {
-            SocketAddress socketAddress = null;
-            try {
-                socketAddress = getSocket().getIOChannel().getLocalAddress();
-            } catch (IOException e) {
-                log.warn(sm.getString("endpoint.warn.noLocalName", 
getSocket()), e);
-            }
-            if (socketAddress instanceof InetSocketAddress) {
-                localName = ((InetSocketAddress) socketAddress).getHostName();
+            AsynchronousSocketChannel sc = getSocket().getIOChannel();
+            if (sc != null) {
+                SocketAddress socketAddress = null;
+                try {
+                    socketAddress = sc.getLocalAddress();
+                } catch (IOException e) {
+                    log.warn(sm.getString("endpoint.warn.noLocalName", 
getSocket()), e);
+                }
+                if (socketAddress instanceof InetSocketAddress) {
+                    localName = ((InetSocketAddress) 
socketAddress).getHostName();
+                }
             }
         }
 
 
         @Override
         protected void populateLocalAddr() {
-            SocketAddress socketAddress = null;
-            try {
-                socketAddress = getSocket().getIOChannel().getLocalAddress();
-            } catch (IOException e) {
-                log.warn(sm.getString("endpoint.warn.noLocalAddr", 
getSocket()), e);
-            }
-            if (socketAddress instanceof InetSocketAddress) {
-                localAddr = ((InetSocketAddress) 
socketAddress).getAddress().getHostAddress();
+            AsynchronousSocketChannel sc = getSocket().getIOChannel();
+            if (sc != null) {
+                SocketAddress socketAddress = null;
+                try {
+                    socketAddress = sc.getLocalAddress();
+                } catch (IOException e) {
+                    log.warn(sm.getString("endpoint.warn.noLocalAddr", 
getSocket()), e);
+                }
+                if (socketAddress instanceof InetSocketAddress) {
+                    localAddr = ((InetSocketAddress) 
socketAddress).getAddress().getHostAddress();
+                }
             }
         }
 
 
         @Override
         protected void populateLocalPort() {
-            SocketAddress socketAddress = null;
-            try {
-                socketAddress = getSocket().getIOChannel().getLocalAddress();
-            } catch (IOException e) {
-                log.warn(sm.getString("endpoint.warn.noLocalPort", 
getSocket()), e);
-            }
-            if (socketAddress instanceof InetSocketAddress) {
-                localPort = ((InetSocketAddress) socketAddress).getPort();
+            AsynchronousSocketChannel sc = getSocket().getIOChannel();
+            if (sc != null) {
+                SocketAddress socketAddress = null;
+                try {
+                    socketAddress = sc.getLocalAddress();
+                } catch (IOException e) {
+                    log.warn(sm.getString("endpoint.warn.noLocalPort", 
getSocket()), e);
+                }
+                if (socketAddress instanceof InetSocketAddress) {
+                    localPort = ((InetSocketAddress) socketAddress).getPort();
+                }
             }
         }
 


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

Reply via email to