8241883: (zipfs) SeekableByteChannel:close followed by SeekableByteChannel:close will throw an NPE coverage
Reviewed-by: clanger, alanb
This commit is contained in:
parent
f11d4628c1
commit
93831d4ed2
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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();
|
throw new ClosedChannelException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void beginWrite() {
|
final void beginWrite() {
|
||||||
rwlock.writeLock().lock();
|
rwlock.writeLock().lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void endWrite() {
|
final void endWrite() {
|
||||||
rwlock.writeLock().unlock();
|
rwlock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -892,11 +892,18 @@ class ZipFileSystem extends FileSystem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
|
super.beginWrite();
|
||||||
|
try {
|
||||||
|
if (!isOpen())
|
||||||
|
return;
|
||||||
// will update the entry
|
// will update the entry
|
||||||
try (OutputStream os = getOutputStream(e)) {
|
try (OutputStream os = getOutputStream(e)) {
|
||||||
os.write(toByteArray());
|
os.write(toByteArray());
|
||||||
}
|
}
|
||||||
super.close();
|
super.close();
|
||||||
|
} finally {
|
||||||
|
super.endWrite();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,14 +339,12 @@ public class ChannelTests extends ZipFsBaseTest {
|
|||||||
/**
|
/**
|
||||||
* Validate when SeekableByteChannel::close is called more than once, that
|
* Validate when SeekableByteChannel::close is called more than once, that
|
||||||
* no error occurs
|
* 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 env Zip FS properties to use when creating the Zip file
|
||||||
* @param compression The compression used when writing the entries
|
* @param compression The compression used when writing the entries
|
||||||
* @throws Exception If an error occurs
|
* @throws Exception If an error occurs
|
||||||
*/
|
*/
|
||||||
@Test(dataProvider = "zipfsMap", enabled = false)
|
@Test(dataProvider = "zipfsMap")
|
||||||
public void sbcCloseTest(final Map<String, String> env,
|
public void sbcCloseTest(final Map<String, String> env,
|
||||||
final int compression) throws Exception {
|
final int compression) throws Exception {
|
||||||
Path zipFile = generatePath(HERE, "test", ".zip");
|
Path zipFile = generatePath(HERE, "test", ".zip");
|
||||||
|
Loading…
Reference in New Issue
Block a user