Install the SIGHUP dump handler reflectively - #2852
Conversation
This avoids warnings during compilation which are printed in every CI summary. sun.misc.Signal and SignalHandler are internal proprietary APIs. The approach is taken over from Main.java.
|
It sounds interesting, I will do the review. |
| } catch (Throwable e) { | ||
| // Will happen if sun.misc.SignalHandler is not available | ||
| dumpHandler = new DumpHandler(context); | ||
| } catch (Exception e) { |
There was a problem hiding this comment.
This narrows the previous catch (Throwable e) to Exception. The reflective DumpHandler constructor can fail with Error subtypes rather than exceptions (ExceptionInInitializerError, NoClassDefFoundError, LinkageError). On JVMs where sun.misc.Signal resolves as a name but can't be initialized or linked (GraalVM native image, -Xrs, restricted/embedded JVMs).
Those would now escape start() and fail activation of diagnostic bundle, which is the exact "Signal not available" case this catch is meant to tolerate.
Please keep catch (Throwable e) (or catch Exception | LinkageError).
| new Class<?>[] { | ||
| signalHandlerClass | ||
| }, | ||
| (proxy, method, args) -> { |
There was a problem hiding this comment.
The proxy ignores method, so every call dispatched to this handler (including Object.equals/hashCode/toString) triggers a full diagnostic dump zip in the working directory.
I suggest the following guarding:
(proxy, method, args) -> {
if ("handle".equals(method.getName())) {
handle();
return null;
}
return method.invoke(this, args); // Object methods
}| public void handle(Signal signal) { | ||
|
|
||
| private void handle() { |
There was a problem hiding this comment.
Dump.dump (collect and zip everything) runs synchronously on the JVM signal-dispatch thread here. Main.registerSignalHandler deliberately offloads its handler body to new Thread(...).
This is pre-existing behaviour, but since the method being rewritten anyway it would be a good moment to match Main and run the dump on a short-lived thread.
This avoids warnings during compilation which are printed in every CI summary.
sun.misc.Signal and SignalHandler are internal proprietary APIs. The approach is taken over from Main.java.