elastic / elastic/support-diagnostics
java.lang.NoClassDefFoundError on stdout redirection (or non tty)
- Dominant language
- Java
- Stars
- 304
- Forks
- 175
- PR merge metrics
- No merged PRs in 30d
Description
As soon as I run diagnostics with stdout redirected I get a java.lang.NoClassDefFoundError
Example:
```
$ ./diagnostics.sh --help > /tmp/log.txt
X11 connection rejected because of wrong authentication.
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class com.elastic.support.util.ResourceCache
at com.elastic.support.diagnostics.DiagnosticApp.main(DiagnosticApp.java:49)
$ ./diagnostics.sh --help
Using /usr/bin/java as Java Runtime
Using -Xms256m -Xmx2000m for options.
2020-12-29 08:36:25,808 main ERROR Unable to locate appender "diag" for logger config "root"
Processing diagnosticInputs...
Usage: [options]
Options:
...
```
But this also happens when executed with a complete command with all the parameters.
Same exception as soon as I add a ```> /tmp/log.txt``` or even just a simple ``` 2>&1 | less```
But it also happens when executed from an ansible task
It looks as if the tool tries to start X11 when stdout is redirected to a file (or not a tty) and DISPLAY is set (say ssh to a host and then switch users with ```sudo su -```).
Why it also happens in ansible task is unclear (but in ansible the script is obviously not run with a tty setting).
the workarounds I found are:
* on the shell: ```unset DISPLAY```
* in ansible: ```script -qefc './diagnostics.sh ...'``` (this in the end simulates a TTY)
This is not really very intuitive!
Contributor guide
Assessment
This issue has not been assessed yet.