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
@ -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 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.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 {
|
||||
|
Loading…
Reference in New Issue
Block a user