Bug 563580

Summary: Change to try-with-resources results in IOException
Product: [Eclipse Project] Platform Reporter: Michael Wohlfart <michael.wohlfart>
Component: TextAssignee: Platform-Text-Inbox <platform-text-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: loskutov
Version: 4.7Keywords: needinfo
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=500153
Whiteboard:
Attachments:
Description Flags
The code location causing the IOException none

Description Michael Wohlfart CLA 2020-05-26 05:55:09 EDT
Created attachment 283017 [details]
The code location causing the IOException

With https://bugs.eclipse.org/bugs/show_bug.cgi?id=500153 the method org.eclipse.core.internal.filebuffers.FileStoreTextFileBuffer.setFileContents(...)  was changed to use try-with-resources. This change now leads to an IOException.

When the output stream is fully read it is closed by the code. Up until the change of Bug 500153 this was completely ok. After the change, the Java runtime will try to close the stream again (auto-closable) which leads to the IOException

Link to code: https://git.eclipse.org/c/platform/eclipse.platform.text.git/tree/org.eclipse.core.filebuffers/src/org/eclipse/core/internal/filebuffers/FileStoreTextFileBuffer.java
Comment 1 Andrey Loskutov CLA 2020-05-26 06:19:12 EDT
Interesting. Can you provide the stack trace or a sample code producing the IOException? Few default implementations of OutputStream I've checked shouldn't throw on calling close() two times, just wondering which one you have in mind.
Comment 2 Michael Wohlfart CLA 2020-05-26 07:53:17 EDT
Hmm.. the documentation of Closeable.close() says that invoking it on an already closed stream does not have any effect. This indeed points to a file store implementation that does not honor this contract. Thanks for the hint, looking further into this...