8220346: Refactor java.lang.Throwable to use Objects.requireNonNull
authordarcy
Mon, 11 Mar 2019 11:23:09 -0700
changeset 54059 1bc8513104f2
parent 54058 be40860e8227
child 54060 53a95878619f
8220346: Refactor java.lang.Throwable to use Objects.requireNonNull Reviewed-by: lancea, mchung, tvaleev, forax, martin, plevart
src/java.base/share/classes/java/lang/Throwable.java
--- a/src/java.base/share/classes/java/lang/Throwable.java	Mon Mar 11 14:06:05 2019 -0400
+++ b/src/java.base/share/classes/java/lang/Throwable.java	Mon Mar 11 11:23:09 2019 -0700
@@ -914,8 +914,7 @@
                 for (Throwable t : suppressedExceptions) {
                     // Enforce constraints on suppressed exceptions in
                     // case of corrupt or malicious stream.
-                    if (t == null)
-                        throw new NullPointerException(NULL_CAUSE_MESSAGE);
+                    Objects.requireNonNull(t, NULL_CAUSE_MESSAGE);
                     if (t == this)
                         throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE);
                     suppressed.add(t);
@@ -942,8 +941,7 @@
                 stackTrace = null;
             } else { // Verify stack trace elements are non-null.
                 for(StackTraceElement ste : stackTrace) {
-                    if (ste == null)
-                        throw new NullPointerException("null StackTraceElement in serial stream. ");
+                    Objects.requireNonNull(ste, "null StackTraceElement in serial stream.");
                 }
             }
         } else {
@@ -1034,8 +1032,7 @@
         if (exception == this)
             throw new IllegalArgumentException(SELF_SUPPRESSION_MESSAGE, exception);
 
-        if (exception == null)
-            throw new NullPointerException(NULL_CAUSE_MESSAGE);
+        Objects.requireNonNull(exception, NULL_CAUSE_MESSAGE);
 
         if (suppressedExceptions == null) // Suppressed exceptions not recorded
             return;