Merge branch 'LANG-1132'
LANG-1132: ReflectionToStringBuilder doesn't throw IllegalArgumentException when the constructor's object param is null. Thanks to Jack Tan.
This commit is contained in:
commit
dee94449e6
|
@ -22,6 +22,7 @@
|
|||
<body>
|
||||
|
||||
<release version="3.5" date="tba" description="tba">
|
||||
<action issue="LANG-1132" type="add" dev="britter" due-to="Jack Tan">ReflectionToStringBuilder doesn't throw IllegalArgumentException when the constructor's object param is null</action>
|
||||
<action issue="LANG-1122" type="fix" dev="britter" due-to="Adrian Ber">Inconsistent behavior of swap for malformed inputs</action>
|
||||
<action issue="LANG-701" type="add" dev="britter" due-to="James Sawle">StringUtils join with var args</action>
|
||||
<action issue="LANG-1130" type="fix" dev="britter">Fix critical issues reported by SonarQube</action>
|
||||
|
|
|
@ -362,6 +362,13 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
|
|||
public static String toStringExclude(final Object object, final String... excludeFieldNames) {
|
||||
return new ReflectionToStringBuilder(object).setExcludeFieldNames(excludeFieldNames).toString();
|
||||
}
|
||||
|
||||
private static Object checkNotNull(final Object obj) {
|
||||
if (obj == null) {
|
||||
throw new IllegalArgumentException("The Object passed in should not be null.");
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not to append static fields.
|
||||
|
@ -400,7 +407,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
|
|||
* if the Object passed in is <code>null</code>
|
||||
*/
|
||||
public ReflectionToStringBuilder(final Object object) {
|
||||
super(object);
|
||||
super(checkNotNull(object));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -420,7 +427,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
|
|||
* if the Object passed in is <code>null</code>
|
||||
*/
|
||||
public ReflectionToStringBuilder(final Object object, final ToStringStyle style) {
|
||||
super(object, style);
|
||||
super(checkNotNull(object), style);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -446,7 +453,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
|
|||
* if the Object passed in is <code>null</code>
|
||||
*/
|
||||
public ReflectionToStringBuilder(final Object object, final ToStringStyle style, final StringBuffer buffer) {
|
||||
super(object, style, buffer);
|
||||
super(checkNotNull(object), style, buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -471,7 +478,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(object, style, buffer);
|
||||
super(checkNotNull(object), style, buffer);
|
||||
this.setUpToClass(reflectUpToClass);
|
||||
this.setAppendTransients(outputTransients);
|
||||
this.setAppendStatics(outputStatics);
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package org.apache.commons.lang3.builder;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ReflectionToStringBuilderTest {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testConstructorWithNullObject() {
|
||||
new ReflectionToStringBuilder(null, ToStringStyle.DEFAULT_STYLE, new StringBuffer());
|
||||
}
|
||||
|
||||
}
|
|
@ -1041,7 +1041,7 @@ public class ToStringBuilderTest {
|
|||
static final int staticInt2 = 67890;
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testReflectionNull() {
|
||||
assertEquals("<null>", ReflectionToStringBuilder.toString(null));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue