# HG changeset patch # User mchung # Date 1484766526 28800 # Node ID 0c05ac48a30bf1106f80b77c1ab4c024d22ea743 # Parent 3a4ebb59aa0ebfcb72dd9a34527ecf4590845242 8172870: test/tools/jmod/JmodTest.java fails on windows with AccessDeniedException Reviewed-by: alanb, chegar diff -r 3a4ebb59aa0e -r 0c05ac48a30b jdk/test/tools/jmod/JmodTest.java --- a/jdk/test/tools/jmod/JmodTest.java Wed Jan 18 17:43:10 2017 +0000 +++ b/jdk/test/tools/jmod/JmodTest.java Wed Jan 18 11:08:46 2017 -0800 @@ -29,7 +29,7 @@ * @modules jdk.compiler * jdk.jlink * @build jdk.testlibrary.FileUtils CompilerUtils - * @run testng JmodTest + * @run testng/othervm -Djava.io.tmpdir=. JmodTest */ import java.io.*; @@ -40,8 +40,10 @@ import java.util.function.Consumer; import java.util.regex.Pattern; import java.util.spi.ToolProvider; +import java.util.stream.Collectors; import java.util.stream.Stream; import jdk.testlibrary.FileUtils; +import jdk.testlibrary.JDKToolFinder; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -593,9 +595,7 @@ findTmpFiles(filename).forEach(tmp -> { try { FileUtils.deleteFileIfExistsWithRetry(tmp); - } catch (IOException e) { - throw new UncheckedIOException(e); - } + } catch (IOException e) {} }); String cp = EXPLODED_DIR.resolve("foo").resolve("classes") + File.pathSeparator + @@ -608,17 +608,25 @@ .assertFailure() .resultChecker(r -> { assertContains(r.output, "unnamed package"); - Set tmpfiles = findTmpFiles(filename).collect(toSet()); + List tmpfiles = findTmpFiles(filename); assertTrue(tmpfiles.isEmpty(), "Unexpected tmp file:" + tmpfiles); }); } - private Stream findTmpFiles(String prefix) { - try { - Path tmpdir = Paths.get(System.getProperty("java.io.tmpdir")); - return Files.find(tmpdir, 1, (p, attrs) -> - p.getFileName().toString().startsWith(prefix) - && p.getFileName().toString().endsWith(".tmp")); + /* + * Returns the list of writeable tmp files with the given prefix. + * + * Ignore the non-writeable tmp files because this test is possibly + * running by another user. + */ + private List findTmpFiles(String prefix) { + Path tmpdir = Paths.get(System.getProperty("java.io.tmpdir")); + try (Stream stream = Files.list(tmpdir)) { + return stream.filter(p -> { + String fn = p.getFileName().toString(); + return Files.isWritable(p) + && fn.startsWith(prefix) && fn.endsWith(".tmp"); + }).collect(Collectors.toList()); } catch (IOException e) { throw new UncheckedIOException(e); }