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

Runtime.exit logging failed: Cannot invoke "java.lang.Module.getClassLoader()" because "m" is null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 21
    • core-libs

      A call to Runtime.exit(), rarely (but consistently) ends up generating a NullPointerException, when it attempts to log a message during the shutdown:

      > Runtime.exit(130) logging failed: Cannot invoke "java.lang.Module.getClassLoader()" because "m" is null

      This was observed when investigating an unrelated issue. During those tests the java process was launched against a JDK debug build and also with the -Xcomp option. Once the java process was launched, a few seconds later, "kill -2 <java-pid>" was issued against that process. That resulted in the NullPointeerException error message noted above.

      In order to get additional details about this NullPointerException, the JDK code was updated locally to print the stacktrace too and that showed:

      Runtime.exit(130) logging failed: Cannot invoke "java.lang.Module.getClassLoader()" because "m" is null
      java.lang.NullPointerException: Cannot invoke "java.lang.Module.getClassLoader()" because "m" is null
          at java.base/jdk.internal.logger.DefaultLoggerFinder.isSystem(DefaultLoggerFinder.java:123)
          at java.base/jdk.internal.logger.LazyLoggers.getLogger(LazyLoggers.java:415)
          at java.base/java.lang.System.getLogger(System.java:1461)
          at java.base/java.lang.Shutdown.logRuntimeExit(Shutdown.java:177)
          at java.base/java.lang.Shutdown.exit(Shutdown.java:160)
          at java.base/java.lang.Terminator$1.handle(Terminator.java:51)
          at java.base/jdk.internal.misc.Signal$1.run(Signal.java:218)
          at java.base/java.lang.Thread.run(Thread.java:1474)

      A trivial application that reproduced it is (on Linux x64 and Linux aarch64):

      # cat foo.java
      public class foo {
          public static void main(String[] args) {
              while (true) {
                  Thread.yield();
              }
          }
      }
      # java -XX:+UseSerialGC -Xcomp foo
      // kill -2 <pid>
      Runtime.exit(130) logging failed: Cannot invoke "java.lang.Module.getClassLoader()" because "m" is null

      I was able to reproduce against Java 21 too, which is where we introduced this logging in Runtime.exit() as part of JDK-8301627.

            jpai Jaikiran Pai
            jpai Jaikiran Pai
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: