提交 a1f0471a 编写于 作者: A alanb

6879463: (file) DirectoryStream#iterator's remove method throws wrong...

6879463: (file) DirectoryStream#iterator's remove method throws wrong exception when stream is closed
Reviewed-by: sherman
上级 585ef699
......@@ -235,7 +235,8 @@ class UnixDirectoryStream
@Override
public void remove() {
if (isClosed) {
throw new ClosedDirectoryStreamException();
throwAsConcurrentModificationException(new
ClosedDirectoryStreamException());
}
Path entry;
synchronized (this) {
......
......@@ -179,7 +179,7 @@ class WindowsDirectoryStream
synchronized (closeLock) {
if (!isOpen)
throwAsConcurrentModificationException(new
IllegalStateException("Directory stream is closed"));
ClosedDirectoryStreamException());
try {
name = FindNextFile(handle, findDataBuffer.address());
if (name == null) {
......@@ -236,7 +236,8 @@ class WindowsDirectoryStream
@Override
public void remove() {
if (!isOpen) {
throw new IllegalStateException("Directory stream is closed");
throwAsConcurrentModificationException(new
ClosedDirectoryStreamException());
}
Path entry;
synchronized (this) {
......
......@@ -154,8 +154,10 @@ public class Basic {
stream.close();
// test IllegalStateException
dir.resolve(foo).createFile();
stream = dir.newDirectoryStream();
i = stream.iterator();
i.next();
try {
stream.iterator();
throw new RuntimeException("IllegalStateException not thrown as expected");
......@@ -172,17 +174,26 @@ public class Basic {
throw new RuntimeException("ConcurrentModificationException not thrown as expected");
} catch (ConcurrentModificationException x) {
Throwable t = x.getCause();
if (!(t instanceof IllegalStateException))
throw new RuntimeException("Cause is not IllegalStateException as expected");
if (!(t instanceof ClosedDirectoryStreamException))
throw new RuntimeException("Cause is not ClosedDirectoryStreamException as expected");
}
try {
i.next();
throw new RuntimeException("IllegalStateException not thrown as expected");
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");
}
try {
i.remove();
throw new RuntimeException("ConcurrentModificationException not thrown as expected");
} catch (ConcurrentModificationException x) {
Throwable t = x.getCause();
if (!(t instanceof IllegalStateException))
throw new RuntimeException("Cause is not IllegalStateException as expected");
if (!(t instanceof ClosedDirectoryStreamException))
throw new RuntimeException("Cause is not ClosedDirectoryStreamException as expected");
}
}
public static void main(String[] args) throws IOException {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册