Skip to content

Commit

Permalink
Fix possible NPE in Diag
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jun 13, 2022
1 parent adace24 commit 811de60
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions terminal/src/main/java/org/jline/terminal/impl/Diag.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,26 @@ private static void testProvider(PrintStream out, TerminalProvider provider) {
}
try (Terminal terminal = provider.sysTerminal("diag", "xterm", false, StandardCharsets.UTF_8,
false, Terminal.SignalHandler.SIG_DFL, false, TerminalProvider.Stream.Output) ) {
Attributes attr = terminal.enterRawMode();
try {
ForkJoinTask<Integer> t = new ForkJoinPool(1).submit(() -> terminal.reader().read(1) );
int r = t.get(1000, TimeUnit.MILLISECONDS);
StringBuilder sb = new StringBuilder();
sb.append("The terminal seems to work: ");
sb.append("terminal ").append(terminal.getClass().getName());
if (terminal instanceof AbstractPosixTerminal) {
sb.append(" with pty ").append(((AbstractPosixTerminal) terminal).getPty().getClass().getName());
if (terminal != null) {
Attributes attr = terminal.enterRawMode();
try {
ForkJoinTask<Integer> t = new ForkJoinPool(1).submit(() -> terminal.reader().read(1) );
int r = t.get(1000, TimeUnit.MILLISECONDS);
StringBuilder sb = new StringBuilder();
sb.append("The terminal seems to work: ");
sb.append("terminal ").append(terminal.getClass().getName());
if (terminal instanceof AbstractPosixTerminal) {
sb.append(" with pty ").append(((AbstractPosixTerminal) terminal).getPty().getClass().getName());
}
out.println(sb);
} catch (Throwable t3) {
out.println("Unable to read from terminal: " + t3);
t3.printStackTrace();
} finally {
terminal.setAttributes(attr);
}
out.println(sb);
} catch (Throwable t3) {
out.println("Unable to read from terminal: " + t3);
t3.printStackTrace();
} finally {
terminal.setAttributes(attr);
} else {
out.println("Not supported by provider");
}
} catch (Throwable t2) {
out.println("Unable to open terminal: " + t2);
Expand Down

0 comments on commit 811de60

Please sign in to comment.