From 0334a2e1ed572cd6b967f2cb663cd97c30984dba Mon Sep 17 00:00:00 2001 From: Martin Oberhuber < martin.oberhuber@windriver.com> Date: Tue, 30 Oct 2007 23:19:13 +0000 Subject: [PATCH] [207785] NPE when trying to send char while no longer connected --- .../emulator/VT100TerminalControl.java | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java index 1760fab6d7b..b0d0c81494c 100644 --- a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java +++ b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java @@ -16,6 +16,7 @@ * Martin Oberhuber (Wind River) - [206892] State handling: Only allow connect when CLOSED * Martin Oberhuber (Wind River) - [206883] Serial Terminal leaks Jobs * Martin Oberhuber (Wind River) - [208145] Terminal prints garbage after quick disconnect/reconnect + * Martin Oberhuber (Wind River) - [207785] NPE when trying to send char while no longer connected *******************************************************************************/ package org.eclipse.tm.internal.terminal.emulator; @@ -419,27 +420,31 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC protected void sendChar(char chKey, boolean altKeyPressed) { try { int byteToSend = chKey; - - if (altKeyPressed) { - // When the ALT key is pressed at the same time that a character is - // typed, translate it into an ESCAPE followed by the character. The - // alternative in this case is to set the high bit of the character - // being transmitted, but that will cause input such as ALT-f to be - // seen as the ISO Latin-1 character '�', which can be confusing to - // European users running Emacs, for whom Alt-f should move forward a - // word instead of inserting the '�' character. - // - // TODO: Make the ESCAPE-vs-highbit behavior user configurable. - - Logger.log("sending ESC + '" + byteToSend + "'"); //$NON-NLS-1$ //$NON-NLS-2$ - getOutputStream().write('\u001b'); - getOutputStream().write(byteToSend); + OutputStream os = getOutputStream(); + if (os==null) { + // Bug 207785: NPE when trying to send char while no longer connected + Logger.log("NOT sending '" + byteToSend + "' because no longer connected"); //$NON-NLS-1$ //$NON-NLS-2$ } else { - Logger.log("sending '" + byteToSend + "'"); //$NON-NLS-1$ //$NON-NLS-2$ - getOutputStream().write(byteToSend); - } + if (altKeyPressed) { + // When the ALT key is pressed at the same time that a character is + // typed, translate it into an ESCAPE followed by the character. The + // alternative in this case is to set the high bit of the character + // being transmitted, but that will cause input such as ALT-f to be + // seen as the ISO Latin-1 character '�', which can be confusing to + // European users running Emacs, for whom Alt-f should move forward a + // word instead of inserting the '�' character. + // + // TODO: Make the ESCAPE-vs-highbit behavior user configurable. - getOutputStream().flush(); + Logger.log("sending ESC + '" + byteToSend + "'"); //$NON-NLS-1$ //$NON-NLS-2$ + getOutputStream().write('\u001b'); + getOutputStream().write(byteToSend); + } else { + Logger.log("sending '" + byteToSend + "'"); //$NON-NLS-1$ //$NON-NLS-2$ + getOutputStream().write(byteToSend); + } + getOutputStream().flush(); + } } catch (SocketException socketException) { Logger.logException(socketException);