Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
/ jdk18u Public archive

Commit 313b033

Browse files
author
Brian Burkhalter
committedApr 23, 2022
8285445: cannot open file "NUL:"
Backport-of: 03cbb48e6a1d806f204a39bbdbb4bc9be9e57a41
1 parent 07f4a0f commit 313b033

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed
 

Diff for: ‎src/java.base/windows/classes/java/io/WinNTFileSystem.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,15 @@ class WinNTFileSystem extends FileSystem {
4848

4949
// Whether to enable alternative data streams (ADS) by suppressing
5050
// checking the path for invalid characters, in particular ":".
51-
// ADS support will be enabled if and only if the property is set and
52-
// is the empty string or is equal, ignoring case, to the string "true".
53-
// By default ADS support is disabled.
51+
// By default, ADS support is enabled and will be disabled if and
52+
// only if the property is set, ignoring case, to the string "false".
5453
private static final boolean ENABLE_ADS;
5554
static {
5655
String enableADS = GetPropertyAction.privilegedGetProperty("jdk.io.File.enableADS");
5756
if (enableADS != null) {
58-
ENABLE_ADS = "".equals(enableADS) || Boolean.parseBoolean(enableADS);
57+
ENABLE_ADS = !enableADS.equalsIgnoreCase(Boolean.FALSE.toString());
5958
} else {
60-
ENABLE_ADS = false;
59+
ENABLE_ADS = true;
6160
}
6261
}
6362

Diff for: ‎test/jdk/java/io/FileOutputStream/OpenNUL.java

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8285445
27+
* @requires (os.family == "windows")
28+
* @summary Verify behavior of opening "NUL:" with ADS enabled and disabled.
29+
* @run main/othervm -Djdk.io.File.enableADS OpenNUL
30+
* @run main/othervm -Djdk.io.File.enableADS=true OpenNUL
31+
*/
32+
33+
import java.io.FileNotFoundException;
34+
import java.io.FileOutputStream;
35+
import java.io.IOException;
36+
37+
public class OpenNUL {
38+
public static void main(String args[]) throws IOException {
39+
String enableADS = System.getProperty("jdk.io.File.enableADS");
40+
boolean fails = enableADS.equalsIgnoreCase(Boolean.FALSE.toString());
41+
42+
FileOutputStream fos;
43+
try {
44+
fos = new FileOutputStream("NUL:");
45+
if (fails)
46+
throw new RuntimeException("Should have failed");
47+
} catch (FileNotFoundException fnfe) {
48+
if (!fails)
49+
throw new RuntimeException("Should not have failed");
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)