Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8241883: (zipfs) SeekableByteChannel:close followed by SeekableByteCh…
…annel:close will throw an NPE coverage

Reviewed-by: clanger, alanb
  • Loading branch information
Lance Andersen committed Apr 10, 2020
1 parent f11d462 commit 93831d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
@@ -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
Expand Down Expand Up @@ -194,11 +194,11 @@ private void ensureOpen() throws IOException {
throw new ClosedChannelException();
}

private final void beginWrite() {
final void beginWrite() {
rwlock.writeLock().lock();
}

private final void endWrite() {
final void endWrite() {
rwlock.writeLock().unlock();
}

Expand Down
15 changes: 11 additions & 4 deletions src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java
Expand Up @@ -892,11 +892,18 @@ private class EntryOutputChannel extends ByteArrayChannel {

@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();
}
}

Expand Down
4 changes: 1 addition & 3 deletions test/jdk/jdk/nio/zipfs/testng/test/ChannelTests.java
Expand Up @@ -339,14 +339,12 @@ public void sbcFAETest(final Map<String, String> env,
/**
* Validate when SeekableByteChannel::close is called more than once, that
* no error occurs
* <p>
* 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<String, String> env,
final int compression) throws Exception {
Path zipFile = generatePath(HERE, "test", ".zip");
Expand Down

0 comments on commit 93831d4

Please sign in to comment.