This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push: new ede98ffdb Return ToStringStyle.nullText instead of NPE for ReflectionToStringBuilder.toString(Object) and friends. ede98ffdb is described below commit ede98ffdb928586528a8b2876b049cb8bf362926 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sat Oct 7 10:19:50 2023 -0400 Return ToStringStyle.nullText instead of NPE for ReflectionToStringBuilder.toString(Object) and friends. --- src/changes/changes.xml | 1 + .../commons/lang3/builder/ReflectionToStringBuilder.java | 16 +++++----------- .../lang3/builder/ReflectionToStringBuilderTest.java | 8 +++++--- .../commons/lang3/builder/ToStringBuilderTest.java | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 16605183c..f5fa60dc8 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -58,6 +58,7 @@ The <action> type attribute can be add,update,fix,remove. <action issue="LANG-1710" type="fix" dev="ggregory" due-to="Shashank Sharma, Gary Gregory, Oksana">ReflectionToStringBuilder changes in version 3.13.0 has broken the logic for overriding classes.</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">Return "null" instead of NPE in ClassLoaderUtils.toString(ClassLoader).</action> <action type="fix" dev="ggregory" due-to="Gary Gregory">Return "null" instead of NPE in ClassLoaderUtils.toString(URLClassLoader).</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">Return ToStringStyle.nullText instead of NPE for ReflectionToStringBuilder.toString(Object) and friends.</action> <!-- ADD --> <action type="add" dev="ggregory" due-to="Rob Spoor, Gary Gregory">Add Functions#function(Function).</action> <action type="add" dev="ggregory" due-to="Rob Spoor, Gary Gregory">Add FailableFunction#function(FailableFunction).</action> diff --git a/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java b/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java index c505a5187..f7091d4f3 100644 --- a/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java @@ -486,11 +486,9 @@ public class ReflectionToStringBuilder extends ToStringBuilder { * * @param object * the Object to build a {@code toString} for, must not be {@code null} - * @throws IllegalArgumentException - * if the Object passed in is {@code null} */ public ReflectionToStringBuilder(final Object object) { - super(Objects.requireNonNull(object, "obj")); + super(object); } /** @@ -504,11 +502,9 @@ public class ReflectionToStringBuilder extends ToStringBuilder { * the Object to build a {@code toString} for, must not be {@code null} * @param style * the style of the {@code toString} to create, may be {@code null} - * @throws IllegalArgumentException - * if the Object passed in is {@code null} */ public ReflectionToStringBuilder(final Object object, final ToStringStyle style) { - super(Objects.requireNonNull(object, "obj"), style); + super(object, style); } /** @@ -528,11 +524,9 @@ public class ReflectionToStringBuilder extends ToStringBuilder { * the style of the {@code toString} to create, may be {@code null} * @param buffer * the {@link StringBuffer} to populate, may be {@code null} - * @throws IllegalArgumentException - * if the Object passed in is {@code null} */ public ReflectionToStringBuilder(final Object object, final ToStringStyle style, final StringBuffer buffer) { - super(Objects.requireNonNull(object, "obj"), style, buffer); + super(object, style, buffer); } /** @@ -557,7 +551,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder { public <T> ReflectionToStringBuilder( final T object, final ToStringStyle style, final StringBuffer buffer, final Class<? super T> reflectUpToClass, final boolean outputTransients, final boolean outputStatics) { - super(Objects.requireNonNull(object, "obj"), style, buffer); + super(object, style, buffer); this.setUpToClass(reflectUpToClass); this.setAppendTransients(outputTransients); this.setAppendStatics(outputStatics); @@ -588,7 +582,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder { final T object, final ToStringStyle style, final StringBuffer buffer, final Class<? super T> reflectUpToClass, final boolean outputTransients, final boolean outputStatics, final boolean excludeNullValues) { - super(Objects.requireNonNull(object, "obj"), style, buffer); + super(object, style, buffer); this.setUpToClass(reflectUpToClass); this.setAppendTransients(outputTransients); this.setAppendStatics(outputStatics); diff --git a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderTest.java index 16a38fd02..222b8053d 100644 --- a/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/ReflectionToStringBuilderTest.java @@ -16,17 +16,19 @@ */ package org.apache.commons.lang3.builder; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.commons.lang3.AbstractLangTest; import org.junit.jupiter.api.Test; +/** + * Tests {@link ReflectionToStringBuilder}. + */ public class ReflectionToStringBuilderTest extends AbstractLangTest { @Test public void testConstructorWithNullObject() { - assertThrows(NullPointerException.class, - () -> new ReflectionToStringBuilder(null, ToStringStyle.DEFAULT_STYLE, new StringBuffer())); + assertEquals("<null>", new ReflectionToStringBuilder(null, ToStringStyle.DEFAULT_STYLE, new StringBuffer()).toString()); } } diff --git a/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java b/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java index 40ec0a735..0307e702e 100644 --- a/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java +++ b/src/test/java/org/apache/commons/lang3/builder/ToStringBuilderTest.java @@ -1265,7 +1265,7 @@ public class ToStringBuilderTest extends AbstractLangTest { @Test public void testReflectionNull() { - assertThrows(NullPointerException.class, () -> ReflectionToStringBuilder.toString(null)); + assertEquals("<null>", ReflectionToStringBuilder.toString(null)); } /**