mirror of
https://github.com/apache/commons-lang.git
synced 2025-02-14 14:05:17 +00:00
Applying Thomas Neidhart's patch for LANG-905; fixing a bug in which EqualsBuilder considers two arrays of the same type to be equal, without considering the contents
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1535653 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4fc5c6b35c
commit
70b3504b9f
@ -22,6 +22,7 @@
|
|||||||
<body>
|
<body>
|
||||||
|
|
||||||
<release version="3.2" date="TBA" description="Next release">
|
<release version="3.2" date="TBA" description="Next release">
|
||||||
|
<action issue="LANG-905" type="fix">EqualsBuilder returns true when comparing arrays, even when the elements are different</action>
|
||||||
<action issue="LANG-774" type="add" due-to="Erhan Bagdemir">Added isStarted, isSuspended and isStopped to StopWatch</action>
|
<action issue="LANG-774" type="add" due-to="Erhan Bagdemir">Added isStarted, isSuspended and isStopped to StopWatch</action>
|
||||||
<action issue="LANG-917" type="fix" due-to="Arne Burmeister">Fixed exception when combining custom and choice format in ExtendedMessageFormat</action>
|
<action issue="LANG-917" type="fix" due-to="Arne Burmeister">Fixed exception when combining custom and choice format in ExtendedMessageFormat</action>
|
||||||
<action issue="LANG-848" type="add" due-to="Alexander Muthmann">Added StringUtils.isBlank/isEmpty CharSequence... methods</action>
|
<action issue="LANG-848" type="add" due-to="Alexander Muthmann">Added StringUtils.isBlank/isEmpty CharSequence... methods</action>
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import org.apache.commons.lang3.ClassUtils;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -354,10 +355,14 @@ public static boolean reflectionEquals(final Object lhs, final Object rhs, final
|
|||||||
}
|
}
|
||||||
final EqualsBuilder equalsBuilder = new EqualsBuilder();
|
final EqualsBuilder equalsBuilder = new EqualsBuilder();
|
||||||
try {
|
try {
|
||||||
reflectionAppend(lhs, rhs, testClass, equalsBuilder, testTransients, excludeFields);
|
if (testClass.isArray()) {
|
||||||
while (testClass.getSuperclass() != null && testClass != reflectUpToClass) {
|
equalsBuilder.append(lhs, rhs);
|
||||||
testClass = testClass.getSuperclass();
|
} else {
|
||||||
reflectionAppend(lhs, rhs, testClass, equalsBuilder, testTransients, excludeFields);
|
reflectionAppend(lhs, rhs, testClass, equalsBuilder, testTransients, excludeFields);
|
||||||
|
while (testClass.getSuperclass() != null && testClass != reflectUpToClass) {
|
||||||
|
testClass = testClass.getSuperclass();
|
||||||
|
reflectionAppend(lhs, rhs, testClass, equalsBuilder, testTransients, excludeFields);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (final IllegalArgumentException e) {
|
} catch (final IllegalArgumentException e) {
|
||||||
// In this case, we tried to test a subclass vs. a superclass and
|
// In this case, we tried to test a subclass vs. a superclass and
|
||||||
|
@ -1126,5 +1126,29 @@ public boolean equals(final Object obj) {
|
|||||||
return EqualsBuilder.reflectionEquals(this, obj);
|
return EqualsBuilder.reflectionEquals(this, obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReflectionArrays() throws Exception {
|
||||||
|
|
||||||
|
final TestObject one = new TestObject(1);
|
||||||
|
final TestObject two = new TestObject(2);
|
||||||
|
|
||||||
|
Object[] o1 = new Object[] { one };
|
||||||
|
Object[] o2 = new Object[] { two };
|
||||||
|
Object[] o3 = new Object[] { one };
|
||||||
|
|
||||||
|
assertTrue(!EqualsBuilder.reflectionEquals(o1, o2));
|
||||||
|
assertTrue(EqualsBuilder.reflectionEquals(o1, o1));
|
||||||
|
assertTrue(EqualsBuilder.reflectionEquals(o1, o3));
|
||||||
|
|
||||||
|
double[] d1 = { 0, 1 };
|
||||||
|
double[] d2 = { 2, 3 };
|
||||||
|
double[] d3 = { 0, 1 };
|
||||||
|
|
||||||
|
assertTrue(!EqualsBuilder.reflectionEquals(d1, d2));
|
||||||
|
assertTrue(EqualsBuilder.reflectionEquals(d1, d1));
|
||||||
|
assertTrue(EqualsBuilder.reflectionEquals(d1, d3));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user