Author: henrib
Date: Sat Jul  9 19:41:11 2011
New Revision: 1144722

URL: http://svn.apache.org/viewvc?rev=1144722&view=rev
Log:
Reduced the number of cases where methods are considered ambiguous. This 
addition considers primitives as more "qualifying" than their object 
equivalents, resolving the ambiguity by picking the method with the most number 
of primitive parameters. The impact is minimal since an expr/script with an 
ambiguous call would have failed before this modification. 

Modified:
    
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/introspection/MethodKey.java

Modified: 
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/introspection/MethodKey.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/introspection/MethodKey.java?rev=1144722&r1=1144721&r2=1144722&view=diff
==============================================================================
--- 
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/introspection/MethodKey.java
 (original)
+++ 
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/introspection/MethodKey.java
 Sat Jul  9 19:41:11 2011
@@ -367,7 +367,7 @@ public final class MethodKey {
          */
         private static final long serialVersionUID = -2314636505414551664L;
     }
-
+        
     /**
      * Utility for parameters matching.
      * @param <T> Method or Constructor
@@ -445,12 +445,10 @@ public final class MethodKey {
                     maximals.addLast(app);
                 }
             }
-
             if (maximals.size() > 1) {
                 // We have more than one maximally specific method
                 throw new AmbiguousException();
             }
-
             return maximals.getFirst();
         } // CSON: RedundantThrows
 
@@ -488,26 +486,34 @@ public final class MethodKey {
 
             if (c1MoreSpecific) {
                 if (c2MoreSpecific) {
-                    /*
-                     *  Incomparable due to cross-assignable arguments (i.e.
-                     * foo(String, Object) vs. foo(Object, String))
-                     */
-
+                    // Incomparable due to cross-assignable arguments (i.e. 
foo(String, Object) vs. foo(Object, String))
                     return INCOMPARABLE;
                 }
-
                 return MORE_SPECIFIC;
             }
-
             if (c2MoreSpecific) {
                 return LESS_SPECIFIC;
             }
 
+            // attempt to choose by picking the one with the greater number of 
primitives or latest primitive parameter
+            int primDiff = 0;
+            for(int c = 0; c < c1.length; ++c) {
+                if (c1[c].isPrimitive()) {
+                    primDiff += 1 << c;
+                }
+                if (c2[c].isPrimitive()) {
+                    primDiff -= 1 << c;
+                }
+            }
+            if (primDiff > 0) {
+                return MORE_SPECIFIC;
+            } else if (primDiff < 0) {
+                return LESS_SPECIFIC;
+            }
             /*
              * Incomparable due to non-related arguments (i.e.
              * foo(Runnable) vs. foo(Serializable))
              */
-
             return INCOMPARABLE;
         }
 


Reply via email to