diff --git a/src/changes/changes.xml b/src/changes/changes.xml index da3522029..92dff9198 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -124,6 +124,7 @@ The type attribute can be add,update,fix,remove. Deprecate ExceptionUtils.ExceptionUtils(). TypeUtils.getRawType() throws a NullPointerException on Wildcard GenericArrayType. Throw IllegalArgumentException instead of InternalError in the builder package. + Avoid NPE in MutableObject#equals() for null content. Add GitHub coverage.yml. Add EnumUtils.getEnumSystemProperty(...). diff --git a/src/main/java/org/apache/commons/lang3/mutable/MutableObject.java b/src/main/java/org/apache/commons/lang3/mutable/MutableObject.java index 7c371f783..259d007b0 100644 --- a/src/main/java/org/apache/commons/lang3/mutable/MutableObject.java +++ b/src/main/java/org/apache/commons/lang3/mutable/MutableObject.java @@ -93,7 +93,7 @@ public class MutableObject implements Mutable, Serializable { } if (this.getClass() == obj.getClass()) { final MutableObject that = (MutableObject) obj; - return this.value.equals(that.value); + return Objects.equals(this.value, that.value); } return false; } diff --git a/src/test/java/org/apache/commons/lang3/mutable/MutableObjectTest.java b/src/test/java/org/apache/commons/lang3/mutable/MutableObjectTest.java index c02d9d97e..b893ffd91 100644 --- a/src/test/java/org/apache/commons/lang3/mutable/MutableObjectTest.java +++ b/src/test/java/org/apache/commons/lang3/mutable/MutableObjectTest.java @@ -47,7 +47,8 @@ public class MutableObjectTest extends AbstractLangTest { final MutableObject mutNumA = new MutableObject<>("ALPHA"); final MutableObject mutNumB = new MutableObject<>("ALPHA"); final MutableObject mutNumC = new MutableObject<>("BETA"); - final MutableObject mutNumD = new MutableObject<>(null); + final MutableObject mutNumNull1 = new MutableObject<>(null); + final MutableObject mutNumNull2 = new MutableObject<>(null); assertEquals(mutNumA, mutNumA); assertEquals(mutNumA, mutNumB); @@ -56,8 +57,10 @@ public class MutableObjectTest extends AbstractLangTest { assertNotEquals(mutNumA, mutNumC); assertNotEquals(mutNumB, mutNumC); assertEquals(mutNumC, mutNumC); - assertNotEquals(mutNumA, mutNumD); - assertEquals(mutNumD, mutNumD); + assertNotEquals(mutNumA, mutNumNull1); + assertEquals(mutNumNull1, mutNumNull1); + assertEquals(mutNumNull1, mutNumNull2); + assertEquals(mutNumNull2, mutNumNull1); assertNotEquals(null, mutNumA); assertNotEquals(mutNumA, new Object());