hansva opened a new issue, #9570:
URL: https://github.com/apache/hop/issues/9570
### Apache Hop version?
2.21.0-SNAPSHOT
### Java version?
21
### Operating system
Other
### What happened?
`SessionDisplay.current()` and `SessionDisplay.currentOrDefault()` answer
"does this thread have a display?" and are documented to never throw: no
display, or a destroyed Hop Web session, gives `null`. Both only catch
`RuntimeException`:
try {
return Display.getCurrent();
} catch (RuntimeException e) {
return null;
}
When SWT can't provide a display, it fails with an `Error`, not a
`RuntimeException`, so the error escapes to the caller:
| Situation | What SWT throws |
|---|---|
| SWT not on the classpath (headless install, server, command line) |
`NoClassDefFoundError` when `Display` is first touched |
| SWT natives can't be loaded (wrong platform jar, missing GTK libraries) |
`UnsatisfiedLinkError`, then `NoClassDefFoundError: Could not initialize class
...Display` on later calls |
| SWT present but no display server (Linux without X/Wayland, a container) |
`SWTError: No more handles` from `Display.getDefault()` in `currentOrDefault()`
|
The callers use `SessionDisplay` precisely to decide whether they may touch
the UI: the Lint plugin (`LintProblemsBarManager`, `LintCanvasOverlayRefresh`,
`LintStatusFilePainter`), the Testing plugin (`TestingGuiPlugin`),
`HopNamespace`, `TreeMemory` and `SashFormMemory`. Instead of "no display, skip
the UI work", they get an `Error`, which typically isn't caught and stops the
command, run or server request it happens in.
### Expected
Both methods return `null` whenever there is no usable display, whatever the
reason, as their documentation says. Errors that mean the JVM itself is in
trouble (`OutOfMemoryError`, `StackOverflowError`) still propagate.
### Proposed fix
In `current()` and `currentOrDefault()`, also treat the "no SWT / no
display" errors as "no display":
} catch (RuntimeException | LinkageError e) {
return null;
} catch (Error e) {
// SWTError ("No more handles") when there is no display server; not
named here,
// so this class still loads without SWT. The JVM's own errors still
propagate.
if (e instanceof VirtualMachineError) {
throw e;
}
return null;
}
`SWTError` isn't caught by name on purpose: referring to it would need the
SWT class to be loadable to match the catch clause, which is exactly the case
being handled.
### Tests
- With `Display` unavailable (e.g. a test class loader that hides
`org.eclipse.swt`, or the `WithoutSwt` helper from #9501), `current()` and
`currentOrDefault()` return `null` instead of throwing.
- `currentOrDefault()` when `Display.getDefault()` throws an `SWTError`:
returns `null`.
- A `VirtualMachineError` is not swallowed.
### Issue Priority
Priority: 2
### Issue Component
Component: API, Component: Hop Gui
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]