Fixed exception when closing channel that was opened with exception

This commit is contained in:
Markus Kreusch
2016-01-17 19:01:54 +01:00
parent 9278426131
commit 0a1eaa8600

View File

@@ -40,11 +40,19 @@ class SharedFileChannel {
public void open(OpenMode mode) {
doLocked(() -> {
Thread thread = Thread.currentThread();
if (openedBy.put(thread, thread) != null) {
throw new IllegalStateException("SharedFileChannel already open for current thread");
}
if (delegate == null) {
createChannel(mode);
boolean failed = true;
try {
if (openedBy.put(thread, thread) != null) {
throw new IllegalStateException("SharedFileChannel already open for current thread");
}
if (delegate == null) {
createChannel(mode);
}
failed = false;
} finally {
if (failed) {
openedBy.remove(thread);
}
}
});
}