From c430720e0aaee11beed1d8ef83e48ee84cc06802 Mon Sep 17 00:00:00 2001 From: Daniel Fuchs Date: Tue, 19 Nov 2013 22:28:12 +0100 Subject: [PATCH] 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10 This test has been seen failing on Solaris 10, presumably because it was run as root. The fix will skip the non-writable case if it can't make a non-writable dir. Reviewed-by: mchung --- .../util/logging/CheckLockLocationTest.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/jdk/test/java/util/logging/CheckLockLocationTest.java b/jdk/test/java/util/logging/CheckLockLocationTest.java index 956621ae6e4..5f3a3a8cb26 100644 --- a/jdk/test/java/util/logging/CheckLockLocationTest.java +++ b/jdk/test/java/util/logging/CheckLockLocationTest.java @@ -33,7 +33,10 @@ import java.io.File; import java.io.IOException; import java.nio.file.AccessDeniedException; import java.nio.file.FileSystemException; +import java.nio.file.Files; import java.nio.file.NoSuchFileException; +import java.nio.file.Path; +import java.nio.file.attribute.UserPrincipal; import java.util.logging.FileHandler; public class CheckLockLocationTest { @@ -169,14 +172,19 @@ public class CheckLockLocationTest { nonWritableDir.deleteOnExit(); // make it non-writable - if (nonWritableDir.setWritable(false)) { + Path path = nonWritableDir.toPath(); + final boolean nonWritable = nonWritableDir.setWritable(false); + final boolean isWritable = Files.isWritable(path); + if (nonWritable && !isWritable) { runNonWritableDirTest = true; + System.out.println("Created non writable dir for " + + getOwner(path) + " at: " + path.toString()); } else { runNonWritableDirTest = false; System.out.println( "Test Setup WARNING: unable to make" + " working directory " + nonWritableDir.getAbsolutePath() - + " non-writable on platform " + System.getProperty("os.name")); - + + "\n\t non-writable for " + getOwner(path) + + " on platform " + System.getProperty("os.name")); } // make sure non-existent directory really doesn't exist @@ -184,9 +192,21 @@ public class CheckLockLocationTest { if (nonExistentDir.exists()) { nonExistentDir.delete(); } + System.out.println("Setup completed - writableDir is: " + writableDir.getPath()); return writableDir; } + private static String getOwner(Path path) { + UserPrincipal user = null; + try { + user = Files.getOwner(path); + } catch (Exception x) { + System.err.println("Failed to get owner of: " + path); + System.err.println("\terror is: " + x); + } + return user == null ? "???" : user.getName(); + } + /** * @param newFile * @return true if file already exists or creation succeeded