mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-24 04:54:40 +02:00
6879463: (file) DirectoryStream#iterator's remove method throws wrong exception when stream is closed
Reviewed-by: sherman
This commit is contained in:
parent
1ff76e3938
commit
b712d23c2f
3 changed files with 21 additions and 8 deletions
|
@ -235,7 +235,8 @@ class UnixDirectoryStream
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if (isClosed) {
|
if (isClosed) {
|
||||||
throw new ClosedDirectoryStreamException();
|
throwAsConcurrentModificationException(new
|
||||||
|
ClosedDirectoryStreamException());
|
||||||
}
|
}
|
||||||
Path entry;
|
Path entry;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
|
|
@ -179,7 +179,7 @@ class WindowsDirectoryStream
|
||||||
synchronized (closeLock) {
|
synchronized (closeLock) {
|
||||||
if (!isOpen)
|
if (!isOpen)
|
||||||
throwAsConcurrentModificationException(new
|
throwAsConcurrentModificationException(new
|
||||||
IllegalStateException("Directory stream is closed"));
|
ClosedDirectoryStreamException());
|
||||||
try {
|
try {
|
||||||
name = FindNextFile(handle, findDataBuffer.address());
|
name = FindNextFile(handle, findDataBuffer.address());
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
|
@ -236,7 +236,8 @@ class WindowsDirectoryStream
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
throw new IllegalStateException("Directory stream is closed");
|
throwAsConcurrentModificationException(new
|
||||||
|
ClosedDirectoryStreamException());
|
||||||
}
|
}
|
||||||
Path entry;
|
Path entry;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
|
|
@ -154,8 +154,10 @@ public class Basic {
|
||||||
stream.close();
|
stream.close();
|
||||||
|
|
||||||
// test IllegalStateException
|
// test IllegalStateException
|
||||||
|
dir.resolve(foo).createFile();
|
||||||
stream = dir.newDirectoryStream();
|
stream = dir.newDirectoryStream();
|
||||||
i = stream.iterator();
|
i = stream.iterator();
|
||||||
|
i.next();
|
||||||
try {
|
try {
|
||||||
stream.iterator();
|
stream.iterator();
|
||||||
throw new RuntimeException("IllegalStateException not thrown as expected");
|
throw new RuntimeException("IllegalStateException not thrown as expected");
|
||||||
|
@ -172,17 +174,26 @@ public class Basic {
|
||||||
throw new RuntimeException("ConcurrentModificationException not thrown as expected");
|
throw new RuntimeException("ConcurrentModificationException not thrown as expected");
|
||||||
} catch (ConcurrentModificationException x) {
|
} catch (ConcurrentModificationException x) {
|
||||||
Throwable t = x.getCause();
|
Throwable t = x.getCause();
|
||||||
if (!(t instanceof IllegalStateException))
|
if (!(t instanceof ClosedDirectoryStreamException))
|
||||||
throw new RuntimeException("Cause is not IllegalStateException as expected");
|
throw new RuntimeException("Cause is not ClosedDirectoryStreamException as expected");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
i.next();
|
i.next();
|
||||||
throw new RuntimeException("IllegalStateException not thrown as expected");
|
throw new RuntimeException("ConcurrentModificationException not thrown as expected");
|
||||||
} catch (ConcurrentModificationException x) {
|
} catch (ConcurrentModificationException x) {
|
||||||
Throwable t = x.getCause();
|
Throwable t = x.getCause();
|
||||||
if (!(t instanceof IllegalStateException))
|
if (!(t instanceof ClosedDirectoryStreamException))
|
||||||
throw new RuntimeException("Cause is not IllegalStateException as expected");
|
throw new RuntimeException("Cause is not ClosedDirectoryStreamException as expected");
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
i.remove();
|
||||||
|
throw new RuntimeException("ConcurrentModificationException not thrown as expected");
|
||||||
|
} catch (ConcurrentModificationException x) {
|
||||||
|
Throwable t = x.getCause();
|
||||||
|
if (!(t instanceof ClosedDirectoryStreamException))
|
||||||
|
throw new RuntimeException("Cause is not ClosedDirectoryStreamException as expected");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue