Error message about exception in upcall not visible when using custom System.err

some-java-user-99206970363698485155 at vodafonemail.de some-java-user-99206970363698485155 at vodafonemail.de
Wed Nov 27 22:49:07 UTC 2024


Hello,

when an upcall encounters a Java exception, the JVM exits, and prints a 
message and the stack trace to `System.err` [0].
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.

Would it make sense to additionally print the message and stack trace 
directly to the `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.
What do you think?

Maybe such behavior would be useful for all JDK code which calls 
`System.exit(...)` on a fatal error, see also 
https://bugs.openjdk.org/browse/JDK-8336329.


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 https://bugs.openjdk.org/browse/JDK-8302691 (but many users 
might not be aware of it, or might not immediately think of it when the 
JVM just exits without any details).

[0] 
https://github.com/openjdk/jdk/blob/jdk-24%2B25/src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java#L310-L311
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20241127/3ecfa6a9/attachment.htm>


More information about the panama-dev mailing list