Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Loth2017-03-13 01:50:04 -0400
committerSarika Sinha2017-03-13 01:50:04 -0400
commitc9e938ae8fd6b46887a9f105eff6c2cfd688e51c (patch)
treecd3b5f37e521635988a6436d512fa58f639c22d2
parent74181464f9d41d73883c744ad09c16e814d1f126 (diff)
downloadeclipse.platform.debug-I20170313-2000.tar.gz
eclipse.platform.debug-I20170313-2000.tar.xz
eclipse.platform.debug-I20170313-2000.zip
Bug 513367 - IllegalStateException while decoding output to ConsoleI20170315-2000I20170315-0500I20170314-2000I20170313-2000
Stream Change-Id: Ia205ed73daab72454193a33c7e3abf053186caa5 Signed-off-by: Andreas Loth <andy_2639@justmail.de>
-rw-r--r--org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleTests.java55
-rw-r--r--org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsoleOutputStream.java6
2 files changed, 60 insertions, 1 deletions
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleTests.java
index b683fe22e..fb05f3ef5 100644
--- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleTests.java
+++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleTests.java
@@ -65,7 +65,7 @@ public class ConsoleTests extends TestCase {
String testString = "a\r"; //$NON-NLS-1$
byte[] testStringBuffer = testString.getBytes(StandardCharsets.UTF_8);
TestCase.assertEquals("Test string \"" + testString + "\" should consist of 2 UTF-8 bytes", 2, testStringBuffer.length); //$NON-NLS-1$ //$NON-NLS-2$
- MessageConsole console = new MessageConsole("Test Console", //$NON-NLS-1$
+ MessageConsole console = new MessageConsole("Test Console 2", //$NON-NLS-1$
IConsoleConstants.MESSAGE_CONSOLE_TYPE, null, StandardCharsets.UTF_8.name(), true);
IDocument document = console.getDocument();
TestHelper.waitForJobs();
@@ -82,4 +82,57 @@ public class ConsoleTests extends TestCase {
TestCase.assertEquals("closing the stream should write the pending \\r", testString, document.get()); //$NON-NLS-1$
}
+ public void testConsoleOutputStreamDocumentClosed() throws IOException {
+ MessageConsole console = new MessageConsole("Test Console 3", //$NON-NLS-1$
+ IConsoleConstants.MESSAGE_CONSOLE_TYPE, null, StandardCharsets.UTF_8.name(), true);
+ IDocument document = console.getDocument();
+ try (IOConsoleOutputStream outStream = console.newOutputStream()) {
+ outStream.write("write1"); //$NON-NLS-1$
+ document.getDocumentPartitioner().disconnect();
+ try {
+ outStream.write("write2"); //$NON-NLS-1$
+ TestCase.fail("IOException with message \"Document is closed\" expected"); //$NON-NLS-1$
+ } catch (IOException ioe) {
+ TestCase.assertEquals("Document is closed", ioe.getMessage()); //$NON-NLS-1$
+ }
+ }
+ }
+
+ public void testConsoleOutputStreamClosed() throws IOException {
+ MessageConsole console = new MessageConsole("Test Console 4", //$NON-NLS-1$
+ IConsoleConstants.MESSAGE_CONSOLE_TYPE, null, StandardCharsets.UTF_8.name(), true);
+ try (IOConsoleOutputStream outStream = console.newOutputStream()) {
+ outStream.write("test1".getBytes(StandardCharsets.UTF_8)); //$NON-NLS-1$
+ outStream.close();
+ try {
+ outStream.write("test2".getBytes(StandardCharsets.UTF_8)); //$NON-NLS-1$
+ TestCase.fail("IOException with message \"Output Stream is closed\" expected"); //$NON-NLS-1$
+ } catch (IOException ioe) {
+ TestCase.assertEquals("Output Stream is closed", ioe.getMessage()); //$NON-NLS-1$
+ }
+ }
+ }
+
+ public void testConsoleOutputStreamDocumentStreamClosed() throws IOException {
+ MessageConsole console = new MessageConsole("Test Console 5", //$NON-NLS-1$
+ IConsoleConstants.MESSAGE_CONSOLE_TYPE, null, StandardCharsets.UTF_8.name(), true);
+ IDocument document = console.getDocument();
+ try (IOConsoleOutputStream outStream = console.newOutputStream()) {
+ outStream.write("write1"); //$NON-NLS-1$
+ document.getDocumentPartitioner().disconnect();
+ try {
+ outStream.write("write2"); //$NON-NLS-1$
+ TestCase.fail("IOException with message \"Document is closed\" expected"); //$NON-NLS-1$
+ } catch (IOException ioe) {
+ TestCase.assertEquals("Document is closed", ioe.getMessage()); //$NON-NLS-1$
+ }
+ try {
+ outStream.write("write3"); //$NON-NLS-1$
+ TestCase.fail("IOException with message \"Output Stream is closed\" expected"); //$NON-NLS-1$
+ } catch (IOException ioe) {
+ TestCase.assertEquals("Output Stream is closed", ioe.getMessage()); //$NON-NLS-1$
+ }
+ }
+ }
+
}
diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsoleOutputStream.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsoleOutputStream.java
index 8ee47071f..0cba219c1 100644
--- a/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsoleOutputStream.java
+++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsoleOutputStream.java
@@ -199,6 +199,9 @@ public class IOConsoleOutputStream extends OutputStream {
*/
@Override
public synchronized void write(byte[] b, int off, int len) throws IOException {
+ if (closed) {
+ throw new IOException("Output Stream is closed"); //$NON-NLS-1$
+ }
StringBuilder builder = new StringBuilder();
this.decoder.decode(builder, b, off, len);
encodedWrite(builder.toString());
@@ -323,6 +326,9 @@ public class IOConsoleOutputStream extends OutputStream {
* @since 3.7
*/
public synchronized void setCharset(Charset charset) throws IOException {
+ if (closed) {
+ throw new IOException("Output Stream is closed"); //$NON-NLS-1$
+ }
StringBuilder builder = new StringBuilder();
this.decoder.finish(builder);
if (builder.length() > 0) {

Back to the top