Summary
Calls to java.lang.Runtime.exit(status)
are logged to the System logger, if enabled.
Problem
It can be difficult to identify the cause of calls to java.lang.System.exit(status)
and Runtime.exit(status)
because the Java runtime exits immediately.
Logging a message and stack trace makes it easier to locate the caller and cause.
Solution
A call to the system logger (java.lang.System.getLogger
) is added to the implementation of Runtime.exit(status)
before shutdown commences.
If the logger named `java.lang.Runtime' is configured with level System.Logger.Level.DEBUG, a message is logged including the status and stack trace.
Also add an @implNote to java.lang.System.exit(int)
to note the behavior of Runtime.exit(int)
.
The configuration of the system logger determines how the message appears in the logs or on the console.
Specification
There is no change to the API or specification. The logging is documented as an @implNote describing the implementation behavior.
The java.lang.Runtime.exit(int)
javadoc has an added implNote
:
* @implNote
* If the {@link System#getLogger(String) the system logger} for {@code java.lang.Runtime}
* is enabled with logging level {@link System.Logger.Level#DEBUG Level.DEBUG} the stack trace
* of the call to {@code Runtime.exit()} is logged.
The java.lang.System.exit(int)
javadoc has an added implNote
:
* @implNote
* The initiation of the shutdown sequence is logged by {@link Runtime#exit(int)}.
- csr of
-
JDK-8301627 System.exit and Runtime.exit debug logging
- Resolved