8220346: Refactor java.lang.Throwable to use Objects.requireNonNull
Reviewed-by: lancea, mchung, tvaleev, forax, martin, plevart
--- 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;