On 3/8/19 12:35 PM, Martin Buchholz wrote:
On Fri, Mar 8, 2019 at 3:57 AM Tagir Valeev <amae...@gmail.com> wrote:

Hello!

diff -r 274361bd6915 src/java.base/share/classes/java/lang/Throwable.java
--- a/src/java.base/share/classes/java/lang/Throwable.java    Thu Mar 07
10:22:19 2019 +0100
+++ b/src/java.base/share/classes/java/lang/Throwable.java    Fri Mar 08
02:06:42 2019 -0800
@@ -874,8 +874,7 @@
           // Validate argument
           StackTraceElement[] defensiveCopy = stackTrace.clone();
           for (int i = 0; i < defensiveCopy.length; i++) {
-            if (defensiveCopy[i] == null)
-                throw new NullPointerException("stackTrace[" + i + "]");
+            Objects.requireNonNull(defensiveCopy[i], "stackTrace[" + i
+ "]");

Won't it produce unnecessary garbage due to string concatenation on
the common case when all frames are non-null?


I share Tagir's doubts.  I avoid this construction in performance sensitive
code.

I see Tagir's comment after I replied.  I share Tagir's concern as well
and the  exception message would be constructed unconditionally with
this change. java.base is compiled with -XDstringConcat=inline due to
bootstrapping and so the supplier does not help here.

Mandy

Reply via email to