Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8289261

Specify NPE when passing null to Throwable::printStackTrace(java.io.PrintStream)

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Right now it is not specified and the stacktrace can be confusing:

      JDK 11:
      ```
      jshell> new Exception().printStackTrace((PrintStream)null)
      | Exception java.lang.NullPointerException
      | at Throwable.printStackTrace (Throwable.java:657)
      | at Throwable.printStackTrace (Throwable.java:648)
      | at (#1:1)
      ```

      JDK 17:
      ```
      jshell> new Exception().printStackTrace((PrintStream)null)
      | Exception java.lang.NullPointerException: Cannot enter synchronized block because the return value of "java.lang.Throwable$PrintStreamOrWriter.lock()" is null
      | at Throwable.printStackTrace (Throwable.java:668)
      | at Throwable.printStackTrace (Throwable.java:659)
      | at (#3:1)
      ```

      JDK 19:
      ```
      jshell> new Exception().printStackTrace((PrintStream)null)
      | Exception java.lang.NullPointerException: Cannot read field "lock" because "ps" is null
      | at PrintStream$1.lock (PrintStream.java:1542)
      | at Throwable$WrappedPrintStream.lock (Throwable.java:781)
      | at Throwable.printStackTrace (Throwable.java:664)
      | at Throwable.printStackTrace (Throwable.java:660)
      | at (#3:1)
      ```

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: