Author: markt
Date: Wed Dec 28 20:40:39 2011
New Revision: 1225327

URL: http://svn.apache.org/viewvc?rev=1225327&view=rev
Log:
Resolve Eclipse warnings in o.a.tomcat.net package

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/net/NioChannel.java
    tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/util/net/SecureNioChannel.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioChannel.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioChannel.java?rev=1225327&r1=1225326&r2=1225327&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioChannel.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioChannel.java Wed Dec 28 
20:40:39 2011
@@ -14,8 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-
 package org.apache.tomcat.util.net;
 
 import java.io.IOException;
@@ -38,7 +36,7 @@ import org.apache.tomcat.util.net.Secure
  * @author Filip Hanik
  * @version 1.0
  */
-public class NioChannel implements ByteChannel{
+public class NioChannel implements ByteChannel {
 
     protected static ByteBuffer emptyBuf = ByteBuffer.allocate(0);
 
@@ -50,11 +48,16 @@ public class NioChannel implements ByteC
 
     protected boolean sendFile = false;
 
-    public NioChannel(SocketChannel channel, ApplicationBufferHandler 
bufHandler) throws IOException {
+    public NioChannel(SocketChannel channel, ApplicationBufferHandler 
bufHandler) {
         this.sc = channel;
         this.bufHandler = bufHandler;
     }
 
+    /**
+     * Reset the channel
+     *
+     * @throws IOException If a problem was encountered resetting the channel
+     */
     public void reset() throws IOException {
         bufHandler.getReadBuffer().clear();
         bufHandler.getWriteBuffer().clear();
@@ -70,11 +73,17 @@ public class NioChannel implements ByteC
     }
 
     /**
-     * returns true if the network buffer has
-     * been flushed out and is empty
-     * @return boolean
+     * Returns true if the network buffer has been flushed out and is empty.
+     *
+     * @param block     Unused. May be used when overridden
+     * @param s         Unused. May be used when overridden
+     * @param timeout   Unused. May be used when overridden
+     * @param lastWrite
+     * @return
+     * @throws IOException
      */
-    public boolean flush(boolean block, Selector s, long 
timeout,MutableInteger lastWrite) throws IOException {
+    public boolean flush(boolean block, Selector s, long timeout,
+            MutableInteger lastWrite) throws IOException {
         if (lastWrite!=null) lastWrite.set(1);
         return true; //no network buffer in the regular channel
     }
@@ -182,6 +191,15 @@ public class NioChannel implements ByteC
         return true;
     }
 
+    /**
+     * Performs SSL handshake hence is a no-op for the non-secure
+     * implementation.
+     *
+     * @param read  Unused in non-secure implementation
+     * @param write Unused in non-secure implementation
+     * @return Always returns zero
+     * @throws IOException
+     */
     public int handshake(boolean read, boolean write) throws IOException {
         return 0;
     }

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=1225327&r1=1225326&r2=1225327&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Wed Dec 28 
20:40:39 2011
@@ -901,10 +901,10 @@ public class NioEndpoint extends Abstrac
                     } else {
                         cancel = true;
                     }
-                    if ( cancel ) 
socket.getPoller().cancelledKey(key,SocketStatus.ERROR,false);
+                    if ( cancel ) 
socket.getPoller().cancelledKey(key,SocketStatus.ERROR);
                 }catch (CancelledKeyException ckx) {
                     try {
-                        
socket.getPoller().cancelledKey(key,SocketStatus.DISCONNECT,true);
+                        
socket.getPoller().cancelledKey(key,SocketStatus.DISCONNECT);
                     }catch (Exception ignore) {}
                 }
             }//end if
@@ -1028,20 +1028,19 @@ public class NioEndpoint extends Abstrac
             else r.reset(socket,ka,OP_REGISTER);
             addEvent(r);
         }
-        public void cancelledKey(SelectionKey key, SocketStatus status, 
boolean dispatch) {
+        public void cancelledKey(SelectionKey key, SocketStatus status) {
             try {
                 if ( key == null ) return;//nothing to do
                 KeyAttachment ka = (KeyAttachment) key.attachment();
                 if (ka != null && ka.getComet() && status != null) {
-                    //the comet event takes care of clean up
-                    //processSocket(ka.getChannel(), status, dispatch);
                     ka.setComet(false);//to avoid a loop
                     if (status == SocketStatus.TIMEOUT ) {
                         if (processSocket(ka.getChannel(), status, true)) {
                             return; // don't close on comet timeout
                         }
                     } else {
-                        processSocket(ka.getChannel(), status, false); //don't 
dispatch if the lines below are cancelling the key
+                        // Don't dispatch if the lines below are canceling the 
key
+                        processSocket(ka.getChannel(), status, false);
                     }
                 }
                 key.attach(null);
@@ -1191,7 +1190,7 @@ public class NioEndpoint extends Abstrac
             boolean result = true;
             try {
                 if ( close ) {
-                    cancelledKey(sk, SocketStatus.STOP, attachment.comet);
+                    cancelledKey(sk, SocketStatus.STOP);
                 } else if ( sk.isValid() && attachment != null ) {
                     attachment.access();//make sure we don't time out valid 
sockets
                     sk.attach(attachment);//cant remember why this is here
@@ -1224,7 +1223,7 @@ public class NioEndpoint extends Abstrac
                                 unreg(sk, attachment,sk.readyOps());
                                 boolean close = (!processSocket(channel, null, 
true));
                                 if (close) {
-                                    
cancelledKey(sk,SocketStatus.DISCONNECT,false);
+                                    cancelledKey(sk,SocketStatus.DISCONNECT);
                                 }
                             } else {
                                 result = false;
@@ -1233,10 +1232,10 @@ public class NioEndpoint extends Abstrac
                     }
                 } else {
                     //invalid key
-                    cancelledKey(sk, SocketStatus.ERROR,false);
+                    cancelledKey(sk, SocketStatus.ERROR);
                 }
             } catch ( CancelledKeyException ckx ) {
-                cancelledKey(sk, SocketStatus.ERROR,false);
+                cancelledKey(sk, SocketStatus.ERROR);
             } catch (Throwable t) {
                 ExceptionUtils.handleThrowable(t);
                 log.error("",t);
@@ -1252,7 +1251,7 @@ public class NioEndpoint extends Abstrac
                 if ( sd.fchannel == null ) {
                     File f = new File(sd.fileName);
                     if ( !f.exists() ) {
-                        cancelledKey(sk,SocketStatus.ERROR,false);
+                        cancelledKey(sk,SocketStatus.ERROR);
                         return false;
                     }
                     sd.fchannel = new FileInputStream(f).getChannel();
@@ -1304,7 +1303,7 @@ public class NioEndpoint extends Abstrac
                         if (log.isDebugEnabled()) {
                             log.debug("Send file connection is being closed");
                         }
-                        cancelledKey(sk,SocketStatus.STOP,false);
+                        cancelledKey(sk,SocketStatus.STOP);
                         return false;
                     }
                 } else if ( attachment.interestOps() == 0 && reg ) {
@@ -1319,11 +1318,11 @@ public class NioEndpoint extends Abstrac
                 }
             }catch ( IOException x ) {
                 if ( log.isDebugEnabled() ) log.debug("Unable to complete 
sendfile request:", x);
-                cancelledKey(sk,SocketStatus.ERROR,false);
+                cancelledKey(sk,SocketStatus.ERROR);
                 return false;
             }catch ( Throwable t ) {
                 log.error("",t);
-                cancelledKey(sk, SocketStatus.ERROR, false);
+                cancelledKey(sk, SocketStatus.ERROR);
                 return false;
             }finally {
                 if (sc!=null) sc.setSendFile(false);
@@ -1360,9 +1359,9 @@ public class NioEndpoint extends Abstrac
                 try {
                     KeyAttachment ka = (KeyAttachment) key.attachment();
                     if ( ka == null ) {
-                        cancelledKey(key, SocketStatus.ERROR,false); //we 
don't support any keys without attachments
+                        cancelledKey(key, SocketStatus.ERROR); //we don't 
support any keys without attachments
                     } else if ( ka.getError() ) {
-                        cancelledKey(key, SocketStatus.ERROR,true);//TODO this 
is not yet being used
+                        cancelledKey(key, SocketStatus.ERROR);//TODO this is 
not yet being used
                     } else if (ka.getComet() && ka.getCometNotify() ) {
                         ka.setCometNotify(false);
                         reg(key,ka,0);//avoid multiple calls, this gets 
reregistered after invocation
@@ -1381,7 +1380,7 @@ public class NioEndpoint extends Abstrac
                         } else if (isTimedout) {
                             key.interestOps(0);
                             ka.interestOps(0); //avoid duplicate timeout calls
-                            cancelledKey(key, SocketStatus.TIMEOUT,true);
+                            cancelledKey(key, SocketStatus.TIMEOUT);
                         } else if (timeout > -1) {
                             long nextTime = now+(timeout-delta);
                             nextExpiration = (nextTime < 
nextExpiration)?nextTime:nextExpiration;
@@ -1400,7 +1399,7 @@ public class NioEndpoint extends Abstrac
                         }
                     }//end if
                 }catch ( CancelledKeyException ckx ) {
-                    cancelledKey(key, SocketStatus.ERROR,false);
+                    cancelledKey(key, SocketStatus.ERROR);
                 }
             }//for
             if ( log.isTraceEnabled() ) log.trace("timeout completed: keys 
processed="+keycount+"; now="+now+"; nextExpiration="+prevExp+"; "+
@@ -1568,6 +1567,7 @@ public class NioEndpoint extends Abstrac
             this.status = status;
         }
 
+        @SuppressWarnings("null") // key
         @Override
         public void run() {
             boolean launch = false;
@@ -1588,6 +1588,8 @@ public class NioEndpoint extends Abstrac
                     if ( handshake == 0 ) {
                         SocketState state = SocketState.OPEN;
                         // Process the request from this socket
+                        // Suppress null warnings for key in this block since
+                        // key can't be null in this block
                         if (status == null) {
                             state = handler.process(
                                     (KeyAttachment) key.attachment(),
@@ -1601,12 +1603,9 @@ public class NioEndpoint extends Abstrac
                         if (state == SocketState.CLOSED) {
                             // Close socket and pool
                             try {
-                                KeyAttachment ka = null;
-                                if (key!=null) {
-                                    ka = (KeyAttachment) key.attachment();
-                                    if (ka!=null) ka.setComet(false);
-                                    socket.getPoller().cancelledKey(key, 
SocketStatus.ERROR, false);
-                                }
+                                KeyAttachment ka = (KeyAttachment) 
key.attachment();
+                                if (ka!=null) ka.setComet(false);
+                                socket.getPoller().cancelledKey(key, 
SocketStatus.ERROR);
                                 nioChannels.offer(socket);
                                 socket = null;
                                 if ( ka!=null ) keyCache.offer(ka);
@@ -1619,7 +1618,7 @@ public class NioEndpoint extends Abstrac
                         KeyAttachment ka = null;
                         if (key!=null) {
                             ka = (KeyAttachment) key.attachment();
-                            socket.getPoller().cancelledKey(key, 
SocketStatus.DISCONNECT, false);
+                            socket.getPoller().cancelledKey(key, 
SocketStatus.DISCONNECT);
                         }
                         nioChannels.offer(socket);
                         socket = null;
@@ -1632,11 +1631,11 @@ public class NioEndpoint extends Abstrac
                         ka.getPoller().add(socket,intops);
                     }
                 }catch(CancelledKeyException cx) {
-                    socket.getPoller().cancelledKey(key,null,false);
+                    socket.getPoller().cancelledKey(key,null);
                 } catch (OutOfMemoryError oom) {
                     try {
                         oomParachuteData = null;
-                        
socket.getPoller().cancelledKey(key,SocketStatus.ERROR,false);
+                        
socket.getPoller().cancelledKey(key,SocketStatus.ERROR);
                         releaseCaches();
                         log.error("", oom);
                     }catch ( Throwable oomt ) {
@@ -1649,7 +1648,7 @@ public class NioEndpoint extends Abstrac
                     }
                 }catch ( Throwable t ) {
                     log.error("",t);
-                    
socket.getPoller().cancelledKey(key,SocketStatus.ERROR,false);
+                    socket.getPoller().cancelledKey(key,SocketStatus.ERROR);
                 } finally {
                     if (launch) {
                         try {

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SecureNioChannel.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SecureNioChannel.java?rev=1225327&r1=1225326&r2=1225327&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/SecureNioChannel.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/SecureNioChannel.java Wed Dec 
28 20:40:39 2011
@@ -105,12 +105,18 @@ public class SecureNioChannel extends Ni
 //                  NIO SSL METHODS
 
//===========================================================================================
     /**
-     * returns true if the network buffer has
-     * been flushed out and is empty
-     * @return boolean
+     * Returns true if the network buffer has been flushed out and is empty.
+     *
+     * @param block     Should a blocking write be used?
+     * @param s
+     * @param timeout
+     * @param lastWrite
+     * @return
+     * @throws IOException
      */
     @Override
-    public boolean flush(boolean block, Selector s, long 
timeout,MutableInteger lastWrite) throws IOException {
+    public boolean flush(boolean block, Selector s, long timeout,
+            MutableInteger lastWrite) throws IOException {
         if (!block) {
             flush(netOutBuffer);
         } else {
@@ -218,6 +224,7 @@ public class SecureNioChannel extends Ni
      * @throws IOException - if an IO exception occurs or if application or 
network buffers contain data
      * @throws SocketTimeoutException - if a socket operation timed out
      */
+    @SuppressWarnings("null") // key cannot be null
     public void rehandshake(long timeout) throws IOException {
         //validate the network buffers are empty
         if (netInBuffer.position() > 0 && 
netInBuffer.position()<netInBuffer.limit()) throw new IOException("Network 
input buffer still contains data. Handshake will fail.");
@@ -247,7 +254,7 @@ public class SecureNioChannel extends Ni
                             }
                             key = getIOChannel().register(selector, hsStatus);
                         } else {
-                            key.interestOps(hsStatus);
+                            key.interestOps(hsStatus); // null warning 
supressed
                         }
                         int keyCount = selector.select(timeout);
                         if (keyCount == 0 && ((System.currentTimeMillis()-now) 
>= timeout)) {



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

Reply via email to