<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>I'd say this behavior is working as intended. This matches what
happens if a thread throws an exception while stderr is
redirected. You don't see the exception message + stack trace
printed, since it's going to the redirected stream.</p>
<p>I think if we unconditionally printed the stack trace to the
default stderr as well, then users might also reasonably ask why
that output is not redirected, or how they can silence it.</p>
<p>If <span class="element-name type-name-label"><a class="moz-txt-link-freetext" href="https://bugs.openjdk.org/browse/JDK-8336329">JDK-8336329</a>
is implemented, we will probably start using that mechanism as
well. Maybe it will have more option on how to redirect the
output. But, I think for now, we want to keep respecting the
redirected stderr.<br>
</span></p>
<p>Jorn</p>
<div class="moz-cite-prefix">On 27-11-2024 23:49,
<a class="moz-txt-link-abbreviated" href="mailto:some-java-user-99206970363698485155@vodafonemail.de">some-java-user-99206970363698485155@vodafonemail.de</a> wrote:<br>
</div>
<blockquote type="cite" cite="mid:278c86b1-8e0c-423b-8938-bd02083bf051@vodafonemail.de">
<p>Hello,</p>
<p>when an upcall encounters a Java exception, the JVM exits, and
prints a message and the stack trace to `System.err` [0].<br>
The problem is when you (or libraries, ...) have used
`System.setErr(...)` to overwrite the default stream, then you
might not see this message and are wondering why the JVM has
just exited without any details and without JVM crash report.</p>
<p>Would it make sense to additionally print the message and stack
trace directly to the `<span class="modifiers"></span><span class="element-name type-name-label">FileDescriptor.err` (and
to be safe call `PrintStream#flush` and
`FileDescriptor#sync`)? This would make sure that users see
it, even if `System.err` was redirected.<br>
What do you think?</span></p>
<p><span class="element-name type-name-label">Maybe such behavior
would be useful for all JDK code which calls
`System.exit(...)` on a fatal error, see also <a class="moz-txt-link-freetext" href="https://bugs.openjdk.org/browse/JDK-8336329" moz-do-not-send="true">https://bugs.openjdk.org/browse/JDK-8336329</a>.</span></p>
<p><span class="element-name type-name-label"><br>
</span></p>
<p><span class="element-name type-name-label">Though arguably
redirecting or silencing `System.err` might also hide other
(non-fatal) errors, so should if possible be avoided in the
first place. Additionally since JDK 21 there is
`System.exit(...)` debug logging, see <a class="moz-txt-link-freetext" href="https://bugs.openjdk.org/browse/JDK-8302691" moz-do-not-send="true">https://bugs.openjdk.org/browse/JDK-8302691</a>
(but many users might not be aware of it, or might not
immediately think of it when the JVM just exits without any
details).<br>
</span></p>
<p>[0]
<a class="moz-txt-link-freetext" href="https://github.com/openjdk/jdk/blob/jdk-24%2B25/src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java#L310-L311" moz-do-not-send="true">https://github.com/openjdk/jdk/blob/jdk-24%2B25/src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java#L310-L311</a><br>
</p>
</blockquote>
</body>
</html>