You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2021/07/16 14:11:58 UTC

[tomcat] branch 8.5.x updated (b363fba -> 666ef0b)

This is an automated email from the ASF dual-hosted git repository.

markt pushed a change to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git.


    from b363fba  Fix typo (#433)
     new 3ae14e0  Refactor. Internal rename only to support upcoming changes.
     new 666ef0b  Additional fix for BZ 65358

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 java/javax/el/Util.java                            | 88 +++++++++++++---------
 java/org/apache/el/util/ReflectionUtil.java        | 84 ++++++++++++---------
 test/org/apache/el/TestMethodExpressionImpl.java   | 13 ++++
 .../el/{TesterBeanEnum.java => TesterBeanI.java}   | 13 ++--
 4 files changed, 119 insertions(+), 79 deletions(-)
 copy test/org/apache/el/{TesterBeanEnum.java => TesterBeanI.java} (75%)

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


[tomcat] 02/02: Additional fix for BZ 65358

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 666ef0b11d9d8c7f4f389e0bea394630f6a4f104
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Jul 16 15:00:18 2021 +0100

    Additional fix for BZ 65358
    
    https://bz.apache.org/bugzilla/show_bug.cgi?id=65358
    A method that does not declare varargs should always be preferred to a
    method that does
---
 java/javax/el/Util.java                          | 40 ++++++++++++++++--------
 java/org/apache/el/util/ReflectionUtil.java      | 40 ++++++++++++++++--------
 test/org/apache/el/TestMethodExpressionImpl.java | 13 ++++++++
 test/org/apache/el/TesterBeanI.java              | 29 +++++++++++++++++
 4 files changed, 96 insertions(+), 26 deletions(-)

diff --git a/java/javax/el/Util.java b/java/javax/el/Util.java
index 5d695f8..0b41196 100644
--- a/java/javax/el/Util.java
+++ b/java/javax/el/Util.java
@@ -335,12 +335,13 @@ class Util {
                 return w;
             }
 
-            candidates.put(w, new MatchResult(exactMatch, assignableMatch, coercibleMatch, varArgsMatch, w.isBridge()));
+            candidates.put(w, new MatchResult(
+                    w.isVarArgs(), exactMatch, assignableMatch, coercibleMatch, varArgsMatch, w.isBridge()));
         }
 
         // Look for the method that has the highest number of parameters where
         // the type matches exactly
-        MatchResult bestMatch = new MatchResult(0, 0, 0, 0, false);
+        MatchResult bestMatch = new MatchResult(true, 0, 0, 0, 0, true);
         Wrapper<T> match = null;
         boolean multiple = false;
         for (Map.Entry<Wrapper<T>, MatchResult> entry : candidates.entrySet()) {
@@ -755,13 +756,16 @@ class Util {
      */
     private static class MatchResult implements Comparable<MatchResult> {
 
+        private final boolean varArgs;
         private final int exactCount;
         private final int assignableCount;
         private final int coercibleCount;
         private final int varArgsCount;
         private final boolean bridge;
 
-        public MatchResult(int exactCount, int assignableCount, int coercibleCount, int varArgsCount, boolean bridge) {
+        public MatchResult(boolean varArgs, int exactCount, int assignableCount, int coercibleCount, int varArgsCount,
+                boolean bridge) {
+            this.varArgs = varArgs;
             this.exactCount = exactCount;
             this.assignableCount = assignableCount;
             this.coercibleCount = coercibleCount;
@@ -769,6 +773,10 @@ class Util {
             this.bridge = bridge;
         }
 
+        public boolean isVarArgs() {
+            return varArgs;
+        }
+
         public int getExactCount() {
             return exactCount;
         }
@@ -791,20 +799,24 @@ class Util {
 
         @Override
         public int compareTo(MatchResult o) {
-            int cmp = Integer.compare(this.getExactCount(), o.getExactCount());
+            // Non-varArgs always beats varArgs
+            int cmp = Boolean.compare(o.isVarArgs(), this.isVarArgs());
             if (cmp == 0) {
-                cmp = Integer.compare(this.getAssignableCount(), o.getAssignableCount());
+                cmp = Integer.compare(this.getExactCount(), o.getExactCount());
                 if (cmp == 0) {
-                    cmp = Integer.compare(this.getCoercibleCount(), o.getCoercibleCount());
+                    cmp = Integer.compare(this.getAssignableCount(), o.getAssignableCount());
                     if (cmp == 0) {
-                        // Fewer var args matches are better
-                        cmp = Integer.compare(o.getVarArgsCount(), this.getVarArgsCount());
+                        cmp = Integer.compare(this.getCoercibleCount(), o.getCoercibleCount());
                         if (cmp == 0) {
-                            // The nature of bridge methods is such that it actually
-                            // doesn't matter which one we pick as long as we pick
-                            // one. That said, pick the 'right' one (the non-bridge
-                            // one) anyway.
-                            cmp = Boolean.compare(o.isBridge(), this.isBridge());
+                            // Fewer var args matches are better
+                            cmp = Integer.compare(o.getVarArgsCount(), this.getVarArgsCount());
+                            if (cmp == 0) {
+                                // The nature of bridge methods is such that it actually
+                                // doesn't matter which one we pick as long as we pick
+                                // one. That said, pick the 'right' one (the non-bridge
+                                // one) anyway.
+                                cmp = Boolean.compare(o.isBridge(), this.isBridge());
+                            }
                         }
                     }
                 }
@@ -820,6 +832,7 @@ class Util {
                     ((MatchResult)o).getAssignableCount() == this.getAssignableCount() &&
                     ((MatchResult)o).getCoercibleCount() == this.getCoercibleCount() &&
                     ((MatchResult)o).getVarArgsCount() == this.getVarArgsCount() &&
+                    ((MatchResult)o).isVarArgs() == this.isVarArgs() &&
                     ((MatchResult)o).isBridge() == this.isBridge());
         }
 
@@ -831,6 +844,7 @@ class Util {
             result = prime * result + (bridge ? 1231 : 1237);
             result = prime * result + coercibleCount;
             result = prime * result + exactCount;
+            result = prime * result + (varArgs ? 1231 : 1237);
             result = prime * result + varArgsCount;
             return result;
         }
diff --git a/java/org/apache/el/util/ReflectionUtil.java b/java/org/apache/el/util/ReflectionUtil.java
index df1c750..c1162d1 100644
--- a/java/org/apache/el/util/ReflectionUtil.java
+++ b/java/org/apache/el/util/ReflectionUtil.java
@@ -255,12 +255,13 @@ public class ReflectionUtil {
                 return getMethod(base.getClass(), base, m);
             }
 
-            candidates.put(m, new MatchResult(exactMatch, assignableMatch, coercibleMatch, varArgsMatch, m.isBridge()));
+            candidates.put(m, new MatchResult(
+                    m.isVarArgs(), exactMatch, assignableMatch, coercibleMatch, varArgsMatch, m.isBridge()));
         }
 
         // Look for the method that has the highest number of parameters where
         // the type matches exactly
-        MatchResult bestMatch = new MatchResult(0, 0, 0, 0, false);
+        MatchResult bestMatch = new MatchResult(true, 0, 0, 0, 0, true);
         Method match = null;
         boolean multiple = false;
         for (Map.Entry<Method, MatchResult> entry : candidates.entrySet()) {
@@ -511,13 +512,16 @@ public class ReflectionUtil {
      */
     private static class MatchResult implements Comparable<MatchResult> {
 
+        private final boolean varArgs;
         private final int exactCount;
         private final int assignableCount;
         private final int coercibleCount;
         private final int varArgsCount;
         private final boolean bridge;
 
-        public MatchResult(int exactCount, int assignableCount, int coercibleCount, int varArgsCount, boolean bridge) {
+        public MatchResult(boolean varArgs, int exactCount, int assignableCount, int coercibleCount, int varArgsCount,
+                boolean bridge) {
+            this.varArgs = varArgs;
             this.exactCount = exactCount;
             this.assignableCount = assignableCount;
             this.coercibleCount = coercibleCount;
@@ -525,6 +529,10 @@ public class ReflectionUtil {
             this.bridge = bridge;
         }
 
+        public boolean isVarArgs() {
+            return varArgs;
+        }
+
         public int getExactCount() {
             return exactCount;
         }
@@ -547,20 +555,24 @@ public class ReflectionUtil {
 
         @Override
         public int compareTo(MatchResult o) {
-            int cmp = Integer.compare(this.getExactCount(), o.getExactCount());
+            // Non-varArgs always beats varArgs
+            int cmp = Boolean.compare(o.isVarArgs(), this.isVarArgs());
             if (cmp == 0) {
-                cmp = Integer.compare(this.getAssignableCount(), o.getAssignableCount());
+                cmp = Integer.compare(this.getExactCount(), o.getExactCount());
                 if (cmp == 0) {
-                    cmp = Integer.compare(this.getCoercible(), o.getCoercible());
+                    cmp = Integer.compare(this.getAssignableCount(), o.getAssignableCount());
                     if (cmp == 0) {
-                        // Fewer var args matches are better
-                        cmp = Integer.compare(o.getVarArgsCount(), this.getVarArgsCount());
+                        cmp = Integer.compare(this.getCoercible(), o.getCoercible());
                         if (cmp == 0) {
-                            // The nature of bridge methods is such that it actually
-                            // doesn't matter which one we pick as long as we pick
-                            // one. That said, pick the 'right' one (the non-bridge
-                            // one) anyway.
-                            cmp = Boolean.compare(o.isBridge(), this.isBridge());
+                            // Fewer var args matches are better
+                            cmp = Integer.compare(o.getVarArgsCount(), this.getVarArgsCount());
+                            if (cmp == 0) {
+                                // The nature of bridge methods is such that it actually
+                                // doesn't matter which one we pick as long as we pick
+                                // one. That said, pick the 'right' one (the non-bridge
+                                // one) anyway.
+                                cmp = Boolean.compare(o.isBridge(), this.isBridge());
+                            }
                         }
                     }
                 }
@@ -576,6 +588,7 @@ public class ReflectionUtil {
                     ((MatchResult)o).getAssignableCount() == this.getAssignableCount() &&
                     ((MatchResult)o).getCoercible() == this.getCoercible() &&
                     ((MatchResult)o).getVarArgsCount() == this.getVarArgsCount() &&
+                    ((MatchResult)o).isVarArgs() == this.isVarArgs() &&
                     ((MatchResult)o).isBridge() == this.isBridge());
         }
 
@@ -587,6 +600,7 @@ public class ReflectionUtil {
             result = prime * result + (bridge ? 1231 : 1237);
             result = prime * result + coercibleCount;
             result = prime * result + exactCount;
+            result = prime * result + (varArgs ? 1231 : 1237);
             result = prime * result + varArgsCount;
             return result;
         }
diff --git a/test/org/apache/el/TestMethodExpressionImpl.java b/test/org/apache/el/TestMethodExpressionImpl.java
index 3d88a96..3d55a25 100644
--- a/test/org/apache/el/TestMethodExpressionImpl.java
+++ b/test/org/apache/el/TestMethodExpressionImpl.java
@@ -897,7 +897,20 @@ public class TestMethodExpressionImpl {
         Assert.assertEquals(javaResult, elResult);
     }
 
+
     private static interface Function<T, R> {
         public R apply(T t);
     }
+
+
+    @Test
+    public void testPreferNoVarArgs() {
+        ELProcessor elp = new ELProcessor();
+        TesterBeanAAA bean = new TesterBeanAAA();
+        bean.setName("xyz");
+        elp.defineBean("bean2", bean);
+        elp.defineBean("bean1", new TesterBeanI());
+        String elResult = (String) elp.eval("bean1.echo(bean2)");
+        Assert.assertEquals("No varargs: xyz", elResult);
+    }
 }
diff --git a/test/org/apache/el/TesterBeanI.java b/test/org/apache/el/TesterBeanI.java
new file mode 100644
index 0000000..9372fc1
--- /dev/null
+++ b/test/org/apache/el/TesterBeanI.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.el;
+
+public class TesterBeanI {
+
+    public String echo(TesterBeanA beanA) {
+        return "No varargs: " + beanA.getName();
+    }
+
+
+    public String echo(TesterBeanAAA beanAAA, @SuppressWarnings("unused") String... extras) {
+        return "With varargs: " + beanAAA.getName();
+    }
+}

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


[tomcat] 01/02: Refactor. Internal rename only to support upcoming changes.

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 3ae14e039b7e32c22cfc62ae11a013d3cbc83c3b
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Jul 16 14:45:35 2021 +0100

    Refactor. Internal rename only to support upcoming changes.
---
 java/javax/el/Util.java                     | 60 ++++++++++++++---------------
 java/org/apache/el/util/ReflectionUtil.java | 54 +++++++++++++-------------
 2 files changed, 57 insertions(+), 57 deletions(-)

diff --git a/java/javax/el/Util.java b/java/javax/el/Util.java
index 383e9b5..5d695f8 100644
--- a/java/javax/el/Util.java
+++ b/java/javax/el/Util.java
@@ -354,7 +354,7 @@ class Util {
             }
         }
         if (multiple) {
-            if (bestMatch.getExact() == paramCount - 1) {
+            if (bestMatch.getExactCount() == paramCount - 1) {
                 // Only one parameter is not an exact match - try using the
                 // super class
                 match = resolveAmbiguousWrapper(candidates.keySet(), paramTypes);
@@ -755,34 +755,34 @@ class Util {
      */
     private static class MatchResult implements Comparable<MatchResult> {
 
-        private final int exact;
-        private final int assignable;
-        private final int coercible;
-        private final int varArgs;
+        private final int exactCount;
+        private final int assignableCount;
+        private final int coercibleCount;
+        private final int varArgsCount;
         private final boolean bridge;
 
-        public MatchResult(int exact, int assignable, int coercible, int varArgs, boolean bridge) {
-            this.exact = exact;
-            this.assignable = assignable;
-            this.coercible = coercible;
-            this.varArgs = varArgs;
+        public MatchResult(int exactCount, int assignableCount, int coercibleCount, int varArgsCount, boolean bridge) {
+            this.exactCount = exactCount;
+            this.assignableCount = assignableCount;
+            this.coercibleCount = coercibleCount;
+            this.varArgsCount = varArgsCount;
             this.bridge = bridge;
         }
 
-        public int getExact() {
-            return exact;
+        public int getExactCount() {
+            return exactCount;
         }
 
-        public int getAssignable() {
-            return assignable;
+        public int getAssignableCount() {
+            return assignableCount;
         }
 
-        public int getCoercible() {
-            return coercible;
+        public int getCoercibleCount() {
+            return coercibleCount;
         }
 
-        public int getVarArgs() {
-            return varArgs;
+        public int getVarArgsCount() {
+            return varArgsCount;
         }
 
         public boolean isBridge() {
@@ -791,14 +791,14 @@ class Util {
 
         @Override
         public int compareTo(MatchResult o) {
-            int cmp = Integer.compare(this.getExact(), o.getExact());
+            int cmp = Integer.compare(this.getExactCount(), o.getExactCount());
             if (cmp == 0) {
-                cmp = Integer.compare(this.getAssignable(), o.getAssignable());
+                cmp = Integer.compare(this.getAssignableCount(), o.getAssignableCount());
                 if (cmp == 0) {
-                    cmp = Integer.compare(this.getCoercible(), o.getCoercible());
+                    cmp = Integer.compare(this.getCoercibleCount(), o.getCoercibleCount());
                     if (cmp == 0) {
                         // Fewer var args matches are better
-                        cmp = Integer.compare(o.getVarArgs(), this.getVarArgs());
+                        cmp = Integer.compare(o.getVarArgsCount(), this.getVarArgsCount());
                         if (cmp == 0) {
                             // The nature of bridge methods is such that it actually
                             // doesn't matter which one we pick as long as we pick
@@ -816,10 +816,10 @@ class Util {
         public boolean equals(Object o) {
             return o == this || (null != o &&
                     this.getClass().equals(o.getClass()) &&
-                    ((MatchResult)o).getExact() == this.getExact() &&
-                    ((MatchResult)o).getAssignable() == this.getAssignable() &&
-                    ((MatchResult)o).getCoercible() == this.getCoercible() &&
-                    ((MatchResult)o).getVarArgs() == this.getVarArgs() &&
+                    ((MatchResult)o).getExactCount() == this.getExactCount() &&
+                    ((MatchResult)o).getAssignableCount() == this.getAssignableCount() &&
+                    ((MatchResult)o).getCoercibleCount() == this.getCoercibleCount() &&
+                    ((MatchResult)o).getVarArgsCount() == this.getVarArgsCount() &&
                     ((MatchResult)o).isBridge() == this.isBridge());
         }
 
@@ -827,11 +827,11 @@ class Util {
         public int hashCode() {
             final int prime = 31;
             int result = 1;
-            result = prime * result + assignable;
+            result = prime * result + assignableCount;
             result = prime * result + (bridge ? 1231 : 1237);
-            result = prime * result + coercible;
-            result = prime * result + exact;
-            result = prime * result + varArgs;
+            result = prime * result + coercibleCount;
+            result = prime * result + exactCount;
+            result = prime * result + varArgsCount;
             return result;
         }
     }
diff --git a/java/org/apache/el/util/ReflectionUtil.java b/java/org/apache/el/util/ReflectionUtil.java
index 469c7f3..df1c750 100644
--- a/java/org/apache/el/util/ReflectionUtil.java
+++ b/java/org/apache/el/util/ReflectionUtil.java
@@ -274,7 +274,7 @@ public class ReflectionUtil {
             }
         }
         if (multiple) {
-            if (bestMatch.getExact() == paramCount - 1) {
+            if (bestMatch.getExactCount() == paramCount - 1) {
                 // Only one parameter is not an exact match - try using the
                 // super class
                 match = resolveAmbiguousMethod(candidates.keySet(), paramTypes);
@@ -511,34 +511,34 @@ public class ReflectionUtil {
      */
     private static class MatchResult implements Comparable<MatchResult> {
 
-        private final int exact;
-        private final int assignable;
-        private final int coercible;
-        private final int varArgs;
+        private final int exactCount;
+        private final int assignableCount;
+        private final int coercibleCount;
+        private final int varArgsCount;
         private final boolean bridge;
 
-        public MatchResult(int exact, int assignable, int coercible, int varArgs, boolean bridge) {
-            this.exact = exact;
-            this.assignable = assignable;
-            this.coercible = coercible;
-            this.varArgs = varArgs;
+        public MatchResult(int exactCount, int assignableCount, int coercibleCount, int varArgsCount, boolean bridge) {
+            this.exactCount = exactCount;
+            this.assignableCount = assignableCount;
+            this.coercibleCount = coercibleCount;
+            this.varArgsCount = varArgsCount;
             this.bridge = bridge;
         }
 
-        public int getExact() {
-            return exact;
+        public int getExactCount() {
+            return exactCount;
         }
 
-        public int getAssignable() {
-            return assignable;
+        public int getAssignableCount() {
+            return assignableCount;
         }
 
         public int getCoercible() {
-            return coercible;
+            return coercibleCount;
         }
 
-        public int getVarArgs() {
-            return varArgs;
+        public int getVarArgsCount() {
+            return varArgsCount;
         }
 
         public boolean isBridge() {
@@ -547,14 +547,14 @@ public class ReflectionUtil {
 
         @Override
         public int compareTo(MatchResult o) {
-            int cmp = Integer.compare(this.getExact(), o.getExact());
+            int cmp = Integer.compare(this.getExactCount(), o.getExactCount());
             if (cmp == 0) {
-                cmp = Integer.compare(this.getAssignable(), o.getAssignable());
+                cmp = Integer.compare(this.getAssignableCount(), o.getAssignableCount());
                 if (cmp == 0) {
                     cmp = Integer.compare(this.getCoercible(), o.getCoercible());
                     if (cmp == 0) {
                         // Fewer var args matches are better
-                        cmp = Integer.compare(o.getVarArgs(), this.getVarArgs());
+                        cmp = Integer.compare(o.getVarArgsCount(), this.getVarArgsCount());
                         if (cmp == 0) {
                             // The nature of bridge methods is such that it actually
                             // doesn't matter which one we pick as long as we pick
@@ -572,10 +572,10 @@ public class ReflectionUtil {
         public boolean equals(Object o) {
             return o == this || (null != o &&
                     this.getClass().equals(o.getClass()) &&
-                    ((MatchResult)o).getExact() == this.getExact() &&
-                    ((MatchResult)o).getAssignable() == this.getAssignable() &&
+                    ((MatchResult)o).getExactCount() == this.getExactCount() &&
+                    ((MatchResult)o).getAssignableCount() == this.getAssignableCount() &&
                     ((MatchResult)o).getCoercible() == this.getCoercible() &&
-                    ((MatchResult)o).getVarArgs() == this.getVarArgs() &&
+                    ((MatchResult)o).getVarArgsCount() == this.getVarArgsCount() &&
                     ((MatchResult)o).isBridge() == this.isBridge());
         }
 
@@ -583,11 +583,11 @@ public class ReflectionUtil {
         public int hashCode() {
             final int prime = 31;
             int result = 1;
-            result = prime * result + assignable;
+            result = prime * result + assignableCount;
             result = prime * result + (bridge ? 1231 : 1237);
-            result = prime * result + coercible;
-            result = prime * result + exact;
-            result = prime * result + varArgs;
+            result = prime * result + coercibleCount;
+            result = prime * result + exactCount;
+            result = prime * result + varArgsCount;
             return result;
         }
     }

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