Skip to content

Commit 5faa559

Browse files
author
Brian Burkhalter
committed
8355444: [java.io] Use @requires tag instead of exiting based on "os.name" property value
Reviewed-by: jpai, lancea
1 parent 01fd49f commit 5faa559

File tree

6 files changed

+21
-33
lines changed

6 files changed

+21
-33
lines changed

test/jdk/java/io/File/MacPathTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 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
@@ -21,6 +21,11 @@
2121
* questions.
2222
*/
2323

24+
/*
25+
* This test is launched via a ProcessBuilder in the main test MacPath which
26+
* includes a @requires (os.family == "mac") tag so no operating system
27+
* conditional is applied here.
28+
*/
2429
import java.io.File;
2530
import java.io.FileInputStream;
2631
import java.io.FileOutputStream;
@@ -29,10 +34,6 @@
2934
public class MacPathTest {
3035

3136
public static void main(String args[]) throws Throwable {
32-
String osname = System.getProperty("os.name");
33-
if (!osname.contains("OS X") && !osname.contains("Darwin"))
34-
return;
35-
3637
// English
3738
test("TestDir_apple", // test dir
3839
"dir_macosx", // dir

test/jdk/java/io/File/MaxPath.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 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,16 +24,21 @@
2424
/* @test
2525
@bug 6481955
2626
@summary Path length less than MAX_PATH (260) works on Windows
27+
@library /test/lib
2728
*/
2829

29-
import java.io.*;
30+
import java.io.File;
31+
import java.io.IOException;
32+
33+
import jtreg.SkippedException;
3034

3135
public class MaxPath {
3236
public static void main(String[] args) throws Exception {
3337
String osName = System.getProperty("os.name");
3438
if (!osName.startsWith("Windows")) {
35-
return;
39+
throw new SkippedException("This test is run only on Windows");
3640
}
41+
3742
int MAX_PATH = 260;
3843
String dir = new File(".").getAbsolutePath() + "\\";
3944
String padding = "1234567890123456789012345678901234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890";

test/jdk/java/io/File/WinDeviceName.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2006, 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 6176051 4858457
2626
@summary Check whether reserved names are handled correctly on Windows
27+
@requires (os.family == "windows")
2728
*/
2829

2930
import java.io.File;
@@ -38,10 +39,6 @@ public class WinDeviceName {
3839
};
3940
public static void main(String[] args) {
4041
String osName = System.getProperty("os.name");
41-
if (!osName.startsWith("Windows")) {
42-
return;
43-
}
44-
4542
for (int i = 0; i < devnames.length; i++) {
4643
String names[] = { devnames[i], devnames[i] + ".TXT",
4744
devnames[i].toLowerCase(),

test/jdk/java/io/File/WinMaxPath.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2006, 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,15 +25,12 @@
2525
@bug 6384833
2626
@summary Check if appropriate exception FileNotFoundException gets
2727
thrown when the pathlengh exceeds the limit.
28+
@requires (os.family == "windows")
2829
*/
2930

3031
import java.io.*;
3132
public class WinMaxPath {
3233
public static void main(String[] args) throws Exception {
33-
String osName = System.getProperty("os.name");
34-
if (!osName.startsWith("Windows")) {
35-
return;
36-
}
3734
try {
3835
char[] as = new char[65000];
3936
java.util.Arrays.fill(as, 'a');

test/jdk/java/io/File/WinSpecialFiles.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2006, 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,15 +25,12 @@
2525
@bug 6192331 6348207 8202076
2626
@summary Check if File.exists()/length() works correctly on Windows
2727
special files hiberfil.sys and pagefile.sys
28+
@requires (os.family == "windows")
2829
*/
2930

3031
import java.io.File;
3132
public class WinSpecialFiles {
3233
public static void main(String[] args) throws Exception {
33-
String osName = System.getProperty("os.name");
34-
if (!osName.startsWith("Windows")) {
35-
return;
36-
}
3734
File root = new File("C:\\");
3835
File[] dir = root.listFiles();
3936
for (int i = 0; i < dir.length; i++) {

test/jdk/java/io/FileOutputStream/ManyFiles.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 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
@@ -37,15 +37,6 @@ public class ManyFiles {
3737
static int NUM_FILES = 2050;
3838

3939
public static void main(String args[]) throws Exception {
40-
// Linux does not yet allow opening this many files; Solaris
41-
// 8 requires an explicit allocation of more file descriptors
42-
// to succeed. Since this test is written to check for a
43-
// Windows capability it is much simpler to only run it
44-
// on that platform.
45-
String osName = System.getProperty("os.name");
46-
if (osName.startsWith("Linux"))
47-
return;
48-
4940
for (int n = 0; n < NUM_FILES; n++) {
5041
File f = new File("file" + count++);
5142
files.add(f);

0 commit comments

Comments
 (0)