tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kkoli...@apache.org
Subject svn commit: r1599393 - in /tomcat/trunk: java/org/apache/coyote/http11/ webapps/docs/
Date Mon, 02 Jun 2014 23:40:11 GMT
Author: kkolinko
Date: Mon Jun  2 23:40:11 2014
New Revision: 1599393

URL: http://svn.apache.org/r1599393
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56582
Convert implementations of ActionHook.action(..) to use switch(enum) operator.
Second part: HTTP processors.

Modified:
    tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11Nio2Processor.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
    tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java?rev=1599393&r1=1599392&r2=1599393&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java Mon Jun  2 23:40:11
2014
@@ -716,7 +716,8 @@ public abstract class AbstractHttp11Proc
     @Override
     public final void action(ActionCode actionCode, Object param) {
 
-        if (actionCode == ActionCode.CLOSE) {
+        switch (actionCode) {
+        case CLOSE: {
             // End the processing of the current request
             try {
                 getOutputBuffer().endRequest();
@@ -724,8 +725,9 @@ public abstract class AbstractHttp11Proc
                 // Set error flag
                 error = true;
             }
-
-        } else if (actionCode == ActionCode.COMMIT) {
+            break;
+        }
+        case COMMIT: {
             // Commit current response
             if (response.isCommitted()) {
                 return;
@@ -739,8 +741,9 @@ public abstract class AbstractHttp11Proc
                 // Set error flag
                 error = true;
             }
-
-        } else if (actionCode == ActionCode.ACK) {
+            break;
+        }
+        case ACK: {
             // Acknowledge request
             // Send a 100 status back if it makes sense (response not committed
             // yet, and client specified an expectation for 100-continue)
@@ -755,8 +758,9 @@ public abstract class AbstractHttp11Proc
                 // Set error flag
                 error = true;
             }
-
-        } else if (actionCode == ActionCode.CLIENT_FLUSH) {
+            break;
+        }
+        case CLIENT_FLUSH: {
             try {
                 getOutputBuffer().flush();
             } catch (IOException e) {
@@ -764,21 +768,25 @@ public abstract class AbstractHttp11Proc
                 error = true;
                 response.setErrorException(e);
             }
-
-        } else if (actionCode == ActionCode.IS_ERROR) {
+            break;
+        }
+        case IS_ERROR: {
             ((AtomicBoolean) param).set(error);
-
-        } else if (actionCode == ActionCode.DISABLE_SWALLOW_INPUT) {
+            break;
+        }
+        case DISABLE_SWALLOW_INPUT: {
             // Do not swallow request input and make sure we are closing the
             // connection
             error = true;
             getInputBuffer().setSwallowInput(false);
-
-        } else if (actionCode == ActionCode.RESET) {
+            break;
+        }
+        case RESET: {
             // Note: This must be called before the response is committed
             getOutputBuffer().reset();
-
-        } else if (actionCode == ActionCode.REQ_SET_BODY_REPLAY) {
+            break;
+        }
+        case REQ_SET_BODY_REPLAY: {
             ByteChunk body = (ByteChunk) param;
 
             InputFilter savedBody = new SavedRequestInputFilter(body);
@@ -788,52 +796,84 @@ public abstract class AbstractHttp11Proc
             AbstractInputBuffer<S> internalBuffer = (AbstractInputBuffer<S>)
                 request.getInputBuffer();
             internalBuffer.addActiveFilter(savedBody);
-        } else if (actionCode == ActionCode.ASYNC_START) {
+            break;
+        }
+        case ASYNC_START: {
             asyncStateMachine.asyncStart((AsyncContextCallback) param);
             // Async time out is based on SocketWrapper access time
             getSocketWrapper().access();
-        } else if (actionCode == ActionCode.ASYNC_DISPATCHED) {
+            break;
+        }
+        case ASYNC_DISPATCHED: {
             asyncStateMachine.asyncDispatched();
-        } else if (actionCode == ActionCode.ASYNC_TIMEOUT) {
+            break;
+        }
+        case ASYNC_TIMEOUT: {
             AtomicBoolean result = (AtomicBoolean) param;
             result.set(asyncStateMachine.asyncTimeout());
-        } else if (actionCode == ActionCode.ASYNC_RUN) {
+            break;
+        }
+        case ASYNC_RUN: {
             asyncStateMachine.asyncRun((Runnable) param);
-        } else if (actionCode == ActionCode.ASYNC_ERROR) {
+            break;
+        }
+        case ASYNC_ERROR: {
             asyncStateMachine.asyncError();
-        } else if (actionCode == ActionCode.ASYNC_IS_STARTED) {
+            break;
+        }
+        case ASYNC_IS_STARTED: {
             ((AtomicBoolean) param).set(asyncStateMachine.isAsyncStarted());
-        } else if (actionCode == ActionCode.ASYNC_IS_DISPATCHING) {
+            break;
+        }
+        case ASYNC_IS_DISPATCHING: {
             ((AtomicBoolean) param).set(asyncStateMachine.isAsyncDispatching());
-        } else if (actionCode == ActionCode.ASYNC_IS_ASYNC) {
+            break;
+        }
+        case ASYNC_IS_ASYNC: {
             ((AtomicBoolean) param).set(asyncStateMachine.isAsync());
-        } else if (actionCode == ActionCode.ASYNC_IS_TIMINGOUT) {
+            break;
+        }
+        case ASYNC_IS_TIMINGOUT: {
             ((AtomicBoolean) param).set(asyncStateMachine.isAsyncTimingOut());
-        } else if (actionCode == ActionCode.ASYNC_IS_ERROR) {
+            break;
+        }
+        case ASYNC_IS_ERROR: {
             ((AtomicBoolean) param).set(asyncStateMachine.isAsyncError());
-        } else if (actionCode == ActionCode.ASYNC_COMPLETE) {
+            break;
+        }
+        case ASYNC_COMPLETE: {
             socketWrapper.clearDispatches();
             if (asyncStateMachine.asyncComplete()) {
                 endpoint.processSocket(this.socketWrapper, SocketStatus.OPEN_READ, true);
             }
-        } else if (actionCode == ActionCode.ASYNC_SETTIMEOUT) {
+            break;
+        }
+        case ASYNC_SETTIMEOUT: {
             if (param == null || socketWrapper == null) {
                 return;
             }
             long timeout = ((Long)param).longValue();
             // If we are not piggy backing on a worker thread, set the timeout
             socketWrapper.setTimeout(timeout);
-        } else if (actionCode == ActionCode.ASYNC_DISPATCH) {
+            break;
+        }
+        case ASYNC_DISPATCH: {
             if (asyncStateMachine.asyncDispatch()) {
                 endpoint.processSocket(this.socketWrapper, SocketStatus.OPEN_READ, true);
             }
-        } else if (actionCode == ActionCode.UPGRADE) {
+            break;
+        }
+        case UPGRADE: {
             httpUpgradeHandler = (HttpUpgradeHandler) param;
             // Stop further HTTP output
             getOutputBuffer().finished = true;
-        } else if (actionCode == ActionCode.AVAILABLE) {
+            break;
+        }
+        case AVAILABLE: {
             request.setAvailable(inputBuffer.available());
-        } else if (actionCode == ActionCode.NB_WRITE_INTEREST) {
+            break;
+        }
+        case NB_WRITE_INTEREST: {
             AtomicBoolean isReady = (AtomicBoolean)param;
             try {
                 isReady.set(getOutputBuffer().isReady());
@@ -841,19 +881,33 @@ public abstract class AbstractHttp11Proc
                 getLog().debug("isReady() failed", e);
                 error = true;
             }
-        } else if (actionCode == ActionCode.NB_READ_INTEREST) {
+            break;
+        }
+        case NB_READ_INTEREST: {
             registerForEvent(true, false);
-        } else if (actionCode == ActionCode.REQUEST_BODY_FULLY_READ) {
+            break;
+        }
+        case REQUEST_BODY_FULLY_READ: {
             AtomicBoolean result = (AtomicBoolean) param;
             result.set(getInputBuffer().isFinished());
-        } else if (actionCode == ActionCode.DISPATCH_READ) {
+            break;
+        }
+        case DISPATCH_READ: {
             socketWrapper.addDispatch(DispatchType.NON_BLOCKING_READ);
-        } else if (actionCode == ActionCode.DISPATCH_WRITE) {
+            break;
+        }
+        case DISPATCH_WRITE: {
             socketWrapper.addDispatch(DispatchType.NON_BLOCKING_WRITE);
-        } else if (actionCode == ActionCode.DISPATCH_EXECUTE) {
+            break;
+        }
+        case DISPATCH_EXECUTE: {
             getEndpoint().executeNonBlockingDispatches(socketWrapper);
-        } else {
+            break;
+        }
+        default: {
             actionInternal(actionCode, param);
+            break;
+        }
         }
     }
 

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java?rev=1599393&r1=1599392&r2=1599393&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11AprProcessor.java Mon Jun  2 23:40:11
2014
@@ -260,12 +260,13 @@ public class Http11AprProcessor extends 
      * @param param Action parameter
      */
     @Override
+    @SuppressWarnings("incomplete-switch") // Other cases are handled by action()
     public void actionInternal(ActionCode actionCode, Object param) {
 
         long socketRef = socketWrapper.getSocket().longValue();
 
-        if (actionCode == ActionCode.REQ_HOST_ADDR_ATTRIBUTE) {
-
+        switch (actionCode) {
+        case REQ_HOST_ADDR_ATTRIBUTE: {
             if (socketRef == 0) {
                 request.remoteAddr().recycle();
             } else {
@@ -279,9 +280,9 @@ public class Http11AprProcessor extends 
                 }
                 request.remoteAddr().setString(socketWrapper.getRemoteAddr());
             }
-
-        } else if (actionCode == ActionCode.REQ_LOCAL_NAME_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_LOCAL_NAME_ATTRIBUTE: {
             if (socketRef == 0) {
                 request.localName().recycle();
             } else {
@@ -295,9 +296,9 @@ public class Http11AprProcessor extends 
                 }
                 request.localName().setString(socketWrapper.getLocalName());
             }
-
-        } else if (actionCode == ActionCode.REQ_HOST_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_HOST_ATTRIBUTE: {
             if (socketRef == 0) {
                 request.remoteHost().recycle();
             } else {
@@ -320,9 +321,9 @@ public class Http11AprProcessor extends 
                     request.remoteHost().setString(socketWrapper.getRemoteHost());
                 }
             }
-
-        } else if (actionCode == ActionCode.REQ_LOCAL_ADDR_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_LOCAL_ADDR_ATTRIBUTE: {
             if (socketRef == 0) {
                 request.localAddr().recycle();
             } else {
@@ -336,9 +337,9 @@ public class Http11AprProcessor extends 
                 }
                 request.localAddr().setString(socketWrapper.getLocalAddr());
             }
-
-        } else if (actionCode == ActionCode.REQ_REMOTEPORT_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_REMOTEPORT_ATTRIBUTE: {
             if (socketRef == 0) {
                 request.setRemotePort(0);
             } else {
@@ -353,9 +354,9 @@ public class Http11AprProcessor extends 
                 }
                 request.setRemotePort(socketWrapper.getRemotePort());
             }
-
-        } else if (actionCode == ActionCode.REQ_LOCALPORT_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_LOCALPORT_ATTRIBUTE: {
             if (socketRef == 0) {
                 request.setLocalPort(0);
             } else {
@@ -370,9 +371,9 @@ public class Http11AprProcessor extends 
                 }
                 request.setLocalPort(socketWrapper.getLocalPort());
             }
-
-        } else if (actionCode == ActionCode.REQ_SSL_ATTRIBUTE ) {
-
+            break;
+        }
+        case REQ_SSL_ATTRIBUTE: {
             if (endpoint.isSSLEnabled() && (socketRef != 0)) {
                 try {
                     // Cipher suite
@@ -419,9 +420,9 @@ public class Http11AprProcessor extends 
                     log.warn(sm.getString("http11processor.socket.ssl"), e);
                 }
             }
-
-        } else if (actionCode == ActionCode.REQ_SSL_CERTIFICATE) {
-
+            break;
+        }
+        case REQ_SSL_CERTIFICATE: {
             if (endpoint.isSSLEnabled() && (socketRef != 0)) {
                 // Consume and buffer the request body, so that it does not
                 // interfere with the client's handshake messages
@@ -457,16 +458,25 @@ public class Http11AprProcessor extends 
                     log.warn(sm.getString("http11processor.socket.ssl"), e);
                 }
             }
-
-        } else if (actionCode == ActionCode.COMET_BEGIN) {
+            break;
+        }
+        case COMET_BEGIN: {
             comet = true;
-        } else if (actionCode == ActionCode.COMET_END) {
+            break;
+        }
+        case COMET_END: {
             comet = false;
-        } else if (actionCode == ActionCode.COMET_CLOSE) {
+            break;
+        }
+        case COMET_CLOSE: {
             ((AprEndpoint)endpoint).processSocket(this.socketWrapper,
                     SocketStatus.OPEN_READ, true);
-        } else if (actionCode == ActionCode.COMET_SETTIMEOUT) {
+            break;
+        }
+        case COMET_SETTIMEOUT: {
             //no op
+            break;
+        }
         }
     }
 

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11Nio2Processor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11Nio2Processor.java?rev=1599393&r1=1599392&r2=1599393&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11Nio2Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11Nio2Processor.java Mon Jun  2 23:40:11
2014
@@ -307,10 +307,11 @@ public class Http11Nio2Processor extends
      * @param param Action parameter
      */
     @Override
+    @SuppressWarnings("incomplete-switch") // Other cases are handled by action()
     public void actionInternal(ActionCode actionCode, Object param) {
 
-        if (actionCode == ActionCode.REQ_HOST_ADDR_ATTRIBUTE) {
-
+        switch (actionCode) {
+        case REQ_HOST_ADDR_ATTRIBUTE: {
             if (socketWrapper == null || socketWrapper.getSocket() == null) {
                 request.remoteAddr().recycle();
             } else {
@@ -327,9 +328,9 @@ public class Http11Nio2Processor extends
                 }
                 request.remoteAddr().setString(socketWrapper.getRemoteAddr());
             }
-
-        } else if (actionCode == ActionCode.REQ_LOCAL_NAME_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_LOCAL_NAME_ATTRIBUTE: {
             if (socketWrapper == null || socketWrapper.getSocket() == null) {
                 request.localName().recycle();
             } else {
@@ -346,9 +347,9 @@ public class Http11Nio2Processor extends
                 }
                 request.localName().setString(socketWrapper.getLocalName());
             }
-
-        } else if (actionCode == ActionCode.REQ_HOST_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_HOST_ATTRIBUTE: {
             if (socketWrapper == null || socketWrapper.getSocket() == null) {
                 request.remoteHost().recycle();
             } else {
@@ -374,9 +375,9 @@ public class Http11Nio2Processor extends
                 }
                 request.remoteHost().setString(socketWrapper.getRemoteHost());
             }
-
-        } else if (actionCode == ActionCode.REQ_LOCAL_ADDR_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_LOCAL_ADDR_ATTRIBUTE: {
             if (socketWrapper == null || socketWrapper.getSocket() == null) {
                 request.localAddr().recycle();
             } else {
@@ -390,9 +391,9 @@ public class Http11Nio2Processor extends
                 }
                 request.localAddr().setString(socketWrapper.getLocalAddr());
             }
-
-        } else if (actionCode == ActionCode.REQ_REMOTEPORT_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_REMOTEPORT_ATTRIBUTE: {
             if (socketWrapper == null || socketWrapper.getSocket() == null) {
                 request.setRemotePort(0);
             } else {
@@ -405,9 +406,9 @@ public class Http11Nio2Processor extends
                 }
                 request.setRemotePort(socketWrapper.getRemotePort());
             }
-
-        } else if (actionCode == ActionCode.REQ_LOCALPORT_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_LOCALPORT_ATTRIBUTE: {
             if (socketWrapper == null || socketWrapper.getSocket() == null) {
                 request.setLocalPort(0);
             } else {
@@ -420,9 +421,9 @@ public class Http11Nio2Processor extends
                 }
                 request.setLocalPort(socketWrapper.getLocalPort());
             }
-
-        } else if (actionCode == ActionCode.REQ_SSL_ATTRIBUTE ) {
-
+            break;
+        }
+        case REQ_SSL_ATTRIBUTE: {
             try {
                 if (sslSupport != null) {
                     Object sslO = sslSupport.getCipherSuite();
@@ -450,9 +451,9 @@ public class Http11Nio2Processor extends
             } catch (Exception e) {
                 log.warn(sm.getString("http11processor.socket.ssl"), e);
             }
-
-        } else if (actionCode == ActionCode.REQ_SSL_CERTIFICATE) {
-
+            break;
+        }
+        case REQ_SSL_CERTIFICATE: {
             if (sslSupport != null && socketWrapper.getSocket() != null) {
                 /*
                  * Consume and buffer the request body, so that it does not
@@ -490,11 +491,17 @@ public class Http11Nio2Processor extends
                     log.warn(sm.getString("http11processor.socket.ssl"), e);
                 }
             }
-        } else if (actionCode == ActionCode.COMET_BEGIN) {
+            break;
+        }
+        case COMET_BEGIN: {
             comet = true;
-        } else if (actionCode == ActionCode.COMET_END) {
+            break;
+        }
+        case COMET_END: {
             comet = false;
-        } else if (actionCode == ActionCode.COMET_CLOSE) {
+            break;
+        }
+        case COMET_CLOSE: {
             if (socketWrapper == null || socketWrapper.getSocket() == null) {
                 return;
             }
@@ -505,7 +512,9 @@ public class Http11Nio2Processor extends
                 // an application controlled thread) or similar.
                 endpoint.processSocket(this.socketWrapper, SocketStatus.OPEN_READ, true);
             }
-        } else if (actionCode == ActionCode.COMET_SETTIMEOUT) {
+            break;
+        }
+        case COMET_SETTIMEOUT: {
             if (param == null) {
                 return;
             }
@@ -518,6 +527,8 @@ public class Http11Nio2Processor extends
             if ( rp.getStage() != org.apache.coyote.Constants.STAGE_SERVICE ) {
                 socketWrapper.setTimeout(timeout);
             }
+            break;
+        }
         }
     }
 

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=1599393&r1=1599392&r2=1599393&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Mon Jun  2 23:40:11
2014
@@ -316,10 +316,11 @@ public class Http11NioProcessor extends 
      * @param param Action parameter
      */
     @Override
+    @SuppressWarnings("incomplete-switch") // Other cases are handled by action()
     public void actionInternal(ActionCode actionCode, Object param) {
 
-        if (actionCode == ActionCode.REQ_HOST_ADDR_ATTRIBUTE) {
-
+        switch (actionCode) {
+        case REQ_HOST_ADDR_ATTRIBUTE: {
             if (socketWrapper == null) {
                 request.remoteAddr().recycle();
             } else {
@@ -331,9 +332,9 @@ public class Http11NioProcessor extends 
                 }
                 request.remoteAddr().setString(socketWrapper.getRemoteAddr());
             }
-
-        } else if (actionCode == ActionCode.REQ_LOCAL_NAME_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_LOCAL_NAME_ATTRIBUTE: {
             if (socketWrapper == null) {
                 request.localName().recycle();
             } else {
@@ -345,9 +346,9 @@ public class Http11NioProcessor extends 
                 }
                 request.localName().setString(socketWrapper.getLocalName());
             }
-
-        } else if (actionCode == ActionCode.REQ_HOST_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_HOST_ATTRIBUTE: {
             if (socketWrapper == null) {
                 request.remoteHost().recycle();
             } else {
@@ -368,9 +369,9 @@ public class Http11NioProcessor extends 
                 }
                 request.remoteHost().setString(socketWrapper.getRemoteHost());
             }
-
-        } else if (actionCode == ActionCode.REQ_LOCAL_ADDR_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_LOCAL_ADDR_ATTRIBUTE: {
             if (socketWrapper == null) {
                 request.localAddr().recycle();
             } else {
@@ -380,9 +381,9 @@ public class Http11NioProcessor extends 
                 }
                 request.localAddr().setString(socketWrapper.getLocalAddr());
             }
-
-        } else if (actionCode == ActionCode.REQ_REMOTEPORT_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_REMOTEPORT_ATTRIBUTE: {
             if (socketWrapper == null) {
                 request.setRemotePort(0);
             } else {
@@ -391,9 +392,9 @@ public class Http11NioProcessor extends 
                 }
                 request.setRemotePort(socketWrapper.getRemotePort());
             }
-
-        } else if (actionCode == ActionCode.REQ_LOCALPORT_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_LOCALPORT_ATTRIBUTE: {
             if (socketWrapper == null) {
                 request.setLocalPort(0);
             } else {
@@ -402,9 +403,9 @@ public class Http11NioProcessor extends 
                 }
                 request.setLocalPort(socketWrapper.getLocalPort());
             }
-
-        } else if (actionCode == ActionCode.REQ_SSL_ATTRIBUTE ) {
-
+            break;
+        }
+        case REQ_SSL_ATTRIBUTE: {
             try {
                 if (sslSupport != null) {
                     Object sslO = sslSupport.getCipherSuite();
@@ -432,10 +433,10 @@ public class Http11NioProcessor extends 
             } catch (Exception e) {
                 log.warn(sm.getString("http11processor.socket.ssl"), e);
             }
-
-        } else if (actionCode == ActionCode.REQ_SSL_CERTIFICATE) {
-
-            if( sslSupport != null) {
+            break;
+        }
+        case REQ_SSL_CERTIFICATE: {
+            if (sslSupport != null) {
                 /*
                  * Consume and buffer the request body, so that it does not
                  * interfere with the client's handshake messages
@@ -472,11 +473,17 @@ public class Http11NioProcessor extends 
                     log.warn(sm.getString("http11processor.socket.ssl"), e);
                 }
             }
-        } else if (actionCode == ActionCode.COMET_BEGIN) {
+            break;
+        }
+        case COMET_BEGIN: {
             comet = true;
-        } else if (actionCode == ActionCode.COMET_END) {
+            break;
+        }
+        case COMET_END: {
             comet = false;
-        } else if (actionCode == ActionCode.COMET_CLOSE) {
+            break;
+        }
+        case COMET_CLOSE: {
             if (socketWrapper==null || socketWrapper.getSocket().getAttachment(false)==null)
{
                 return;
             }
@@ -487,7 +494,9 @@ public class Http11NioProcessor extends 
                 // an application controlled thread) or similar.
                 socketWrapper.getSocket().getPoller().add(socketWrapper.getSocket());
             }
-        } else if (actionCode == ActionCode.COMET_SETTIMEOUT) {
+            break;
+        }
+        case COMET_SETTIMEOUT: {
             if (param==null) {
                 return;
             }
@@ -501,6 +510,8 @@ public class Http11NioProcessor extends 
             if ( rp.getStage() != org.apache.coyote.Constants.STAGE_SERVICE ) {
                 attach.setTimeout(timeout);
             }
+            break;
+        }
         }
     }
 

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=1599393&r1=1599392&r2=1599393&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11Processor.java Mon Jun  2 23:40:11 2014
@@ -232,11 +232,12 @@ public class Http11Processor extends Abs
      * @param actionCode Type of the action
      * @param param Action parameter
      */
+    @SuppressWarnings("incomplete-switch") // Other cases are handled by action()
     @Override
     public void actionInternal(ActionCode actionCode, Object param) {
 
-        if (actionCode == ActionCode.REQ_SSL_ATTRIBUTE ) {
-
+        switch (actionCode) {
+        case REQ_SSL_ATTRIBUTE: {
             try {
                 if (sslSupport != null) {
                     Object sslO = sslSupport.getCipherSuite();
@@ -260,9 +261,9 @@ public class Http11Processor extends Abs
             } catch (Exception e) {
                 log.warn(sm.getString("http11processor.socket.ssl"), e);
             }
-
-        } else if (actionCode == ActionCode.REQ_HOST_ADDR_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_HOST_ADDR_ATTRIBUTE: {
             if (socketWrapper == null) {
                 request.remoteAddr().recycle();
             } else {
@@ -274,9 +275,9 @@ public class Http11Processor extends Abs
                 }
                 request.remoteAddr().setString(socketWrapper.getRemoteAddr());
             }
-
-        } else if (actionCode == ActionCode.REQ_LOCAL_NAME_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_LOCAL_NAME_ATTRIBUTE: {
             if (socketWrapper == null) {
                 request.localName().recycle();
             } else {
@@ -288,9 +289,9 @@ public class Http11Processor extends Abs
                 }
                 request.localName().setString(socketWrapper.getLocalName());
             }
-
-        } else if (actionCode == ActionCode.REQ_HOST_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_HOST_ATTRIBUTE: {
             if (socketWrapper == null) {
                 request.remoteHost().recycle();
             } else {
@@ -311,9 +312,9 @@ public class Http11Processor extends Abs
                 }
                 request.remoteHost().setString(socketWrapper.getRemoteHost());
             }
-
-        } else if (actionCode == ActionCode.REQ_LOCAL_ADDR_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_LOCAL_ADDR_ATTRIBUTE: {
             if (socketWrapper == null) {
                 request.localAddr().recycle();
             } else {
@@ -323,9 +324,9 @@ public class Http11Processor extends Abs
                 }
                 request.localAddr().setString(socketWrapper.getLocalAddr());
             }
-
-        } else if (actionCode == ActionCode.REQ_REMOTEPORT_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_REMOTEPORT_ATTRIBUTE: {
             if (socketWrapper == null) {
                 request.setRemotePort(0);
             } else {
@@ -334,9 +335,9 @@ public class Http11Processor extends Abs
                 }
                 request.setRemotePort(socketWrapper.getRemotePort());
             }
-
-        } else if (actionCode == ActionCode.REQ_LOCALPORT_ATTRIBUTE) {
-
+            break;
+        }
+        case REQ_LOCALPORT_ATTRIBUTE: {
             if (socketWrapper == null) {
                 request.setLocalPort(0);
             } else {
@@ -345,9 +346,10 @@ public class Http11Processor extends Abs
                 }
                 request.setLocalPort(socketWrapper.getLocalPort());
             }
-
-        } else if (actionCode == ActionCode.REQ_SSL_CERTIFICATE) {
-            if( sslSupport != null) {
+            break;
+        }
+        case REQ_SSL_CERTIFICATE: {
+            if (sslSupport != null) {
                 /*
                  * Consume and buffer the request body, so that it does not
                  * interfere with the client's handshake messages
@@ -367,6 +369,8 @@ public class Http11Processor extends Abs
                     log.warn(sm.getString("http11processor.socket.ssl"), e);
                 }
             }
+            break;
+        }
         }
     }
 

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1599393&r1=1599392&r2=1599393&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Mon Jun  2 23:40:11 2014
@@ -133,6 +133,10 @@
       <fix>
         Fix input concurrency issue in NIO2 upgrade. (remm)
       </fix>
+      <scode>
+        <bug>56582</bug>: Use switch(actionCode) in processors instead of a
+        chain of "elseif"s. (kkolinko)
+      </scode>
     </changelog>
   </subsection>
   <subsection name="Jasper">



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


Mime
View raw message