You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
The method JAXBEqualsStrategy.equals(ObjectLocator leftLocator, ObjectLocator rightLocator, Object lhs, Object rhs) is not symmetric when comparing an Enum and a Concrete class, thus it violates the contract of Object.equals().
If lhs is an Enum and rhs is not an Enum, a ClassCastException to java.lang.Enum is thrown. If rhs is not an enum and lhs is an Enum, no exception is thrown and the method correctly compares lhs and rhs.
I observed this behaviour in 0.6.5 and verified that it also occurs in the latest released version 0.9.2.
public class EqualsStrategyTest {
@Test
public void testJAXBEqualsSymmetryConcreteClassAndEnum() {
assertFalse(JAXBEqualsStrategy.INSTANCE.equals(null, null, new SomeConcreteClass(), SomeEnum.ENUM));
}
@Test
public void testJAXBEqualsSymmetryEnumAndConcreteClass() {
// This test fails and throws a ClassCastException assertFalse(JAXBEqualsStrategy.INSTANCE.equals(null, null, SomeEnum.ENUM, new SomeConcreteClass()));
}
private static class SomeConcreteClass {
}
private enum SomeEnum {
ENUM;
}
}
The problem is in DefaultEqualsStrategy.equalsInternal(ObjectLocator leftLocator, ObjectLocator rightLocator, Object lhs, Object rhs):
If the left hand side of the equals is an Enum, we assume that the right is an Enum as well, which is incorrect in the example case, resulting in the ClassCastException.
Environment
java8u31, using maven
Affected Versions
[current]
The text was updated successfully, but these errors were encountered:
The method JAXBEqualsStrategy.equals(ObjectLocator leftLocator, ObjectLocator rightLocator, Object lhs, Object rhs) is not symmetric when comparing an Enum and a Concrete class, thus it violates the contract of Object.equals().
If lhs is an Enum and rhs is not an Enum, a ClassCastException to java.lang.Enum is thrown. If rhs is not an enum and lhs is an Enum, no exception is thrown and the method correctly compares lhs and rhs.
I observed this behaviour in 0.6.5 and verified that it also occurs in the latest released version 0.9.2.
The problem is in DefaultEqualsStrategy.equalsInternal(ObjectLocator leftLocator, ObjectLocator rightLocator, Object lhs, Object rhs):
If the left hand side of the equals is an Enum, we assume that the right is an Enum as well, which is incorrect in the example case, resulting in the ClassCastException.
Environment
java8u31, using maven
Affected Versions
[current]
The text was updated successfully, but these errors were encountered: