Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
2.0
-
None
-
None
-
None
-
Operating System: other
Platform: Other
-
34600
Description
The equals() method of the Enum class in Commons Lang 2.0 is too fragile. If
the "Other" argument is a non-null abject of any other type than Enum, then a
ClassCastException is thrown.
The offending line code is:
if (other == this)
{ return true; }else if (other == null)
{ return false; }else if (other.getClass() == this.getClass())
{ // shouldn't happen, but... return iName.equals(((Enum) other).iName); } else if (((Enum)
other).getEnumClass().getName().equals(getEnumClass().getName())) {
If "other" is, say, a String, then the last else-if clause will throw an
exception when it tries to cast it to Enum.
This method should be more robust, and tolerate ANY argument, regardless of type.