Re: Strange difference in behavior ELSupport in Tomcat 6.0.20 and Tomcat 6.0.26

2010-09-26 Thread sbrejeon


Konstantin Kolinko wrote:
 
 2010/7/6 Roxana missbl...@gmail.com:
 BTW, if you really need to compare apples with oranges, you can
 convert one of them or both to strings.
 Best regards,
 Konstantin Kolinko
 

http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/lang/ELSupport.java?revision=981816view=markup

equals:
144  } else if (obj0.getClass().isEnum()) {
145 return obj0.equals(coerceToEnum(obj1, obj0.getClass())); 

coerceToEnum(obj, type):
180  if (type.isAssignableFrom(obj.getClass())) {
181 return (Enum?) obj;
182 }
183 
184 if (!(obj instanceof String)) {
185 throw new ELException(MessageFactory.get(error.convert,
186 obj, obj.getClass(), type));
187 } 

enum A{
 test
}

enum B{
 test
}

A.test==B.test throws the exception. couldn't it just return false?

Regards
Sbrejeon






-- 
View this message in context: 
http://old.nabble.com/Strange-difference-in-behavior-ELSupport-in-Tomcat-6.0.20-and-Tomcat--6.0.26-tp29088066p29815264.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


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



Re: Strange difference in behavior ELSupport in Tomcat 6.0.20 and Tomcat 6.0.26

2010-09-26 Thread sbrejeon


markt-2 wrote:
 
 On 27/09/2010 02:23, sbrejeon wrote:
 A.test==B.test throws the exception. couldn't it just return false?
 
 Such a change would put Tomcat's EL implementation in breach of the EL
 spec so this behaviour will not be changed.
 
 Mark
 

Thank you for your quick reply.

The spec says that If A or B is an enum, coerce both A and B to enum, apply
operator.
Does't it simply mean that both A and B must be coercible to enums. instead
of if A is an enum then B must be an enum of type A, or vice versa.

in the coerceToEnum method I would return the object if it is an enum
(whatever its type is):

public final static Enum? coerceToEnum(final Object obj, Class type) {
if (obj == null || .equals(obj)) {
return null;
}

if(obj.getClass().isEnum()){
 return (Enum?)obj;
}
...
}

Like the original creator of this post, I have a series of enums of
different types that implement a common interface. I need to be able to
compare them and I don't want to have to translate them to Strings.

Regards
Sbrejeon


-- 
View this message in context: 
http://old.nabble.com/Strange-difference-in-behavior-ELSupport-in-Tomcat-6.0.20-and-Tomcat--6.0.26-tp29088066p29815521.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


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