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

Jorn Vernee jorn.vernee at oracle.com
Thu Nov 28 11:20:07 UTC 2024


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.

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.

If JDK-8336329 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.

Jorn

On 27-11-2024 23:49, some-java-user-99206970363698485155 at vodafonemail.de 
wrote:
>
> 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/20241128/a5b85124/attachment.htm>


More information about the panama-dev mailing list