Author: markt
Date: Thu Jan 31 18:32:02 2019
New Revision: 1852628

URL: http://svn.apache.org/viewvc?rev=1852628&view=rev
Log:
Improve algorithm that determines if two @OnMessage annotations have been added 
for the same message type. Prior to this change some matches were missed.

Modified:
    tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: 
tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java?rev=1852628&r1=1852627&r2=1852628&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java 
(original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/pojo/PojoMethodMapping.java 
Thu Jan 31 18:32:02 2019
@@ -373,7 +373,6 @@ public class PojoMethodMapping {
         private int indexInputStream = -1;
         private int indexReader = -1;
         private int indexPrimitive = -1;
-        private Class<?> primitiveType = null;
         private Map<Integer,PojoPathParam> indexPathParams = new HashMap<>();
         private int indexPayload = -1;
         private DecoderMatch decoderMatch = null;
@@ -454,7 +453,6 @@ public class PojoMethodMapping {
                 } else if (Util.isPrimitive(types[i])) {
                     if (indexPrimitive == -1) {
                         indexPrimitive = i;
-                        primitiveType = types[i];
                     } else {
                         throw new DeploymentException(sm.getString(
                                 "pojoMethodMapping.duplicateMessageParam",
@@ -561,7 +559,6 @@ public class PojoMethodMapping {
                 // The boolean we found is a payload, not a last flag
                 indexPayload = indexBoolean;
                 indexPrimitive = indexBoolean;
-                primitiveType = Boolean.TYPE;
                 indexBoolean = -1;
             }
             if (indexPayload == -1) {
@@ -599,33 +596,26 @@ public class PojoMethodMapping {
             if (otherHandler == null) {
                 return false;
             }
-            if (indexByteArray >= 0 && otherHandler.indexByteArray >= 0) {
-                return true;
-            }
-            if (indexByteBuffer >= 0 && otherHandler.indexByteBuffer >= 0) {
-                return true;
-            }
-            if (indexInputStream >= 0 && otherHandler.indexInputStream >= 0) {
-                return true;
-            }
-            if (indexPong >= 0 && otherHandler.indexPong >= 0) {
-                return true;
-            }
-            if (indexPrimitive >= 0 && otherHandler.indexPrimitive >= 0
-                    && primitiveType == otherHandler.primitiveType) {
-                return true;
-            }
-            if (indexReader >= 0 && otherHandler.indexReader >= 0) {
-                return true;
-            }
-            if (indexString >= 0 && otherHandler.indexString >= 0) {
-                return true;
-            }
-            if (decoderMatch != null && otherHandler.decoderMatch != null
-                    && 
decoderMatch.getTarget().equals(otherHandler.decoderMatch.getTarget())) {
-                return true;
-            }
-            return false;
+
+            return isPong() && otherHandler.isPong() || isBinary() && 
otherHandler.isBinary() ||
+                    isText() && otherHandler.isText();
+        }
+
+
+        private boolean isPong() {
+            return indexPong >= 0;
+        }
+
+
+        private boolean isText() {
+            return indexString >= 0 || indexPrimitive >= 0 || indexReader >= 0 
||
+                    (decoderMatch != null && 
decoderMatch.getTextDecoders().size() > 0);
+        }
+
+
+        private boolean isBinary() {
+            return indexByteArray >= 0 || indexByteBuffer >= 0 || 
indexInputStream >= 0 ||
+                    (decoderMatch != null && 
decoderMatch.getBinaryDecoders().size() > 0);
         }
 
 

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1852628&r1=1852627&r2=1852628&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Jan 31 18:32:02 2019
@@ -217,6 +217,11 @@
         with <code>@OnMessage</code> does not conform to the requirements set
         out in the Javadoc. (mark)
       </fix>
+      <fix>
+        Improve algorithm that determines if two <code>@OnMessage</code>
+        annotations have been added for the same message type. Prior to this
+        change some matches were missed. (markt) 
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Web applications">



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

Reply via email to