hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asan...@apache.org
Subject svn commit: r1144472 - in /httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio: DefaultNHttpClientConnection.java DefaultNHttpServerConnection.java reactor/IOSessionImpl.java
Date Fri, 08 Jul 2011 20:06:16 GMT
Author: asankha
Date: Fri Jul  8 20:06:16 2011
New Revision: 1144472

URL: http://svn.apache.org/viewvc?rev=1144472&view=rev
Log:
fix possible NPE if the connection is closed - and the address is null


Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java?rev=1144472&r1=1144471&r2=1144472&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
Fri Jul  8 20:06:16 2011
@@ -29,6 +29,7 @@ package org.apache.http.impl.nio;
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.net.SocketAddress;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
@@ -261,11 +262,18 @@ public class DefaultNHttpClientConnectio
     public String toString() {
         StringBuilder buf = new StringBuilder();
 
-        if (this.session.getRemoteAddress() instanceof InetSocketAddress &&
-            this.session.getLocalAddress()  instanceof InetSocketAddress) {
+        final SocketAddress remoteAddress = this.session.getRemoteAddress();
+        final SocketAddress localAddress = this.session.getLocalAddress();
 
-            final InetSocketAddress remote = ((InetSocketAddress) this.session.getRemoteAddress());
-            final InetSocketAddress local  = ((InetSocketAddress) this.session.getLocalAddress());
+        if (remoteAddress == null || localAddress == null) {
+            return "[CLOSED]";
+        }
+
+        if (remoteAddress instanceof InetSocketAddress &&
+            localAddress instanceof InetSocketAddress) {
+
+            final InetSocketAddress remote = ((InetSocketAddress) remoteAddress);
+            final InetSocketAddress local  = ((InetSocketAddress) localAddress);
 
             buf.append(local.getAddress() != null ? local.getAddress().getHostAddress() :
local.getAddress())
             .append(':')
@@ -276,9 +284,9 @@ public class DefaultNHttpClientConnectio
             .append(remote.getPort());
 
         } else {
-            buf.append(this.session.getLocalAddress())
+            buf.append(localAddress)
             .append("->")
-            .append(this.session.getRemoteAddress());
+            .append(remoteAddress);
         }
 
         return buf.toString();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java?rev=1144472&r1=1144471&r2=1144472&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
Fri Jul  8 20:06:16 2011
@@ -29,6 +29,7 @@ package org.apache.http.impl.nio;
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.net.SocketAddress;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
@@ -263,11 +264,18 @@ public class DefaultNHttpServerConnectio
     public String toString() {
         StringBuilder buf = new StringBuilder();
 
-        if (this.session.getRemoteAddress() instanceof InetSocketAddress &&
-            this.session.getLocalAddress()  instanceof InetSocketAddress) {
+        final SocketAddress remoteAddress = this.session.getRemoteAddress();
+        final SocketAddress localAddress  = this.session.getLocalAddress();
 
-            final InetSocketAddress remote = ((InetSocketAddress) this.session.getRemoteAddress());
-            final InetSocketAddress local  = ((InetSocketAddress) this.session.getLocalAddress());
+        if (remoteAddress == null || localAddress == null) {
+            return "[CLOSED]";
+        }
+
+        if (remoteAddress instanceof InetSocketAddress &&
+            localAddress instanceof InetSocketAddress) {
+
+            final InetSocketAddress remote = ((InetSocketAddress) remoteAddress);
+            final InetSocketAddress local  = ((InetSocketAddress) localAddress);
 
             buf.append(remote.getAddress() != null ? remote.getAddress().getHostAddress()
: remote.getAddress())
             .append(':')
@@ -278,9 +286,9 @@ public class DefaultNHttpServerConnectio
             .append(local.getPort());
 
         } else {
-            buf.append(this.session.getRemoteAddress())
+            buf.append(remoteAddress)
             .append("->")
-            .append(this.session.getLocalAddress());
+            .append(localAddress);
         }
 
         return buf.toString();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java?rev=1144472&r1=1144471&r2=1144472&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/IOSessionImpl.java
Fri Jul  8 20:06:16 2011
@@ -312,24 +312,29 @@ public class IOSessionImpl implements IO
     public synchronized String toString() {
         StringBuilder buffer = new StringBuilder();
 
-        if (getRemoteAddress() instanceof InetSocketAddress &&
-            getLocalAddress()  instanceof InetSocketAddress) {
+        final SocketAddress remoteAddress = getRemoteAddress();
+        final SocketAddress localAddress = getLocalAddress();
 
-            final InetSocketAddress remote = ((InetSocketAddress) getRemoteAddress());
-            final InetSocketAddress local  = ((InetSocketAddress) getLocalAddress());
-
-            buffer.append(local.getAddress() != null ? local.getAddress().getHostAddress()
: local.getAddress())
-            .append(':')
-            .append(local.getPort())
-            .append("<->")
-            .append(remote.getAddress() != null ? remote.getAddress().getHostAddress() :
remote.getAddress())
-            .append(':')
-            .append(remote.getPort());
-
-        } else {
-            buffer.append(getLocalAddress())
-            .append("<->")
-            .append(getRemoteAddress());
+        if (remoteAddress != null && localAddress != null) {
+            if (remoteAddress instanceof InetSocketAddress &&
+                localAddress instanceof InetSocketAddress) {
+
+                final InetSocketAddress remote = ((InetSocketAddress) remoteAddress);
+                final InetSocketAddress local  = ((InetSocketAddress) localAddress);
+
+                buffer.append(local.getAddress() != null ? local.getAddress().getHostAddress()
: local.getAddress())
+                .append(':')
+                .append(local.getPort())
+                .append("<->")
+                .append(remote.getAddress() != null ? remote.getAddress().getHostAddress()
: remote.getAddress())
+                .append(':')
+                .append(remote.getPort());
+
+            } else {
+                buffer.append(localAddress)
+                .append("<->")
+                .append(remoteAddress);
+            }
         }
 
         buffer.append("[");



Mime
View raw message