diff --git a/test/hotspot/jtreg/runtime/8176717/TestInheritFD.java b/test/hotspot/jtreg/runtime/8176717/TestInheritFD.java index 722bb41964e..50857eea6d5 100644 --- a/test/hotspot/jtreg/runtime/8176717/TestInheritFD.java +++ b/test/hotspot/jtreg/runtime/8176717/TestInheritFD.java @@ -1,21 +1,3 @@ -import static java.io.File.createTempFile; -import static java.lang.Long.parseLong; -import static java.lang.System.getProperty; -import static java.nio.file.Files.readAllBytes; -import static java.util.Arrays.stream; -import static java.util.stream.Collectors.joining; -import static java.util.stream.Collectors.toList; -import static jdk.test.lib.process.ProcessTools.createJavaProcessBuilder; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.Collection; -import java.util.stream.Stream; - /* * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -39,6 +21,26 @@ import java.util.stream.Stream; * questions. */ +import static java.io.File.createTempFile; +import static java.lang.Long.parseLong; +import static java.lang.System.getProperty; +import static java.nio.file.Files.readAllBytes; +import static java.util.Arrays.stream; +import static java.util.Collections.emptyList; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; +import static jdk.test.lib.process.ProcessTools.createJavaProcessBuilder; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Collection; +import java.util.Optional; +import java.util.stream.Stream; + /* * @test TestInheritFD * @bug 8176717 8176809 @@ -163,7 +165,7 @@ public class TestInheritFD { static Collection outputContainingFilenames() { long pid = ProcessHandle.current().pid(); - String[] command = stream(new String[][]{ + Optional command = stream(new String[][]{ {"/usr/bin/lsof", "-p"}, {"/usr/sbin/lsof", "-p"}, {"/bin/lsof", "-p"}, @@ -171,11 +173,11 @@ public class TestInheritFD { {"/usr/local/bin/lsof", "-p"}, {"/usr/bin/pfiles", "-F"}}) // Solaris .filter(args -> new File(args[0]).exists()) - .findFirst() - .orElseThrow(() -> new RuntimeException("could not find lsof-like command")); + .findFirst(); - System.out.println("using command: " + command[0] + " " + command[1]); - return run(command[0], command[1], "" + pid).collect(toList()); + System.out.println("using command: " + command.map((c) -> c[0] + " " + c[1]).orElse("")); + // if command can not be found return list without log file (some machines does not have "lsof" in the expected place) + return command.map(c -> run(c[0], c[1], "" + pid).collect(toList())).orElse(emptyList()); } static boolean findOpenLogFile(Collection fileNames) {