From d1543429ff29ca0d761b8473b3fb8621abcd226d Mon Sep 17 00:00:00 2001 From: Brent Christian Date: Tue, 13 May 2025 17:05:15 +0000 Subject: [PATCH] 8356107: [java.lang] Use @requires tag instead of exiting based on os.name or separatorChar property Reviewed-by: naoto, bpb --- .../lang/ProcessBuilder/SiblingIOEHandle.java | 7 +-- .../java/lang/RuntimeTests/exec/Space.java | 11 ++-- .../java/lang/RuntimeTests/exec/Status.java | 7 +-- .../lang/System/NonAnsiFileEncodingTest.java | 63 ------------------- 4 files changed, 9 insertions(+), 79 deletions(-) delete mode 100644 test/jdk/java/lang/System/NonAnsiFileEncodingTest.java diff --git a/test/jdk/java/lang/ProcessBuilder/SiblingIOEHandle.java b/test/jdk/java/lang/ProcessBuilder/SiblingIOEHandle.java index 2e3cc0b78c8..0aecae7dc40 100644 --- a/test/jdk/java/lang/ProcessBuilder/SiblingIOEHandle.java +++ b/test/jdk/java/lang/ProcessBuilder/SiblingIOEHandle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,7 @@ * @bug 6921885 * @run main/othervm SiblingIOEHandle * @summary inherit IOE handles and MS CreateProcess limitations (kb315939) + * @requires (os.family == "windows") */ import java.io.BufferedReader; @@ -58,10 +59,6 @@ public class SiblingIOEHandle { } public static void main(String[] args) { - if (!System.getProperty("os.name").startsWith("Windows")) { - return; - } - APP app = (args.length > 0) ? APP.valueOf(args[0]) : APP.A; switch (app) { case A: diff --git a/test/jdk/java/lang/RuntimeTests/exec/Space.java b/test/jdk/java/lang/RuntimeTests/exec/Space.java index 02debae3491..ef24376ce19 100644 --- a/test/jdk/java/lang/RuntimeTests/exec/Space.java +++ b/test/jdk/java/lang/RuntimeTests/exec/Space.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,13 +24,13 @@ /* @test 1.4 00/10/18 @bug 4231349 @summary test runtime.exec on windows for extra space in cmd + @requires (os.family == "windows") */ import java.io.*; public class Space { public static void main(String[] args) throws Exception { - if (File.separatorChar == '\\') { - try { + try { Process p = Runtime.getRuntime().exec( "cmd /c echo hello" ); BufferedReader reader = new BufferedReader( new InputStreamReader(p.getInputStream())); @@ -38,10 +38,9 @@ public class Space { String echo = reader.readLine(); if (echo.length() == 6) throw new RuntimeException("Extra space in command."); - } catch (IOException e) { - // not Win NT - cmd doesnt exist + } catch (IOException e) { + // not Win NT - cmd doesn't exist return; - } } } } diff --git a/test/jdk/java/lang/RuntimeTests/exec/Status.java b/test/jdk/java/lang/RuntimeTests/exec/Status.java index 5a976c98f3d..ab0165c52e2 100644 --- a/test/jdk/java/lang/RuntimeTests/exec/Status.java +++ b/test/jdk/java/lang/RuntimeTests/exec/Status.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,7 @@ * @bug 4763362 * @summary Ensure that Process.waitFor returns the correct status code * even for very short-running subprocesses + * @requires (os.family == "linux") */ @@ -35,10 +36,6 @@ public class Status { public static void main(String args[]) throws Exception { - if (!System.getProperty("os.name").equals("Linux")) { - System.out.println("Only for Linux"); - return; - } UnixCommands.ensureCommandsAvailable("false"); final String falseCmd = UnixCommands.findCommand("false"); diff --git a/test/jdk/java/lang/System/NonAnsiFileEncodingTest.java b/test/jdk/java/lang/System/NonAnsiFileEncodingTest.java deleted file mode 100644 index 1683e711765..00000000000 --- a/test/jdk/java/lang/System/NonAnsiFileEncodingTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * @test - * @bug 4459099 - * @key i18n - * @summary Tests non ANSI code page locales set default file encoding - * to "utf-8". This test must be run on Windows 2K/XP in one of Armenian, - * Georgian, Hindi, Punjabi, Gujarati, Tamil, Telugu, Kannada, Marathi, - * or Sanskrit languages. - */ - -public class NonAnsiFileEncodingTest { - public static void main(String[] s) { - String OS = System.getProperty("os.name"); - String lang = System.getProperty("user.language"); - String fileenc = System.getProperty("file.encoding"); - - if (!(OS.equals("Windows 2000") || OS.equals("Windows XP"))) { - System.out.println("This test is not meaningful on the platform \"" + OS + "\"."); - return; - } - - if (!(lang.equals("hy") || // Armenian - lang.equals("ka") || // Georgian - lang.equals("hi") || // Hindi - lang.equals("pa") || // Punjabi - lang.equals("gu") || // Gujarati - lang.equals("ta") || // Tamil - lang.equals("te") || // Telugu - lang.equals("kn") || // Kannada - lang.equals("mr") || // Marathi - lang.equals("sa"))) { // Sanskrit - System.out.println("Windows' locale settings for this test is incorrect. Select one of \"Armenian\", \"Georgian\", \"Hindi\", \"Punjabi\", \"Gujarati\", \"Tamil\", \"Telugu\", \"Kannada\", \"Marathi\", or \"Sanskrit\" for the user locale, and \"English(United States)\" for the system default locale using the Control Panel."); - return; - } - - if (!fileenc.equals("utf-8")) { - throw new RuntimeException("file.encoding is incorrectly set to \"" + fileenc + "\". Should be \"utf-8\"."); - } - } -}