mirror of
https://github.com/apache/commons-lang.git
synced 2025-02-07 02:28:25 +00:00
Return ToStringStyle.nullText instead of NPE for
ReflectionToStringBuilder.toString(Object) and friends.
This commit is contained in:
parent
8d116286d9
commit
ede98ffdb9
@ -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>
|
||||
|
@ -486,11 +486,9 @@ public static String toStringInclude(final Object object, final String... includ
|
||||
*
|
||||
* @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 ReflectionToStringBuilder(final Object object) {
|
||||
* 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 ReflectionToStringBuilder(final Object object, final ToStringStyle style)
|
||||
* 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 ReflectionToStringBuilder(final Object object, final ToStringStyle style,
|
||||
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 <T> ReflectionToStringBuilder(
|
||||
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);
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1265,7 +1265,7 @@ class InheritedReflectionStaticFieldsFixture extends SimpleReflectionStaticField
|
||||
|
||||
@Test
|
||||
public void testReflectionNull() {
|
||||
assertThrows(NullPointerException.class, () -> ReflectionToStringBuilder.toString(null));
|
||||
assertEquals("<null>", ReflectionToStringBuilder.toString(null));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user