commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r1535653 - in /commons/proper/lang/trunk/src: changes/changes.xml main/java/org/apache/commons/lang3/builder/EqualsBuilder.java test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java
Date Fri, 25 Oct 2013 08:19:29 GMT
Author: bayard
Date: Fri Oct 25 08:19:29 2013
New Revision: 1535653

URL: http://svn.apache.org/r1535653
Log:
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

Modified:
    commons/proper/lang/trunk/src/changes/changes.xml
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java

Modified: commons/proper/lang/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/changes/changes.xml?rev=1535653&r1=1535652&r2=1535653&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/changes/changes.xml (original)
+++ commons/proper/lang/trunk/src/changes/changes.xml Fri Oct 25 08:19:29 2013
@@ -22,6 +22,7 @@
   <body>
 
   <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-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>

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java?rev=1535653&r1=1535652&r2=1535653&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
Fri Oct 25 08:19:29 2013
@@ -24,6 +24,7 @@ import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.ClassUtils;
 import org.apache.commons.lang3.tuple.Pair;
 
 /**
@@ -354,10 +355,14 @@ public class EqualsBuilder implements Bu
         }
         final EqualsBuilder equalsBuilder = new EqualsBuilder();
         try {
-            reflectionAppend(lhs, rhs, testClass, equalsBuilder, testTransients, excludeFields);
-            while (testClass.getSuperclass() != null && testClass != reflectUpToClass)
{
-                testClass = testClass.getSuperclass();
+            if (testClass.isArray()) {
+                equalsBuilder.append(lhs, rhs);
+            } else {
                 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) {
             // In this case, we tried to test a subclass vs. a superclass and

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java?rev=1535653&r1=1535652&r2=1535653&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/builder/EqualsBuilderTest.java
Fri Oct 25 08:19:29 2013
@@ -1126,5 +1126,29 @@ public class EqualsBuilderTest {
             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));
+    }
+
 }
 



Mime
View raw message