add checkNotNull method in ReflectionToStringBuilder.java to fix #LANG-1132

This commit is contained in:
Jack 2015-05-06 11:43:03 +08:00
parent 474a837858
commit 39380da86a
1 changed files with 11 additions and 4 deletions

View File

@ -363,6 +363,13 @@ public static String toStringExclude(final Object object, final String... exclud
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 static String toStringExclude(final Object object, final String... exclud
* if the Object passed in is <code>null</code>
*/
public ReflectionToStringBuilder(final Object object) {
super(object);
super(checkNotNull(object));
}
/**
@ -420,7 +427,7 @@ public ReflectionToStringBuilder(final Object object) {
* 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 ReflectionToStringBuilder(final Object object, final ToStringStyle style)
* 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 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(object, style, buffer);
super(checkNotNull(object), style, buffer);
this.setUpToClass(reflectUpToClass);
this.setAppendTransients(outputTransients);
this.setAppendStatics(outputStatics);