Author: markt Date: Tue May 31 21:03:17 2016 New Revision: 1746344 URL: http://svn.apache.org/viewvc?rev=1746344&view=rev Log: SocketWrapperBase.socket is final and is always created non-null. Remove unnecessary null checks
Modified: tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java tomcat/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java Modified: tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java?rev=1746344&r1=1746343&r2=1746344&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java (original) +++ tomcat/trunk/java/org/apache/coyote/AbstractProtocol.java Tue May 31 21:03:17 2016 @@ -716,10 +716,6 @@ public abstract class AbstractProtocol<S } S socket = wrapper.getSocket(); - if (socket == null) { - // Nothing to do. Socket has been closed. - return SocketState.CLOSED; - } Processor processor = connections.get(socket); if (status == SocketEvent.DISCONNECT && processor == null) { @@ -975,11 +971,9 @@ public abstract class AbstractProtocol<S @Override public void release(SocketWrapperBase<S> socketWrapper) { S socket = socketWrapper.getSocket(); - if (socket != null) { - Processor processor = connections.remove(socket); - //getProtocol().removeWaitingProcessor(processor); - release(processor); - } + Processor processor = connections.remove(socket); + //getProtocol().removeWaitingProcessor(processor); + release(processor); } Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java?rev=1746344&r1=1746343&r2=1746344&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java Tue May 31 21:03:17 2016 @@ -825,7 +825,7 @@ public class Http11Processor extends Abs break; } case REQ_SSL_CERTIFICATE: { - if (sslSupport != null && socketWrapper.getSocket() != null) { + if (sslSupport != null) { // Consume and buffer the request body, so that it does not // interfere with the client's handshake messages InputFilter[] inputFilters = inputBuffer.getFilters(); Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1746344&r1=1746343&r2=1746344&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Tue May 31 21:03:17 2016 @@ -2255,10 +2255,6 @@ public class AprEndpoint extends Abstrac public void run() { synchronized (socketWrapper) { // Process the request from this socket - if (socketWrapper.getSocket() == null) { - // Closed in another thread - return; - } SocketState state = getHandler().process(socketWrapper, event); if (state == Handler.SocketState.CLOSED) { // Close socket and pool Modified: tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java?rev=1746344&r1=1746343&r2=1746344&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Tue May 31 21:03:17 2016 @@ -424,12 +424,10 @@ public class Nio2Endpoint extends Abstra if (log.isDebugEnabled()) log.error("",e); } try { - if (socket.getSocket() != null) { - synchronized (socket.getSocket()) { - if (socket.getSocket() != null && socket.getSocket().isOpen()) { - countDownConnection(); - socket.getSocket().close(true); - } + synchronized (socket.getSocket()) { + if (socket.getSocket().isOpen()) { + countDownConnection(); + socket.getSocket().close(true); } } } catch (Throwable e) { @@ -942,10 +940,7 @@ public class Nio2Endpoint extends Abstra @Override public void close() throws IOException { - Nio2Channel socket = getSocket(); - if (socket != null) { - socket.close(); - } + getSocket().close(); } @Override @@ -1395,9 +1390,6 @@ public class Nio2Endpoint extends Abstra public void awaitBytes() { - if (getSocket() == null) { - return; - } // NO-OP is there is already a read in progress. if (readPending.tryAcquire()) { getSocket().getBufHandler().configureReadBufferForWrite(); @@ -1643,26 +1635,24 @@ public class Nio2Endpoint extends Abstra int handshake = -1; try { - if (socketWrapper.getSocket() != null) { - // For STOP there is no point trying to handshake as the - // Poller has been stopped. - if (!socketWrapper.getSocket().isHandshakeComplete() && event == SocketEvent.ERROR) { - handshake = -1; - } else if (socketWrapper.getSocket().isHandshakeComplete() || - event == SocketEvent.STOP || - event == SocketEvent.ERROR) { - handshake = 0; - } else { - handshake = socketWrapper.getSocket().handshake(); - // The handshake process reads/writes from/to the - // socket. status may therefore be OPEN_WRITE once - // the handshake completes. However, the handshake - // happens when the socket is opened so the status - // must always be OPEN_READ after it completes. It - // is OK to always set this as it is only used if - // the handshake completes. - event = SocketEvent.OPEN_READ; - } + // For STOP there is no point trying to handshake as the + // Poller has been stopped. + if (!socketWrapper.getSocket().isHandshakeComplete() && event == SocketEvent.ERROR) { + handshake = -1; + } else if (socketWrapper.getSocket().isHandshakeComplete() || + event == SocketEvent.STOP || + event == SocketEvent.ERROR) { + handshake = 0; + } else { + handshake = socketWrapper.getSocket().handshake(); + // The handshake process reads/writes from/to the + // socket. status may therefore be OPEN_WRITE once + // the handshake completes. However, the handshake + // happens when the socket is opened so the status + // must always be OPEN_READ after it completes. It + // is OK to always set this as it is only used if + // the handshake completes. + event = SocketEvent.OPEN_READ; } } catch (IOException x) { handshake = -1; Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java?rev=1746344&r1=1746343&r2=1746344&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/NioBlockingSelector.java Tue May 31 21:03:17 2016 @@ -245,7 +245,6 @@ public class NioBlockingSelector { public void add(final NioSocketWrapper key, final int ops, final KeyReference ref) { if ( key == null ) return; NioChannel nch = key.getSocket(); - if ( nch == null ) return; final SocketChannel ch = nch.getIOChannel(); if ( ch == null ) return; @@ -276,7 +275,6 @@ public class NioBlockingSelector { public void remove(final NioSocketWrapper key, final int ops) { if ( key == null ) return; NioChannel nch = key.getSocket(); - if ( nch == null ) return; final SocketChannel ch = nch.getIOChannel(); if ( ch == null ) return; Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1746344&r1=1746343&r2=1746344&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Tue May 31 21:03:17 2016 @@ -1230,10 +1230,7 @@ public class NioEndpoint extends Abstrac @Override public void close() throws IOException { - NioChannel socket = getSocket(); - if (socket != null) { - socket.close(); - } + getSocket().close(); } @@ -1432,9 +1429,6 @@ public class NioEndpoint extends Abstrac @Override public void run() { NioChannel socket = socketWrapper.getSocket(); - if (socket == null) { - return; - } SelectionKey key = socket.getIOChannel().keyFor( socket.getPoller().getSelector()); Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java?rev=1746344&r1=1746343&r2=1746344&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java Tue May 31 21:03:17 2016 @@ -312,7 +312,7 @@ public abstract class SocketWrapperBase< * @throws IOException If an IO error occurs during the write */ public final void write(boolean block, byte[] buf, int off, int len) throws IOException { - if (len == 0 || buf == null || getSocket() == null) { + if (len == 0 || buf == null) { return; } @@ -412,10 +412,6 @@ public abstract class SocketWrapperBase< * @throws IOException If an IO error occurs during the write */ public boolean flush(boolean block) throws IOException { - if (getSocket() == null) { - return false; - } - boolean result = false; if (block) { // A blocking flush will always empty the buffer. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org