Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2019-04-22 18:19:01 -0400
committerAndrey Loskutov2019-04-22 18:20:07 -0400
commitb621bc2634284592c44a531de4746470e56c261c (patch)
treeae76d660f09d7ea80e720b14202ce3cc8f6b2490
parente5b4f42c768864837d6f15b5b2db8861d35f7829 (diff)
downloadeclipse.platform.debug-b621bc2634284592c44a531de4746470e56c261c.tar.gz
eclipse.platform.debug-b621bc2634284592c44a531de4746470e56c261c.tar.xz
eclipse.platform.debug-b621bc2634284592c44a531de4746470e56c261c.zip
Revert "Bug 307309 - [console] IOConsoleInputStream throws unwanted
IOExceptions" This reverts commit e5b4f42c768864837d6f15b5b2db8861d35f7829, which caused regression, see bug 307309 comment 19. Change-Id: Id399ccdc46235b7529415ba7473b777309a7f12d Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/ConsoleTests.java30
-rw-r--r--org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsoleInputStream.java19
2 files changed, 21 insertions, 28 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 b7950dc85..cd9d51eae 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2017, 2019 Andreas Loth and others.
+ * Copyright (c) 2017, 2018 Andreas Loth and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -37,6 +37,7 @@ import org.eclipse.ui.console.MessageConsole;
import junit.framework.TestCase;
+
public class ConsoleTests extends AbstractDebugTest {
public ConsoleTests() {
@@ -188,36 +189,15 @@ public class ConsoleTests extends AbstractDebugTest {
}
}
- /**
- * Tests for IOConsoleInputStream#available().
- *
- * @throws Exception if test fails
- */
public void testIOConsoleAvailable() throws Exception {
- IOConsole console = new IOConsole("", null);
- try (InputStream consoleInput = console.getInputStream()) {
- consoleInput.available();
- consoleInput.available();
- }
- console = new IOConsole("", null);
- try (InputStream consoleInput = console.getInputStream()) {
- consoleInput.available();
- new Thread(() -> {
- try {
- Thread.sleep(100);
- consoleInput.close();
- } catch (Exception e) {
- }
- }).start();
- assertEquals("read() did not signaled EOF.", -1, consoleInput.read());
- }
+ final IOConsole console = new IOConsole("", null);
- console = new IOConsole("", null);
try (InputStream consoleInput = console.getInputStream()) {
- consoleInput.close();
consoleInput.available();
consoleInput.available();
+ } catch (IOException ioe) {
+ TestCase.assertEquals("Input Stream is closed", ioe.getMessage()); //$NON-NLS-1$
}
}
}
diff --git a/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsoleInputStream.java b/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsoleInputStream.java
index 4cade5ad9..04bc9468f 100644
--- a/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsoleInputStream.java
+++ b/org.eclipse.ui.console/src/org/eclipse/ui/console/IOConsoleInputStream.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2018 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -54,6 +54,11 @@ public class IOConsoleInputStream extends InputStream {
private int size = 0;
/**
+ * Flag to indicate that EOF has been sent already.
+ */
+ private boolean eofSent = false;
+
+ /**
* Flag to indicate that the stream has been closed.
*/
private boolean closed = false;
@@ -86,7 +91,7 @@ public class IOConsoleInputStream extends InputStream {
@Override
public synchronized int read(byte[] b, int off, int len) throws IOException {
waitForData();
- if (available() == 0) {
+ if (available() == -1) {
return -1;
}
@@ -113,7 +118,7 @@ public class IOConsoleInputStream extends InputStream {
@Override
public synchronized int read() throws IOException {
waitForData();
- if (available() == 0) {
+ if (available() == -1) {
return -1;
}
@@ -247,6 +252,14 @@ public class IOConsoleInputStream extends InputStream {
@Override
public int available() throws IOException {
+ if (closed && eofSent) {
+ throw new IOException("Input Stream Closed"); //$NON-NLS-1$
+ } else if (size == 0) {
+ if (!eofSent) {
+ eofSent = true;
+ return -1;
+ }
+ }
return size;
}

Back to the top