Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 513367

Summary: IllegalStateException while decoding output to Console Stream
Product: [Eclipse Project] Platform Reporter: Sarika Sinha <sarika.sinha>
Component: DebugAssignee: Andreas Loth <andy_2639>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 4.6   
Target Milestone: 4.7 M7   
Hardware: PC   
OS: Windows 7   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=507664
Whiteboard:
Bug Depends on:    
Bug Blocks: 507664    
Attachments:
Description Flags
Check that stream is not closed before using decoder
none
Test cases for writing to closed streams / streams with closed documents
none
Test suites console output none

Description Sarika Sinha CLA 2017-03-09 04:52:51 EST
java.lang.IllegalStateException: Current state = FLUSHED, new state = CODING
	at java.nio.charset.CharsetDecoder.throwIllegalStateException(CharsetDecoder.java:992)
	at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:572)
	at org.eclipse.ui.internal.console.StreamDecoder.internalDecode(StreamDecoder.java:58)
	at org.eclipse.ui.internal.console.StreamDecoder.decode(StreamDecoder.java:80)
	at org.eclipse.ui.console.IOConsoleOutputStream.write(IOConsoleOutputStream.java:203)
	at org.eclipse.ui.console.IOConsoleOutputStream.write(IOConsoleOutputStream.java:212)
	at org.eclipse.debug.internal.ui.views.console.ProcessConsole$StreamListener.streamAppended(ProcessConsole.java:639)
	at org.eclipse.debug.internal.core.OutputStreamMonitor$ContentNotifier.run(OutputStreamMonitor.java:267)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.debug.internal.core.OutputStreamMonitor$ContentNotifier.notifyAppend(OutputStreamMonitor.java:277)
	at org.eclipse.debug.internal.core.OutputStreamMonitor.fireStreamAppended(OutputStreamMonitor.java:118)
	at org.eclipse.debug.internal.core.OutputStreamMonitor.read(OutputStreamMonitor.java:159)
	at org.eclipse.debug.internal.core.OutputStreamMonitor.access$1(OutputStreamMonitor.java:137)
	at org.eclipse.debug.internal.core.OutputStreamMonitor$1.run(OutputStreamMonitor.java:212)
	at java.lang.Thread.run(Thread.java:745)
  
  java.io.IOException: Document is closed
	at org.eclipse.ui.internal.console.IOConsolePartitioner.streamAppended(IOConsolePartitioner.java:462)
	at org.eclipse.ui.console.IOConsoleOutputStream.notifyParitioner(IOConsoleOutputStream.java:290)
	at org.eclipse.ui.console.IOConsoleOutputStream.encodedWrite(IOConsoleOutputStream.java:285)
	at org.eclipse.ui.console.IOConsoleOutputStream.write(IOConsoleOutputStream.java:204)
	at org.eclipse.ui.console.IOConsoleOutputStream.write(IOConsoleOutputStream.java:212)
	at org.eclipse.debug.internal.ui.views.console.ProcessConsole$StreamListener.streamAppended(ProcessConsole.java:639)
	at org.eclipse.debug.internal.core.OutputStreamMonitor$ContentNotifier.run(OutputStreamMonitor.java:267)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.debug.internal.core.OutputStreamMonitor$ContentNotifier.notifyAppend(OutputStreamMonitor.java:277)
	at org.eclipse.debug.internal.core.OutputStreamMonitor.fireStreamAppended(OutputStreamMonitor.java:118)
	at org.eclipse.debug.internal.core.OutputStreamMonitor.read(OutputStreamMonitor.java:159)
	at org.eclipse.debug.internal.core.OutputStreamMonitor.access$1(OutputStreamMonitor.java:137)
	at org.eclipse.debug.internal.core.OutputStreamMonitor$1.run(OutputStreamMonitor.java:212)
	at java.lang.Thread.run(Thread.java:745)
Comment 1 Andreas Loth CLA 2017-03-11 05:51:41 EST
Created attachment 267217 [details]
Check that stream is not closed before using decoder

The check for a closed stream was only in encodedWrite, which is fine when other methods don't do anything which relies on an open stream.

However, write(byte[] b, int off, int len) now uses the decoder which must not be used after the stream was closed.

Fix: do a stream closed check in write(byte[] b, int off, int len) and setCharset(Charset charset). This check throws an IOException when the stream is closed. This produces a better error message than the IllegalStateException.
Comment 2 Andreas Loth CLA 2017-03-11 05:52:29 EST
Created attachment 267218 [details]
Test cases for writing to closed streams / streams with closed documents
Comment 3 Andreas Loth CLA 2017-03-11 05:55:54 EST
(In reply to Sarika Sinha from comment #0)

>   java.io.IOException: Document is closed

I don't know what this exception should tell me.
Comment 4 Sarika Sinha CLA 2017-03-13 01:52:57 EDT
Thanks Andreas,
Released the changes with
http://git.eclipse.org/c/platform/eclipse.platform.debug.git/commit/?id=c9e938ae8fd6b46887a9f105eff6c2cfd688e51c
Comment 5 Sarika Sinha CLA 2017-03-13 01:53:40 EDT
(In reply to Andreas Loth from comment #3)
> (In reply to Sarika Sinha from comment #0)
> 
> >   java.io.IOException: Document is closed
> 
> I don't know what this exception should tell me.

The point is to analyze why the document is closed, is it a timing issue in test case or a genuine problem?
Comment 6 Andreas Loth CLA 2017-03-20 14:29:52 EDT
(In reply to Sarika Sinha from comment #5)
> The point is to analyze why the document is closed, is it a timing issue in
> test case or a genuine problem?

Which test case fails? Does it fail always (reproducible) or only sometimes?
Comment 7 Sarika Sinha CLA 2017-03-21 04:32:52 EDT
Test is not failing but if you run Platform Debug test suite, you can see many of these exceptions in the console.
Comment 8 Andreas Loth CLA 2017-03-26 02:29:23 EDT
Created attachment 267466 [details]
Test suites console output

(In reply to Sarika Sinha from comment #7)
> Test is not failing but if you run Platform Debug test suite, you can see
> many of these exceptions in the console.

On my computer (Windows 10 Pro x64 Anniversary Update), I ran the test suites AutomatedSuite, LocalSuite, and PerformanceSuite. Neither of the suites produced a java.io.IOException: Document is closed.

I attached the console output of the test suites.

However, the tests
testPreserveExpandedOnContentStress,
testPreserveLargeModelOnContent, JFaceViewerPerformanceTests.testRefreshListFiltered, and
VirtualViewerPerformanceTests.testRefreshListFiltered
failed on my system. I included the stacktraces in the attached zip file.

I used the Platform Debug master branch at commit dc90c09f030a8347a715054261d62b973fdb3d92. The target definition I'm using is included in the zip.
Comment 9 Sarika Sinha CLA 2017-03-27 06:04:08 EDT
Thanks, I am also not observing them now.