author | jbachorik |
Tue, 21 Jan 2014 13:04:55 +0100 | |
changeset 22353 | d09e3ff5fd63 |
parent 21426 | 65335399143c |
child 25223 | 4d33af5975a5 |
permissions | -rw-r--r-- |
17430
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
1 |
/* |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
4 |
* |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
8 |
* |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
13 |
* accompanied this code). |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
14 |
* |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
18 |
* |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
21 |
* questions. |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
22 |
*/ |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
23 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
24 |
/* @test |
21426
65335399143c
8027155: test/java/io/File/NulFile.java failing when test run in othervm mode
dxu
parents:
18807
diff
changeset
|
25 |
* @bug 8003992 8027155 |
17430
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
26 |
* @summary Test a file whose path name is embedded with NUL character, and |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
27 |
* ensure it is handled correctly. |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
28 |
* @author Dan Xu |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
29 |
*/ |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
30 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
31 |
import java.io.File; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
32 |
import java.io.FileFilter; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
33 |
import java.io.FileInputStream; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
34 |
import java.io.FileOutputStream; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
35 |
import java.io.RandomAccessFile; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
36 |
import java.io.FileNotFoundException; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
37 |
import java.io.FilenameFilter; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
38 |
import java.io.IOException; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
39 |
import java.net.MalformedURLException; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
40 |
import java.nio.file.InvalidPathException; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
41 |
import java.io.ByteArrayInputStream; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
42 |
import java.io.ByteArrayOutputStream; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
43 |
import java.io.ObjectOutputStream; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
44 |
import java.io.ObjectInputStream; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
45 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
46 |
public class NulFile { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
47 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
48 |
private static final char CHAR_NUL = '\u0000'; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
49 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
50 |
private static final String ExceptionMsg = "Invalid file path"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
51 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
52 |
public static void main(String[] args) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
53 |
testFile(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
54 |
testFileInUnix(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
55 |
testFileInWindows(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
56 |
testTempFile(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
57 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
58 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
59 |
private static void testFile() { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
60 |
test(new File(new StringBuilder().append(CHAR_NUL).toString())); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
61 |
test(new File( |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
62 |
new StringBuilder().append("").append(CHAR_NUL).toString())); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
63 |
test(new File( |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
64 |
new StringBuilder().append(CHAR_NUL).append("").toString())); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
65 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
66 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
67 |
private static void testFileInUnix() { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
68 |
String osName = System.getProperty("os.name"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
69 |
if (osName.startsWith("Windows")) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
70 |
return; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
71 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
72 |
String unixFile = "/"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
73 |
test(unixFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
74 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
75 |
unixFile = "//"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
76 |
test(unixFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
77 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
78 |
unixFile = "data/info"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
79 |
test(unixFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
80 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
81 |
unixFile = "/data/info"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
82 |
test(unixFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
83 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
84 |
unixFile = "//data//info"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
85 |
test(unixFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
86 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
87 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
88 |
private static void testFileInWindows() { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
89 |
String osName = System.getProperty("os.name"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
90 |
if (!osName.startsWith("Windows")) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
91 |
return; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
92 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
93 |
String windowsFile = "\\"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
94 |
test(windowsFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
95 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
96 |
windowsFile = "\\\\"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
97 |
test(windowsFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
98 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
99 |
windowsFile = "/"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
100 |
test(windowsFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
101 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
102 |
windowsFile = "//"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
103 |
test(windowsFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
104 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
105 |
windowsFile = "/\\"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
106 |
test(windowsFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
107 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
108 |
windowsFile = "\\/"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
109 |
test(windowsFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
110 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
111 |
windowsFile = "data\\info"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
112 |
test(windowsFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
113 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
114 |
windowsFile = "\\data\\info"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
115 |
test(windowsFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
116 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
117 |
windowsFile = "\\\\server\\data\\info"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
118 |
test(windowsFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
119 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
120 |
windowsFile = "z:data\\info"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
121 |
test(windowsFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
122 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
123 |
windowsFile = "z:\\data\\info"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
124 |
test(windowsFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
125 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
126 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
127 |
private static void test(final String name) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
128 |
int length = name.length(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
129 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
130 |
for (int i = 0; i <= length; i++) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
131 |
StringBuilder sbName = new StringBuilder(name); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
132 |
sbName.insert(i, CHAR_NUL); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
133 |
String curName = sbName.toString(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
134 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
135 |
// test File(String parent, String child) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
136 |
File testFile = new File(curName, "child"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
137 |
test(testFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
138 |
testFile = new File("parent", curName); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
139 |
test(testFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
140 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
141 |
// test File(String pathname) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
142 |
testFile = new File(curName); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
143 |
test(testFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
144 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
145 |
// test File(File parent, String child) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
146 |
testFile = new File(new File(curName), "child"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
147 |
test(testFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
148 |
testFile = new File(new File("parent"), curName); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
149 |
test(testFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
150 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
151 |
// test FileInputStream |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
152 |
testFileInputStream(curName); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
153 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
154 |
// test FileOutputStream |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
155 |
testFileOutputStream(curName); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
156 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
157 |
// test RandomAccessFile |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
158 |
testRandomAccessFile(curName); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
159 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
160 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
161 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
162 |
private static void testFileInputStream(final String str) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
163 |
boolean exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
164 |
FileInputStream is = null; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
165 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
166 |
is = new FileInputStream(str); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
167 |
} catch (FileNotFoundException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
168 |
if (ExceptionMsg.equals(ex.getMessage())) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
169 |
exceptionThrown = true; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
170 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
171 |
if (!exceptionThrown) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
172 |
throw new RuntimeException("FileInputStream constructor" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
173 |
+ " should throw FileNotFoundException"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
174 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
175 |
if (is != null) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
176 |
throw new RuntimeException("FileInputStream constructor" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
177 |
+ " should fail"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
178 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
179 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
180 |
exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
181 |
is = null; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
182 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
183 |
is = new FileInputStream(new File(str)); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
184 |
} catch (FileNotFoundException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
185 |
if (ExceptionMsg.equals(ex.getMessage())) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
186 |
exceptionThrown = true; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
187 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
188 |
if (!exceptionThrown) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
189 |
throw new RuntimeException("FileInputStream constructor" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
190 |
+ " should throw FileNotFoundException"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
191 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
192 |
if (is != null) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
193 |
throw new RuntimeException("FileInputStream constructor" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
194 |
+ " should fail"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
195 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
196 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
197 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
198 |
private static void testFileOutputStream(final String str) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
199 |
boolean exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
200 |
FileOutputStream os = null; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
201 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
202 |
os = new FileOutputStream(str); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
203 |
} catch (FileNotFoundException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
204 |
if (ExceptionMsg.equals(ex.getMessage())) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
205 |
exceptionThrown = true; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
206 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
207 |
if (!exceptionThrown) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
208 |
throw new RuntimeException("FileOutputStream constructor" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
209 |
+ " should throw FileNotFoundException"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
210 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
211 |
if (os != null) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
212 |
throw new RuntimeException("FileOutputStream constructor" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
213 |
+ " should fail"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
214 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
215 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
216 |
exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
217 |
os = null; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
218 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
219 |
os = new FileOutputStream(new File(str)); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
220 |
} catch (FileNotFoundException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
221 |
if (ExceptionMsg.equals(ex.getMessage())) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
222 |
exceptionThrown = true; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
223 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
224 |
if (!exceptionThrown) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
225 |
throw new RuntimeException("FileOutputStream constructor" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
226 |
+ " should throw FileNotFoundException"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
227 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
228 |
if (os != null) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
229 |
throw new RuntimeException("FileOutputStream constructor" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
230 |
+ " should fail"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
231 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
232 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
233 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
234 |
private static void testRandomAccessFile(final String str) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
235 |
boolean exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
236 |
RandomAccessFile raf = null; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
237 |
String[] modes = {"r", "rw", "rws", "rwd"}; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
238 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
239 |
for (String mode : modes) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
240 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
241 |
raf = new RandomAccessFile(str, mode); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
242 |
} catch (FileNotFoundException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
243 |
if (ExceptionMsg.equals(ex.getMessage())) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
244 |
exceptionThrown = true; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
245 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
246 |
if (!exceptionThrown) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
247 |
throw new RuntimeException("RandomAccessFile constructor" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
248 |
+ " should throw FileNotFoundException"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
249 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
250 |
if (raf != null) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
251 |
throw new RuntimeException("RandomAccessFile constructor" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
252 |
+ " should fail"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
253 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
254 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
255 |
exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
256 |
raf = null; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
257 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
258 |
raf = new RandomAccessFile(new File(str), mode); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
259 |
} catch (FileNotFoundException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
260 |
if (ExceptionMsg.equals(ex.getMessage())) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
261 |
exceptionThrown = true; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
262 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
263 |
if (!exceptionThrown) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
264 |
throw new RuntimeException("RandomAccessFile constructor" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
265 |
+ " should throw FileNotFoundException"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
266 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
267 |
if (raf != null) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
268 |
throw new RuntimeException("RandomAccessFile constructor" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
269 |
+ " should fail"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
270 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
271 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
272 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
273 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
274 |
private static void test(File testFile) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
275 |
test(testFile, false); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
276 |
// test serialization |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
277 |
testSerialization(testFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
278 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
279 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
280 |
@SuppressWarnings("deprecation") |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
281 |
private static void test(File testFile, boolean derived) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
282 |
boolean exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
283 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
284 |
if (testFile == null) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
285 |
throw new RuntimeException("test file should not be null."); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
286 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
287 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
288 |
// getPath() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
289 |
if (testFile.getPath().indexOf(CHAR_NUL) < 0) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
290 |
throw new RuntimeException( |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
291 |
"File path should contain Nul character"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
292 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
293 |
// getAbsolutePath() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
294 |
if (testFile.getAbsolutePath().indexOf(CHAR_NUL) < 0) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
295 |
throw new RuntimeException( |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
296 |
"File absolute path should contain Nul character"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
297 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
298 |
// getAbsoluteFile() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
299 |
File derivedAbsFile = testFile.getAbsoluteFile(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
300 |
if (derived) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
301 |
if (derivedAbsFile.getPath().indexOf(CHAR_NUL) < 0) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
302 |
throw new RuntimeException( |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
303 |
"Derived file path should also contain Nul character"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
304 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
305 |
} else { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
306 |
test(derivedAbsFile, true); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
307 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
308 |
// getCanonicalPath() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
309 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
310 |
exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
311 |
testFile.getCanonicalPath(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
312 |
} catch (IOException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
313 |
if (ExceptionMsg.equals(ex.getMessage())) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
314 |
exceptionThrown = true; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
315 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
316 |
if (!exceptionThrown) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
317 |
throw new RuntimeException( |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
318 |
"getCanonicalPath() should throw IOException with" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
319 |
+ " message \"" + ExceptionMsg + "\""); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
320 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
321 |
// getCanonicalFile() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
322 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
323 |
exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
324 |
testFile.getCanonicalFile(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
325 |
} catch (IOException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
326 |
if (ExceptionMsg.equals(ex.getMessage())) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
327 |
exceptionThrown = true; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
328 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
329 |
if (!exceptionThrown) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
330 |
throw new RuntimeException( |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
331 |
"getCanonicalFile() should throw IOException with" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
332 |
+ " message \"" + ExceptionMsg + "\""); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
333 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
334 |
// toURL() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
335 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
336 |
exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
337 |
testFile.toURL(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
338 |
} catch (MalformedURLException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
339 |
if (ExceptionMsg.equals(ex.getMessage())) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
340 |
exceptionThrown = true; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
341 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
342 |
if (!exceptionThrown) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
343 |
throw new RuntimeException("toURL() should throw IOException with" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
344 |
+ " message \"" + ExceptionMsg + "\""); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
345 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
346 |
// canRead() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
347 |
if (testFile.canRead()) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
348 |
throw new RuntimeException("File should not be readable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
349 |
// canWrite() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
350 |
if (testFile.canWrite()) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
351 |
throw new RuntimeException("File should not be writable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
352 |
// exists() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
353 |
if (testFile.exists()) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
354 |
throw new RuntimeException("File should not be existed"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
355 |
// isDirectory() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
356 |
if (testFile.isDirectory()) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
357 |
throw new RuntimeException("File should not be a directory"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
358 |
// isFile() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
359 |
if (testFile.isFile()) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
360 |
throw new RuntimeException("File should not be a file"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
361 |
// isHidden() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
362 |
if (testFile.isHidden()) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
363 |
throw new RuntimeException("File should not be hidden"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
364 |
// lastModified() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
365 |
if (testFile.lastModified() != 0L) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
366 |
throw new RuntimeException("File last modified time should be 0L"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
367 |
// length() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
368 |
if (testFile.length() != 0L) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
369 |
throw new RuntimeException("File length should be 0L"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
370 |
// createNewFile() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
371 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
372 |
exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
373 |
testFile.createNewFile(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
374 |
} catch (IOException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
375 |
if (ExceptionMsg.equals(ex.getMessage())) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
376 |
exceptionThrown = true; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
377 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
378 |
if (!exceptionThrown) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
379 |
throw new RuntimeException( |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
380 |
"createNewFile() should throw IOException with" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
381 |
+ " message \"" + ExceptionMsg + "\""); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
382 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
383 |
// delete() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
384 |
if (testFile.delete()) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
385 |
throw new RuntimeException("Delete operation should fail"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
386 |
// list() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
387 |
if (testFile.list() != null) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
388 |
throw new RuntimeException("File list() should return null"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
389 |
// list(FilenameFilter) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
390 |
FilenameFilter fnFilter = new FilenameFilter() { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
391 |
@Override |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
392 |
public boolean accept(File dir, String name) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
393 |
return false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
394 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
395 |
}; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
396 |
if (testFile.list(fnFilter) != null) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
397 |
throw new RuntimeException("File list(FilenameFilter) should" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
398 |
+ " return null"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
399 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
400 |
// listFiles() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
401 |
if (testFile.listFiles() != null) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
402 |
throw new RuntimeException("File listFiles() should return null"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
403 |
// listFiles(FilenameFilter) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
404 |
if (testFile.listFiles(fnFilter) != null) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
405 |
throw new RuntimeException("File listFiles(FilenameFilter)" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
406 |
+ " should return null"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
407 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
408 |
// listFiles(FileFilter) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
409 |
FileFilter fFilter = new FileFilter() { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
410 |
@Override |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
411 |
public boolean accept(File file) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
412 |
return false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
413 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
414 |
}; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
415 |
if (testFile.listFiles(fFilter) != null) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
416 |
throw new RuntimeException("File listFiles(FileFilter)" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
417 |
+ " should return null"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
418 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
419 |
// mkdir() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
420 |
if (testFile.mkdir()) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
421 |
throw new RuntimeException("File should not be able to" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
422 |
+ " create directory"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
423 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
424 |
// mkdirs() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
425 |
if (testFile.mkdirs()) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
426 |
throw new RuntimeException("File should not be able to" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
427 |
+ " create directories"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
428 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
429 |
// renameTo(File) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
430 |
if (testFile.renameTo(new File("dest"))) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
431 |
throw new RuntimeException("File rename should fail"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
432 |
if (new File("dest").renameTo(testFile)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
433 |
throw new RuntimeException("File rename should fail"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
434 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
435 |
exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
436 |
testFile.renameTo(null); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
437 |
} catch (NullPointerException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
438 |
exceptionThrown = true; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
439 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
440 |
if (!exceptionThrown) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
441 |
throw new RuntimeException("File rename should thrown NPE"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
442 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
443 |
// setLastModified(long) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
444 |
if (testFile.setLastModified(0L)) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
445 |
throw new RuntimeException("File should fail to set" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
446 |
+ " last modified time"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
447 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
448 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
449 |
exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
450 |
testFile.setLastModified(-1); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
451 |
} catch (IllegalArgumentException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
452 |
if ("Negative time".equals(ex.getMessage())) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
453 |
exceptionThrown = true; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
454 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
455 |
if (!exceptionThrown) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
456 |
throw new RuntimeException("File should fail to set" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
457 |
+ " last modified time with message \"Negative time\""); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
458 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
459 |
// setReadOnly() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
460 |
if (testFile.setReadOnly()) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
461 |
throw new RuntimeException("File should fail to set read-only"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
462 |
// setWritable(boolean writable, boolean ownerOnly) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
463 |
if (testFile.setWritable(true, true)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
464 |
throw new RuntimeException("File should fail to set writable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
465 |
if (testFile.setWritable(true, false)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
466 |
throw new RuntimeException("File should fail to set writable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
467 |
if (testFile.setWritable(false, true)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
468 |
throw new RuntimeException("File should fail to set writable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
469 |
if (testFile.setWritable(false, false)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
470 |
throw new RuntimeException("File should fail to set writable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
471 |
// setWritable(boolean writable) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
472 |
if (testFile.setWritable(false)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
473 |
throw new RuntimeException("File should fail to set writable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
474 |
if (testFile.setWritable(true)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
475 |
throw new RuntimeException("File should fail to set writable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
476 |
// setReadable(boolean readable, boolean ownerOnly) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
477 |
if (testFile.setReadable(true, true)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
478 |
throw new RuntimeException("File should fail to set readable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
479 |
if (testFile.setReadable(true, false)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
480 |
throw new RuntimeException("File should fail to set readable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
481 |
if (testFile.setReadable(false, true)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
482 |
throw new RuntimeException("File should fail to set readable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
483 |
if (testFile.setReadable(false, false)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
484 |
throw new RuntimeException("File should fail to set readable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
485 |
// setReadable(boolean readable) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
486 |
if (testFile.setReadable(false)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
487 |
throw new RuntimeException("File should fail to set readable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
488 |
if (testFile.setReadable(true)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
489 |
throw new RuntimeException("File should fail to set readable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
490 |
// setExecutable(boolean executable, boolean ownerOnly) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
491 |
if (testFile.setExecutable(true, true)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
492 |
throw new RuntimeException("File should fail to set executable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
493 |
if (testFile.setExecutable(true, false)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
494 |
throw new RuntimeException("File should fail to set executable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
495 |
if (testFile.setExecutable(false, true)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
496 |
throw new RuntimeException("File should fail to set executable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
497 |
if (testFile.setExecutable(false, false)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
498 |
throw new RuntimeException("File should fail to set executable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
499 |
// setExecutable(boolean executable) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
500 |
if (testFile.setExecutable(false)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
501 |
throw new RuntimeException("File should fail to set executable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
502 |
if (testFile.setExecutable(true)) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
503 |
throw new RuntimeException("File should fail to set executable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
504 |
// canExecute() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
505 |
if (testFile.canExecute()) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
506 |
throw new RuntimeException("File should not be executable"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
507 |
// getTotalSpace() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
508 |
if (testFile.getTotalSpace() != 0L) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
509 |
throw new RuntimeException("The total space should be 0L"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
510 |
// getFreeSpace() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
511 |
if (testFile.getFreeSpace() != 0L) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
512 |
throw new RuntimeException("The free space should be 0L"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
513 |
// getUsableSpace() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
514 |
if (testFile.getUsableSpace() != 0L) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
515 |
throw new RuntimeException("The usable space should be 0L"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
516 |
// compareTo(File null) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
517 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
518 |
exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
519 |
testFile.compareTo(null); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
520 |
} catch (NullPointerException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
521 |
exceptionThrown = true; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
522 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
523 |
if (!exceptionThrown) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
524 |
throw new RuntimeException("compareTo(null) should throw NPE"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
525 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
526 |
// toString() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
527 |
if (testFile.toString().indexOf(CHAR_NUL) < 0) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
528 |
throw new RuntimeException( |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
529 |
"File path should contain Nul character"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
530 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
531 |
// toPath() |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
532 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
533 |
exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
534 |
testFile.toPath(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
535 |
} catch (InvalidPathException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
536 |
exceptionThrown = true; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
537 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
538 |
if (!exceptionThrown) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
539 |
throw new RuntimeException("toPath() should throw" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
540 |
+ " InvalidPathException"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
541 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
542 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
543 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
544 |
private static void testSerialization(File testFile) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
545 |
String path = testFile.getPath(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
546 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
547 |
// serialize test file |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
548 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
549 |
ObjectOutputStream oos = new ObjectOutputStream(baos); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
550 |
oos.writeObject(testFile); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
551 |
oos.close(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
552 |
// deserialize test file |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
553 |
byte[] bytes = baos.toByteArray(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
554 |
ByteArrayInputStream is = new ByteArrayInputStream(bytes); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
555 |
ObjectInputStream ois = new ObjectInputStream(is); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
556 |
File newFile = (File) ois.readObject(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
557 |
// test |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
558 |
String newPath = newFile.getPath(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
559 |
if (!path.equals(newPath)) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
560 |
throw new RuntimeException( |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
561 |
"Serialization should not change file path"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
562 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
563 |
test(newFile, false); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
564 |
} catch (IOException | ClassNotFoundException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
565 |
System.err.println("Exception happens in testSerialization"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
566 |
System.err.println(ex.getMessage()); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
567 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
568 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
569 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
570 |
private static void testTempFile() { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
571 |
final String[] names = {"x", "xx", "xxx", "xxxx"}; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
572 |
final String shortPrefix = "sp"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
573 |
final String prefix = "prefix"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
574 |
final String suffix = "suffix"; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
575 |
File tmpDir = new File("tmpDir"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
576 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
577 |
for (String name : names) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
578 |
int length = name.length(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
579 |
for (int i = 0; i <= length; i++) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
580 |
StringBuilder sbName = new StringBuilder(name); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
581 |
sbName.insert(i, CHAR_NUL); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
582 |
String curName = sbName.toString(); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
583 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
584 |
// test prefix |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
585 |
testCreateTempFile(curName, suffix, tmpDir); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
586 |
// test suffix |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
587 |
testCreateTempFile(shortPrefix, curName, tmpDir); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
588 |
testCreateTempFile(prefix, curName, tmpDir); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
589 |
// test directory |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
590 |
testCreateTempFile(shortPrefix, suffix, new File(curName)); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
591 |
testCreateTempFile(prefix, suffix, new File(curName)); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
592 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
593 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
594 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
595 |
|
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
596 |
private static void testCreateTempFile(String prefix, String suffix, |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
597 |
File directory) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
598 |
// createTempFile(String prefix, String suffix, File directory) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
599 |
boolean exceptionThrown = false; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
600 |
boolean shortPrefix = (prefix.length() < 3); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
601 |
if (shortPrefix) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
602 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
603 |
File.createTempFile(prefix, suffix, directory); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
604 |
} catch (IllegalArgumentException ex) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
605 |
if ("Prefix string too short".equals(ex.getMessage())) |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
606 |
exceptionThrown = true; |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
607 |
} catch (IOException ioe) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
608 |
System.err.println("IOException happens in testCreateTempFile"); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
609 |
System.err.println(ioe.getMessage()); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
610 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
611 |
} else { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
612 |
try { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
613 |
File.createTempFile(prefix, suffix, directory); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
614 |
} catch (IOException ex) { |
18807
7d65f90d7348
8017212: File.createTempFile requires unnecessary "read" permission
dxu
parents:
18157
diff
changeset
|
615 |
String err = "Unable to create temporary file"; |
21426
65335399143c
8027155: test/java/io/File/NulFile.java failing when test run in othervm mode
dxu
parents:
18807
diff
changeset
|
616 |
if (ex.getMessage() != null && ex.getMessage().startsWith(err)) |
17430
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
617 |
exceptionThrown = true; |
18807
7d65f90d7348
8017212: File.createTempFile requires unnecessary "read" permission
dxu
parents:
18157
diff
changeset
|
618 |
else { |
7d65f90d7348
8017212: File.createTempFile requires unnecessary "read" permission
dxu
parents:
18157
diff
changeset
|
619 |
throw new RuntimeException("Get IOException with message, " |
7d65f90d7348
8017212: File.createTempFile requires unnecessary "read" permission
dxu
parents:
18157
diff
changeset
|
620 |
+ ex.getMessage() + ", expect message, "+ err); |
7d65f90d7348
8017212: File.createTempFile requires unnecessary "read" permission
dxu
parents:
18157
diff
changeset
|
621 |
} |
17430
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
622 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
623 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
624 |
if (!exceptionThrown) { |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
625 |
throw new RuntimeException("createTempFile() should throw" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
626 |
+ (shortPrefix ? " IllegalArgumentException" |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
627 |
: " IOException")); |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
628 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
629 |
} |
c445531b8f6b
8003992: File and other classes in java.io do not handle embedded nulls properly
dxu
parents:
diff
changeset
|
630 |
} |