commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject [2/5] [lang] add checkNotNull method in ReflectionToStringBuilder.java to fix #LANG-1132
Date Thu, 07 May 2015 18:45:37 GMT
add checkNotNull method in ReflectionToStringBuilder.java to fix #LANG-1132


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/39380da8
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/39380da8
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/39380da8

Branch: refs/heads/master
Commit: 39380da86acc717f419da48f070f8cf7d9f9ec94
Parents: 474a837
Author: Jack <792626757@qq.com>
Authored: Wed May 6 11:43:03 2015 +0800
Committer: Jack <792626757@qq.com>
Committed: Wed May 6 11:43:03 2015 +0800

----------------------------------------------------------------------
 .../lang3/builder/ReflectionToStringBuilder.java     | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/39380da8/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java
----------------------------------------------------------------------
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 d172b1e..6c2199b 100644
--- a/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java
@@ -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);


Mime
View raw message