Avoid NPE in MutableObject#equals() for null content

This commit is contained in:
Gary Gregory 2023-07-16 16:34:20 -04:00
parent 53bb929c8f
commit 514f6751ab
3 changed files with 8 additions and 4 deletions

View File

@ -124,6 +124,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate ExceptionUtils.ExceptionUtils().</action>
<action issue="LANG-1697" type="fix" dev="ggregory" due-to="Jan Arne Sparka, Gary Gregory">TypeUtils.getRawType() throws a NullPointerException on Wildcard GenericArrayType.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Throw IllegalArgumentException instead of InternalError in the builder package.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Avoid NPE in MutableObject#equals() for null content.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add GitHub coverage.yml.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add EnumUtils.getEnumSystemProperty(...).</action>

View File

@ -93,7 +93,7 @@ public class MutableObject<T> implements Mutable<T>, 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;
}

View File

@ -47,7 +47,8 @@ public class MutableObjectTest extends AbstractLangTest {
final MutableObject<String> mutNumA = new MutableObject<>("ALPHA");
final MutableObject<String> mutNumB = new MutableObject<>("ALPHA");
final MutableObject<String> mutNumC = new MutableObject<>("BETA");
final MutableObject<String> mutNumD = new MutableObject<>(null);
final MutableObject<String> mutNumNull1 = new MutableObject<>(null);
final MutableObject<String> 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());