1 Reply Latest reply on Oct 28, 2009 8:13 PM by Anton Lisovenko

    Seam-EL enum matching bug?

    Anton Lisovenko Newbie

      Hello.


      Imagine I have some enum named EntityType and EntityType.Order enum value. And I have the class, which has two overloaded methods, one of which uses this enum:
         


         public abstract boolean canSee(CommonProperties entity);
          
          public abstract boolean canSee(EntityType type);







      Then I use this method in the xhtml:




      <h:commandLink rendered="#{profile.role.canEdit('Order')}" .. />




      The method canSee(CommonProperties entity); is chosen instead of the method with enum and the conversion exception is raised later. I debuged this and noticed that seam el doesn't make any coercions while choosing the best methods among all overloaded methods (methods with the same name). See ReflectionUtil.pickBest method, which chooses the best method with the same name to process the value expression:




          private static Method pickBest(Class[] paramTypes, Method a, Method b) {
              int r = 0;
              for (int i = 0; i < paramTypes.length; i++) {
                  if (paramTypes[i] != null) {
                      r += matches(paramTypes[i], a.getParameterTypes()[i]);
                      r -= matches(paramTypes[i], b.getParameterTypes()[i]);
                  }
              }
              return (r >= 0) ? a : b;
          }



      So, both methods return 0 and the first method ('a') is returned, and this can be either method - in my situation it is the wrong one.


      The problem is that if there is no overloading of methods - everything works, the method is found by name and then the enum coercion is made in seam internally (from string 'Order' to enum EntityType.Order) and the method is processed.


      For now I will have to rename the method with enum (allthough they are really similar in functionality) to avoid wrong method choosing, but this seems to be the seam-el bug. May be non-critical, but this took me several hours to get the reason. Believe this will help anyone.