author | lancea |
Fri, 14 Dec 2018 14:17:22 -0500 | |
changeset 53031 | 0873841d1669 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1 |
/* |
53031
0873841d1669
8215372: Incorrect nio/file/DirectoryStream/Basic.java tests for validating the use of a glob
lancea
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
4 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
8 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
13 |
* accompanied this code). |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
14 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
18 |
* |
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
22 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
23 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
24 |
/* @test |
3065
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
25 |
* @bug 4313887 6838333 |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
26 |
* @summary Unit test for java.nio.file.DirectoryStream |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
27 |
* @library .. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
28 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
29 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
30 |
import java.nio.file.*; |
8158 | 31 |
import static java.nio.file.Files.*; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
32 |
import java.util.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
33 |
import java.io.IOException; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
34 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
35 |
public class Basic { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
36 |
static boolean found; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
37 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
38 |
static void doTest(final Path dir) throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
39 |
DirectoryStream<Path> stream; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
40 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
41 |
// test that directory is empty |
8158 | 42 |
try (DirectoryStream<Path> ds = newDirectoryStream(dir)) { |
43 |
if (ds.iterator().hasNext()) |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
44 |
throw new RuntimeException("directory not empty"); |
3065
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
45 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
46 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
47 |
// create file in directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
48 |
final Path foo = Paths.get("foo"); |
8158 | 49 |
createFile(dir.resolve(foo)); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
50 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
51 |
// iterate over directory and check there is one entry |
8158 | 52 |
stream = newDirectoryStream(dir); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
53 |
found = false; |
3065
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
54 |
try { |
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
55 |
for (Path entry: stream) { |
8158 | 56 |
if (entry.getFileName().equals(foo)) { |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
57 |
if (found) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
58 |
throw new RuntimeException("entry already found"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
59 |
found = true; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
60 |
} else { |
8158 | 61 |
throw new RuntimeException("entry " + entry.getFileName() + |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
62 |
" not expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
63 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
64 |
} |
3065
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
65 |
} finally { |
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
66 |
stream.close(); |
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
67 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
68 |
if (!found) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
69 |
throw new RuntimeException("entry not found"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
70 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
71 |
// check filtering: f* should match foo |
8580
d1585a92e376
7025468: Tests using diamond with anonymous inner classes needs to be reverted
alanb
parents:
8158
diff
changeset
|
72 |
DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() { |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
73 |
private PathMatcher matcher = |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
74 |
dir.getFileSystem().getPathMatcher("glob:f*"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
75 |
public boolean accept(Path file) { |
53031
0873841d1669
8215372: Incorrect nio/file/DirectoryStream/Basic.java tests for validating the use of a glob
lancea
parents:
47216
diff
changeset
|
76 |
return matcher.matches(file.getFileName()); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
77 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
78 |
}; |
53031
0873841d1669
8215372: Incorrect nio/file/DirectoryStream/Basic.java tests for validating the use of a glob
lancea
parents:
47216
diff
changeset
|
79 |
|
0873841d1669
8215372: Incorrect nio/file/DirectoryStream/Basic.java tests for validating the use of a glob
lancea
parents:
47216
diff
changeset
|
80 |
found = false; |
8158 | 81 |
try (DirectoryStream<Path> ds = newDirectoryStream(dir, filter)) { |
82 |
for (Path entry: ds) { |
|
53031
0873841d1669
8215372: Incorrect nio/file/DirectoryStream/Basic.java tests for validating the use of a glob
lancea
parents:
47216
diff
changeset
|
83 |
if (entry.getFileName().equals(foo)) |
0873841d1669
8215372: Incorrect nio/file/DirectoryStream/Basic.java tests for validating the use of a glob
lancea
parents:
47216
diff
changeset
|
84 |
found = true; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
85 |
} |
53031
0873841d1669
8215372: Incorrect nio/file/DirectoryStream/Basic.java tests for validating the use of a glob
lancea
parents:
47216
diff
changeset
|
86 |
if (!found) |
0873841d1669
8215372: Incorrect nio/file/DirectoryStream/Basic.java tests for validating the use of a glob
lancea
parents:
47216
diff
changeset
|
87 |
throw new RuntimeException(String.format("Error: entry: %s was not found", foo)); |
3065
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
88 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
89 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
90 |
// check filtering: z* should not match any files |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
91 |
filter = new DirectoryStream.Filter<Path>() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
92 |
private PathMatcher matcher = |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
93 |
dir.getFileSystem().getPathMatcher("glob:z*"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
94 |
public boolean accept(Path file) { |
53031
0873841d1669
8215372: Incorrect nio/file/DirectoryStream/Basic.java tests for validating the use of a glob
lancea
parents:
47216
diff
changeset
|
95 |
return matcher.matches(file.getFileName()); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
96 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
97 |
}; |
8158 | 98 |
try (DirectoryStream<Path> ds = newDirectoryStream(dir, filter)) { |
99 |
if (ds.iterator().hasNext()) |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
100 |
throw new RuntimeException("no matching entries expected"); |
3065
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
101 |
} |
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
102 |
|
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
103 |
// check that an IOException thrown by a filter is propagated |
3065
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
104 |
filter = new DirectoryStream.Filter<Path>() { |
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
105 |
public boolean accept(Path file) throws IOException { |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
106 |
throw new java.util.zip.ZipException(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
107 |
} |
3065
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
108 |
}; |
8158 | 109 |
stream = newDirectoryStream(dir, filter); |
3065
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
110 |
try { |
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
111 |
stream.iterator().hasNext(); |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
112 |
throw new RuntimeException("DirectoryIteratorException expected"); |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
113 |
} catch (DirectoryIteratorException x) { |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
114 |
IOException cause = x.getCause(); |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
115 |
if (!(cause instanceof java.util.zip.ZipException)) |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
116 |
throw new RuntimeException("Expected IOException not propagated"); |
3065
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
117 |
} finally { |
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
118 |
stream.close(); |
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2057
diff
changeset
|
119 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
120 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
121 |
// check that exception or error thrown by filter is not thrown |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
122 |
// by newDirectoryStream or iterator method. |
8158 | 123 |
stream = newDirectoryStream(dir, new DirectoryStream.Filter<Path>() { |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
124 |
public boolean accept(Path file) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
125 |
throw new RuntimeException("Should not be visible"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
126 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
127 |
}); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
128 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
129 |
stream.iterator(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
130 |
} finally { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
131 |
stream.close(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
132 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
133 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
134 |
// test NotDirectoryException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
135 |
try { |
8158 | 136 |
newDirectoryStream(dir.resolve(foo)); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
137 |
throw new RuntimeException("NotDirectoryException not thrown"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
138 |
} catch (NotDirectoryException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
139 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
140 |
|
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
141 |
// test UnsupportedOperationException |
8158 | 142 |
stream = newDirectoryStream(dir); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
143 |
Iterator<Path> i = stream.iterator(); |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
144 |
i.next(); |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
145 |
try { |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
146 |
i.remove(); |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
147 |
throw new RuntimeException("UnsupportedOperationException expected"); |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
148 |
} catch (UnsupportedOperationException uoe) { |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
149 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
150 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
151 |
// test IllegalStateException |
8158 | 152 |
stream = newDirectoryStream(dir); |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
153 |
stream.iterator(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
154 |
try { |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
155 |
// attempt to obtain second iterator |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
156 |
stream.iterator(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
157 |
throw new RuntimeException("IllegalStateException not thrown as expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
158 |
} catch (IllegalStateException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
159 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
160 |
stream.close(); |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
161 |
|
8158 | 162 |
stream = newDirectoryStream(dir); |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
163 |
stream.close(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
164 |
try { |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
165 |
// attempt to obtain iterator after stream is closed |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
166 |
stream.iterator(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
167 |
throw new RuntimeException("IllegalStateException not thrown as expected"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
168 |
} catch (IllegalStateException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
169 |
} |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
170 |
|
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
171 |
// test that iterator reads to end of stream when closed |
8158 | 172 |
stream = newDirectoryStream(dir); |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
173 |
i = stream.iterator(); |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
174 |
stream.close(); |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
175 |
while (i.hasNext()) |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
176 |
i.next(); |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
177 |
|
8158 | 178 |
stream = newDirectoryStream(dir); |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
179 |
i = stream.iterator(); |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
180 |
stream.close(); |
4058
21c6bd5381ca
6879463: (file) DirectoryStream#iterator's remove method throws wrong exception when stream is closed
alanb
parents:
3065
diff
changeset
|
181 |
try { |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
182 |
for (;;) i.next(); |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
183 |
} catch (NoSuchElementException expected) { } |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
184 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
185 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
186 |
public static void main(String[] args) throws IOException { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
187 |
Path dir = TestUtil.createTemporaryDirectory(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
188 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
189 |
doTest(dir); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
190 |
} finally { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
191 |
TestUtil.removeAll(dir); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
192 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
193 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
194 |
} |