diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ByteArrayChannel.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ByteArrayChannel.java index db053280076..84e122a835b 100644 --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ByteArrayChannel.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ByteArrayChannel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -194,11 +194,11 @@ public class ByteArrayChannel implements SeekableByteChannel { throw new ClosedChannelException(); } - private final void beginWrite() { + final void beginWrite() { rwlock.writeLock().lock(); } - private final void endWrite() { + final void endWrite() { rwlock.writeLock().unlock(); } diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java index cba76e1bc59..c12143d357b 100644 --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java @@ -892,11 +892,18 @@ class ZipFileSystem extends FileSystem { @Override public void close() throws IOException { - // will update the entry - try (OutputStream os = getOutputStream(e)) { - os.write(toByteArray()); + super.beginWrite(); + try { + if (!isOpen()) + return; + // will update the entry + try (OutputStream os = getOutputStream(e)) { + os.write(toByteArray()); + } + super.close(); + } finally { + super.endWrite(); } - super.close(); } } diff --git a/test/jdk/jdk/nio/zipfs/testng/test/ChannelTests.java b/test/jdk/jdk/nio/zipfs/testng/test/ChannelTests.java index b48d021b4bb..3c7d18988b7 100644 --- a/test/jdk/jdk/nio/zipfs/testng/test/ChannelTests.java +++ b/test/jdk/jdk/nio/zipfs/testng/test/ChannelTests.java @@ -339,14 +339,12 @@ public class ChannelTests extends ZipFsBaseTest { /** * Validate when SeekableByteChannel::close is called more than once, that * no error occurs - *
- * Note: this is currently disabled due to bug JDK-8241883
*
* @param env Zip FS properties to use when creating the Zip file
* @param compression The compression used when writing the entries
* @throws Exception If an error occurs
*/
- @Test(dataProvider = "zipfsMap", enabled = false)
+ @Test(dataProvider = "zipfsMap")
public void sbcCloseTest(final Map