author | alanb |
Fri, 14 Sep 2018 16:56:09 +0100 | |
changeset 51745 | 90c1dcdebc64 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
28749
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
1 |
/* |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
4 |
* |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
8 |
* |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
13 |
* accompanied this code). |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
14 |
* |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
18 |
* |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
21 |
* questions. |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
22 |
*/ |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
23 |
|
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
24 |
import java.io.File; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
25 |
import java.io.IOException; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
26 |
import java.nio.channels.AsynchronousFileChannel; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
27 |
import java.nio.channels.FileChannel; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
28 |
import java.nio.channels.FileLock; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
29 |
import java.nio.file.StandardOpenOption; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
30 |
|
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
31 |
/* |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
32 |
* @test |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
33 |
* @bug 6880737 |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
34 |
* @summary Test FileLock constructor parameter validation. |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
35 |
*/ |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
36 |
public class FileLockConstructor { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
37 |
public static void main(String[] args) throws IOException { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
38 |
FileLock fileLock = null; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
39 |
int failures = 0; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
40 |
|
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
41 |
// null FileChannel |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
42 |
boolean exceptionThrown = false; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
43 |
try { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
44 |
fileLock = new FileLockSub((FileChannel)null, 0, 0, false); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
45 |
} catch (NullPointerException npe) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
46 |
exceptionThrown = true; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
47 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
48 |
if (!exceptionThrown) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
49 |
System.err.println("FileLock constructor did not throw NPE for null FileChannel"); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
50 |
failures++; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
51 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
52 |
|
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
53 |
// null AsynchronousFileChannel |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
54 |
exceptionThrown = false; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
55 |
try { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
56 |
fileLock = new FileLockSub((AsynchronousFileChannel)null, 0, 0, true); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
57 |
} catch (NullPointerException npe) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
58 |
exceptionThrown = true; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
59 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
60 |
if (!exceptionThrown) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
61 |
System.err.println("FileLock constructor did not throw NPE for null AsynchronousFileChannel"); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
62 |
failures++; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
63 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
64 |
|
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
65 |
// create temporary file |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
66 |
File tmpFile = File.createTempFile("FileLock", "tmp"); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
67 |
tmpFile.deleteOnExit(); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
68 |
|
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
69 |
// position and size preconditions |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
70 |
long[][] posAndSize = new long[][] { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
71 |
{0, 42}, // valid |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
72 |
{-1, 42}, // invalid: position < 0 |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
73 |
{0, -1}, // invalid: size < 0 |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
74 |
{Long.MAX_VALUE, 1} // invalid: position + size < 0 |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
75 |
}; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
76 |
|
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
77 |
// test position and size preconditions for FileChannel case |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
78 |
try (FileChannel syncChannel = FileChannel.open(tmpFile.toPath(), |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
79 |
StandardOpenOption.READ, StandardOpenOption.WRITE)) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
80 |
|
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
81 |
for (int i = 0; i < posAndSize.length; i++) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
82 |
boolean preconditionsHold = i == 0; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
83 |
exceptionThrown = false; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
84 |
try { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
85 |
fileLock = new FileLockSub(syncChannel, posAndSize[i][0], |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
86 |
posAndSize[i][1], true); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
87 |
} catch (IllegalArgumentException iae) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
88 |
exceptionThrown = true; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
89 |
} catch (Exception e) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
90 |
System.err.println("Unexpected exception \"" + e + "\" caught" |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
91 |
+ " for position " + posAndSize[i][0] + " and size " |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
92 |
+ posAndSize[i][1] + " for FileChannel variant"); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
93 |
failures++; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
94 |
continue; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
95 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
96 |
if (preconditionsHold && exceptionThrown) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
97 |
System.err.println("FileLock constructor incorrectly threw IAE" |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
98 |
+ " for position " + posAndSize[i][0] + " and size " |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
99 |
+ posAndSize[i][1] + " for FileChannel variant"); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
100 |
failures++; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
101 |
} else if (!preconditionsHold && !exceptionThrown) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
102 |
System.err.println("FileLock constructor did not throw IAE" |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
103 |
+ " for position " + posAndSize[i][0] + " and size " |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
104 |
+ posAndSize[i][1] + " for FileChannel variant"); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
105 |
failures++; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
106 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
107 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
108 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
109 |
|
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
110 |
// test position and size preconditions for AsynchronousFileChannel case |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
111 |
try (AsynchronousFileChannel asyncChannel |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
112 |
= AsynchronousFileChannel.open(tmpFile.toPath(), |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
113 |
StandardOpenOption.READ, StandardOpenOption.WRITE)) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
114 |
for (int i = 0; i < posAndSize.length; i++) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
115 |
boolean preconditionsHold = i == 0; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
116 |
exceptionThrown = false; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
117 |
try { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
118 |
fileLock = new FileLockSub(asyncChannel, posAndSize[i][0], |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
119 |
posAndSize[i][1], true); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
120 |
} catch (IllegalArgumentException iae) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
121 |
exceptionThrown = true; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
122 |
} catch (Exception e) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
123 |
System.err.println("Unexpected exception \"" + e + "\" caught" |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
124 |
+ " for position " + posAndSize[i][0] + " and size " |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
125 |
+ posAndSize[i][1] + " for AsynchronousFileChannel variant"); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
126 |
failures++; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
127 |
continue; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
128 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
129 |
if (preconditionsHold && exceptionThrown) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
130 |
System.err.println("FileLock constructor incorrectly threw IAE" |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
131 |
+ " for position " + posAndSize[i][0] + " and size " |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
132 |
+ posAndSize[i][1] + " for AsynchronousFileChannel variant"); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
133 |
failures++; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
134 |
} else if (!preconditionsHold && !exceptionThrown) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
135 |
System.err.println("FileLock constructor did not throw IAE" |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
136 |
+ " for position " + posAndSize[i][0] + " and size " |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
137 |
+ posAndSize[i][1] + " for AsynchronousFileChannel variant"); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
138 |
failures++; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
139 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
140 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
141 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
142 |
|
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
143 |
if (failures > 0) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
144 |
throw new RuntimeException("Incurred " + failures + |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
145 |
" failures while testing FileLock."); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
146 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
147 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
148 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
149 |
|
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
150 |
class FileLockSub extends FileLock { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
151 |
FileLockSub(FileChannel channel, long position, long size, boolean shared) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
152 |
super(channel, position, size, shared); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
153 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
154 |
|
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
155 |
FileLockSub(AsynchronousFileChannel channel, long position, long size, |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
156 |
boolean shared) { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
157 |
super(channel, position, size, shared); |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
158 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
159 |
|
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
160 |
@Override |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
161 |
public boolean isValid() { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
162 |
return false; |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
163 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
164 |
|
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
165 |
@Override |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
166 |
public void release() throws IOException { |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
167 |
// do nothing |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
168 |
} |
a75be4abe9cf
6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
bpb
parents:
diff
changeset
|
169 |
} |