Skip to content

Commit 4826a91

Browse files
author
Brian Burkhalter
committed
8355443: [java.io] Use @requires tag instead of exiting based on File.separatorChar value
Reviewed-by: naoto, vyazici
1 parent 5faa559 commit 4826a91

File tree

10 files changed

+26
-51
lines changed

10 files changed

+26
-51
lines changed

test/jdk/java/io/FileInputStream/LeadingSlash.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,22 +26,21 @@
2626
* @bug 4487368
2727
* @summary Test, if FileInputStream can handle
2828
* a leading slash in file name.
29+
* @requires (os.family == "windows")
2930
*/
3031

3132
import java.io.*;
3233

3334
public class LeadingSlash {
3435
public static void main (String args[]) throws Exception {
35-
if (File.separatorChar == '\\') { // Windows
36-
File file = null;
37-
try {
38-
file = File.createTempFile("bug", "4487368");
39-
new FileInputStream("\\" + file.getPath()).close();
40-
new FileOutputStream("\\" + file.getPath()).close();
41-
} finally {
42-
if (file != null)
43-
file.delete();
44-
}
36+
File file = null;
37+
try {
38+
file = File.createTempFile("bug", "4487368");
39+
new FileInputStream("\\" + file.getPath()).close();
40+
new FileOutputStream("\\" + file.getPath()).close();
41+
} finally {
42+
if (file != null)
43+
file.delete();
4544
}
4645
}
4746
}

test/jdk/java/io/pathNames/GeneralSolaris.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
2424
/* @test
2525
@bug 4035924 4095767
2626
@summary General exhaustive test of solaris pathname handling
27+
@requires (os.family != "windows")
2728
@author Mark Reinhold
2829
2930
@build General GeneralSolaris
@@ -65,10 +66,6 @@ private static void checkPaths() throws Exception {
6566
}
6667

6768
public static void main(String[] args) throws Exception {
68-
if (File.separatorChar != '/') {
69-
/* This test is only valid on Unix systems */
70-
return;
71-
}
7269
if (args.length > 0) debug = true;
7370

7471
initTestData(3);

test/jdk/java/io/pathNames/GeneralWin32.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
2424
/* @test
2525
@bug 4032066 4039597 4046914 4054511 4065189 4109131 4875229 6983520 8009258
2626
@summary General exhaustive test of win32 pathname handling
27+
@requires (os.family == "windows")
2728
@author Mark Reinhold
2829
2930
@build General GeneralWin32
@@ -162,10 +163,6 @@ private static void checkUncPaths(int depth) throws Exception {
162163

163164

164165
public static void main(String[] args) throws Exception {
165-
if (File.separatorChar != '\\') {
166-
/* This test is only valid on win32 systems */
167-
return;
168-
}
169166
if (args.length > 0) debug = true;
170167

171168
initTestData(3);

test/jdk/java/io/pathNames/unix/TrailingSlash.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
2424
/* @test
2525
* @bug 4427862
2626
* @summary Ensure that trailing slashes are ignored when opening files
27+
* @requires (os.family != "windows")
2728
*/
2829

2930
import java.io.*;
@@ -107,11 +108,6 @@ static void go(String fn, String fns) throws Exception {
107108
}
108109

109110
public static void main(String[] args) throws Exception {
110-
if (File.separatorChar != '/') {
111-
// This test is only valid on Unix systems
112-
return;
113-
}
114-
115111
go("xyzzy", "xyzzy");
116112
go("xyzzy", "xyzzy/");
117113
go("xyzzy", "xyzzy//");

test/jdk/java/io/pathNames/win32/DriveOnly.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
/* @test
2525
@bug 4096648
2626
@summary Make sure that isDirectory and lastModified work on "x:"
27+
@requires (os.family == "windows")
2728
*/
2829

2930
import java.io.File;
@@ -32,7 +33,6 @@
3233
public class DriveOnly {
3334

3435
public static void main(String[] args) throws Exception {
35-
if (File.separatorChar != '\\') return;
3636
File f = new File("").getCanonicalFile();
3737
while (f.getParent() != null) f = f.getParentFile();
3838
String p = f.getPath().substring(0, 2);

test/jdk/java/io/pathNames/win32/DriveRelativePath.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
2424
/* @test
2525
@bug 4070044 4164823
2626
@summary Check getCanonicalPath's treatment of drive-relative paths (win32)
27+
@requires (os.family == "windows")
2728
*/
2829

2930
import java.io.*;
@@ -37,11 +38,6 @@ static void fail(String s) {
3738

3839
public static void main(String[] args) throws IOException {
3940

40-
if (File.separatorChar != '\\') {
41-
/* This test is only valid on win32 systems */
42-
return;
43-
}
44-
4541
File f = new File("foo");
4642
String c = f.getCanonicalPath();
4743
System.err.println(c);

test/jdk/java/io/pathNames/win32/DriveSlash.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525
@bug 4065189
2626
@summary Check that win32 pathnames of the form "C:\\"
2727
can be listed by the File.list method
28+
@requires (os.family == "windows")
2829
@author Mark Reinhold
2930
*/
3031

@@ -35,9 +36,6 @@ public class DriveSlash {
3536

3637
public static void main(String[] args) throws Exception {
3738

38-
/* This test is only valid on win32 systems */
39-
if (File.separatorChar != '\\') return;
40-
4139
File f = new File("c:\\");
4240
System.err.println(f.getCanonicalPath());
4341
String[] fs = f.list();

test/jdk/java/io/pathNames/win32/RenameDelete.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
2424
/*
2525
* @test
2626
* @bug 4042592 4042593
27+
@requires (os.family == "windows")
2728
* @summary Test operation of rename and delete on win32
2829
*/
2930

@@ -40,11 +41,6 @@ public class RenameDelete {
4041
public static void main(String[] args) throws Exception {
4142
boolean success = false;
4243

43-
if (File.separatorChar != '\\') {
44-
System.err.println("Not a win32 platform -- test inapplicable");
45-
return;
46-
}
47-
4844
//construct a test file in this location
4945
File f1 = new File(".");
5046
StringBuffer location = new StringBuffer("\\");

test/jdk/java/io/pathNames/win32/SJIS.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
@bug 4039597
2626
@summary Check that pathnames containing double-byte characters are not
2727
corrupted by win32 path processing
28+
@requires (os.family == "windows")
2829
@author Mark Reinhold
2930
@library /test/lib
3031
*/
@@ -52,7 +53,6 @@ public static void main(String[] args) throws Exception {
5253

5354
/* This test is only valid on win32 systems
5455
that use the SJIS encoding */
55-
if (File.separatorChar != '\\') return;
5656
String enc = System.getProperty("native.encoding");
5757
if ((enc == null) || !enc.equals("MS932")) {
5858
throw new SkippedException(

test/jdk/java/io/pathNames/win32/bug6344646.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525
* @bug 6344646
2626
* @summary tests that WinNTFileSystem.hashCode() uses
2727
* locale independent case mapping.
28+
* @requires (os.family == "windows")
2829
*/
2930

3031
import java.io.*;
@@ -34,11 +35,6 @@ public class bug6344646 {
3435
public static void main(String[] s) {
3536
Locale reservedLocale = Locale.getDefault();
3637
try {
37-
/* This test is only valid on win32 systems */
38-
if (File.separatorChar != '\\') {
39-
return;
40-
}
41-
4238
Locale.setDefault(Locale.of("lt"));
4339
File f1 = new File("J\u0301");
4440
File f2 = new File("j\u0301");

0 commit comments

Comments
 (0)