Author: kkolinko
Date: Sun Oct 19 18:23:07 2014
New Revision: 1632965

URL: http://svn.apache.org/r1632965
Log:
Further improve processing of null arguments in remote endpoint (followup to 
r1632625):
1) Document IllegalArgumentException in javadoc
2) Handle null arguments in sendObject() methods to throw 
IllegalArgumentException instead of NPE.

Modified:
    tomcat/trunk/java/javax/websocket/PongMessage.java
    tomcat/trunk/java/javax/websocket/RemoteEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/javax/websocket/PongMessage.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/PongMessage.java?rev=1632965&r1=1632964&r2=1632965&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/PongMessage.java (original)
+++ tomcat/trunk/java/javax/websocket/PongMessage.java Sun Oct 19 18:23:07 2014
@@ -24,7 +24,7 @@ import java.nio.ByteBuffer;
  */
 public interface PongMessage {
     /**
-     * Get the payload of the Pong message..
+     * Get the payload of the Pong message.
      *
      * @return  The payload of the Pong message.
      */

Modified: tomcat/trunk/java/javax/websocket/RemoteEndpoint.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/websocket/RemoteEndpoint.java?rev=1632965&r1=1632964&r2=1632965&view=diff
==============================================================================
--- tomcat/trunk/java/javax/websocket/RemoteEndpoint.java (original)
+++ tomcat/trunk/java/javax/websocket/RemoteEndpoint.java Sun Oct 19 18:23:07 
2014
@@ -68,6 +68,7 @@ public interface RemoteEndpoint {
          * when the message has been sent.
          * @param data          The text message to send
          * @return A Future that signals when the message has been sent.
+         * @throws IllegalArgumentException if {@code data} is {@code null}.
          */
         Future<Void> sendBinary(ByteBuffer data);
 
@@ -77,11 +78,29 @@ public interface RemoteEndpoint {
          * @param data          The text message to send
          * @param completion    Used to signal to the client when the message 
has
          *                      been sent
+         * @throws IllegalArgumentException if {@code data} or {@code 
completion}
+         *                      is {@code null}.
          */
         void sendBinary(ByteBuffer data, SendHandler completion);
 
+        /**
+         * Encodes object as a message and sends it asynchronously, using the
+         * Future to signal to the client when the message has been sent.
+         * @param obj           The object to be sent.
+         * @return A Future that signals when the message has been sent.
+         * @throws IllegalArgumentException if {@code obj} is {@code null}.
+         */
         Future<Void> sendObject(Object obj);
 
+        /**
+         * Encodes object as a message and sends it asynchronously, using the
+         * SendHandler to signal to the client when the message has been sent.
+         * @param obj           The object to be sent.
+         * @param completion    Used to signal to the client when the message 
has
+         *                      been sent
+         * @throws IllegalArgumentException if {@code obj} or
+         *                      {@code completion} is {@code null}.
+         */
         void sendObject(Object obj, SendHandler completion);
 
     }
@@ -91,6 +110,7 @@ public interface RemoteEndpoint {
         /**
          * Send the message, blocking until the message is sent.
          * @param text  The text message to send.
+         * @throws IllegalArgumentException if {@code text} is {@code null}.
          * @throws IOException if an I/O error occurs during the sending of the
          *                     message.
          */
@@ -99,6 +119,7 @@ public interface RemoteEndpoint {
         /**
          * Send the message, blocking until the message is sent.
          * @param data  The binary message to send
+         * @throws IllegalArgumentException if {@code data} is {@code null}.
          * @throws IOException if an I/O error occurs during the sending of the
          *                     message.
          */
@@ -112,6 +133,7 @@ public interface RemoteEndpoint {
          * @param fragment  The partial message to send
          * @param isLast    <code>true</code> if this is the last part of the
          *                  message, otherwise <code>false</code>
+         * @throws IllegalArgumentException if {@code fragment} is {@code 
null}.
          * @throws IOException if an I/O error occurs during the sending of the
          *                     message.
          */
@@ -125,6 +147,8 @@ public interface RemoteEndpoint {
          * @param partialByte   The partial message to send
          * @param isLast        <code>true</code> if this is the last part of 
the
          *                      message, otherwise <code>false</code>
+         * @throws IllegalArgumentException if {@code partialByte} is
+         *                     {@code null}.
          * @throws IOException if an I/O error occurs during the sending of the
          *                     message.
          */
@@ -134,7 +158,16 @@ public interface RemoteEndpoint {
 
         Writer getSendWriter() throws IOException;
 
-        void sendObject(Object o) throws IOException, EncodeException;
+        /**
+         * Encodes object as a message and sends it to the remote endpoint.
+         * @param data  The object to be sent.
+         * @throws EncodeException if there was a problem encoding the
+         *                     {@code data} object as a websocket message.
+         * @throws IllegalArgumentException if {@code data} is {@code null}.
+         * @throws IOException if an I/O error occurs during the sending of the
+         *                     message.
+         */
+        void sendObject(Object data) throws IOException, EncodeException;
 
     }
     /**

Modified: 
tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java?rev=1632965&r1=1632964&r2=1632965&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java 
Sun Oct 19 18:23:07 2014
@@ -528,6 +528,13 @@ public abstract class WsRemoteEndpointIm
     @SuppressWarnings({"unchecked", "rawtypes"})
     public void sendObjectByCompletion(Object obj, SendHandler completion) {
 
+        if (obj == null) {
+            throw new 
IllegalArgumentException(sm.getString("wsRemoteEndpoint.nullData"));
+        }
+        if (completion == null) {
+            throw new 
IllegalArgumentException(sm.getString("wsRemoteEndpoint.nullHandler"));
+        }
+
         if (Util.isPrimitive(obj.getClass())) {
             String msg = obj.toString();
             sendStringByCompletion(msg, completion);

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1632965&r1=1632964&r2=1632965&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Sun Oct 19 18:23:07 2014
@@ -213,7 +213,7 @@
         Fix client subprotocol handling. (remm)
       </fix>
       <fix>
-        Add null checks for arguments in remote endpoint. (remm)
+        Add null checks for arguments in remote endpoint. (remm/kkolinko)
       </fix>
     </changelog>
   </subsection>



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

Reply via email to