test/jdk/java/util/logging/CheckLockLocationTest.java
author mikael
Mon, 29 Jul 2019 09:59:04 -0700
changeset 57584 9d82a35b6ff7
parent 47216 71c04702a3d5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21825
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
     4
 *
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
     8
 *
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    13
 * accompanied this code).
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    14
 *
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    18
 *
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    21
 * questions.
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    22
 */
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    23
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    24
/*
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    25
 * @test
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    26
 * @bug     6244047
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    27
 * @author Jim Gish
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    28
 * @summary throw more precise IOException when pattern specifies invalid directory
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    29
 *
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    30
 * @run  main/othervm CheckLockLocationTest
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    31
 */
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    32
import java.io.File;
39566
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
    33
import java.io.FileOutputStream;
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    34
import java.io.IOException;
39566
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
    35
import java.io.OutputStream;
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    36
import java.nio.file.AccessDeniedException;
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    37
import java.nio.file.FileSystemException;
21825
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
    38
import java.nio.file.Files;
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    39
import java.nio.file.NoSuchFileException;
21825
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
    40
import java.nio.file.Path;
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
    41
import java.nio.file.attribute.UserPrincipal;
39566
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
    42
import java.util.UUID;
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    43
import java.util.logging.FileHandler;
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    44
public class CheckLockLocationTest {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    45
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    46
    private static final String NON_WRITABLE_DIR = "non-writable-dir";
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    47
    private static final String NOT_A_DIR = "not-a-dir";
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    48
    private static final String WRITABLE_DIR = "writable-dir";
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    49
    private static final String NON_EXISTENT_DIR = "non-existent-dir";
14757
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
    50
    private static boolean runNonWritableDirTest;
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    51
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    52
    public static void main(String... args) throws IOException {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    53
        // we'll base all file creation attempts on the system temp directory,
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    54
        // %t and also try specifying non-existent directories and plain files
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    55
        // that should be directories, and non-writable directories,
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    56
        // to exercise all code paths of checking the lock location
14757
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
    57
        // Note that on platforms like Windows that don't support
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
    58
        // setWritable() on a directory, we'll skip the non-writable
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
    59
        // directory test if setWritable(false) returns false.
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
    60
        //
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    61
        File writableDir = setup();
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    62
        // we now have three files/directories to work with:
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    63
        //    writableDir
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    64
        //    notAdir
14757
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
    65
        //    nonWritableDir (may not be possible on some platforms)
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    66
        //    nonExistentDir (which doesn't exist)
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    67
        runTests(writableDir);
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    68
    }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    69
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    70
    /**
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    71
     * @param writableDir in which log and lock file are created
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    72
     * @throws SecurityException
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    73
     * @throws RuntimeException
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    74
     * @throws IOException
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    75
     */
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    76
    private static void runTests(File writableDir) throws SecurityException,
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    77
            RuntimeException, IOException {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    78
        // Test 1: make sure we can create FileHandler in writable directory
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    79
        try {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    80
            new FileHandler("%t/" + WRITABLE_DIR + "/log.log");
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    81
        } catch (IOException ex) {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    82
            throw new RuntimeException("Test failed: should have been able"
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    83
                    + " to create FileHandler for " + "%t/" + WRITABLE_DIR
39566
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
    84
                    + "/log.log in writable directory"
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
    85
                    + (!writableDir.canRead() // concurrent tests running or user conf issue?
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
    86
                        ? ": directory not readable.\n\tPlease check your "
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
    87
                         + "environment and machine configuration."
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
    88
                        : "."), ex);
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    89
        } finally {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    90
            // the above test leaves files in the directory.  Get rid of the
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    91
            // files created and the directory
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    92
            delete(writableDir);
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    93
        }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    94
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
    95
        // Test 2: creating FileHandler in non-writable directory should fail
14757
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
    96
        if (runNonWritableDirTest) {
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
    97
            try {
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
    98
                new FileHandler("%t/" + NON_WRITABLE_DIR + "/log.log");
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
    99
                throw new RuntimeException("Test failed: should not have been able"
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
   100
                        + " to create FileHandler for " + "%t/" + NON_WRITABLE_DIR
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
   101
                        + "/log.log in non-writable directory.");
14779
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   102
            } catch (AccessDeniedException ex) {
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   103
                // the right exception was thrown, so continue.
14757
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
   104
            } catch (IOException ex) {
14779
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   105
                throw new RuntimeException(
14757
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
   106
                        "Test failed: Expected exception was not an "
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
   107
                                + "AccessDeniedException", ex);
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   108
            }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   109
        }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   110
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   111
        // Test 3: creating FileHandler in non-directory should fail
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   112
        try {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   113
            new FileHandler("%t/" + NOT_A_DIR + "/log.log");
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   114
            throw new RuntimeException("Test failed: should not have been able"
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   115
                    + " to create FileHandler for " + "%t/" + NOT_A_DIR
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   116
                    + "/log.log in non-directory.");
14779
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   117
        } catch (FileSystemException ex) {
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   118
            // the right exception was thrown, so continue.
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   119
        } catch (IOException ex) {
14779
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   120
            throw new RuntimeException("Test failed: exception thrown was not a "
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   121
                    + "FileSystemException", ex);
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   122
        }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   123
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   124
        // Test 4: make sure we can't create a FileHandler in a non-existent dir
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   125
        try {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   126
            new FileHandler("%t/" + NON_EXISTENT_DIR + "/log.log");
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   127
            throw new RuntimeException("Test failed: should not have been able"
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   128
                    + " to create FileHandler for " + "%t/" + NON_EXISTENT_DIR
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   129
                    + "/log.log in a non-existent directory.");
14779
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   130
        } catch (NoSuchFileException ex) {
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   131
            // the right exception was thrown, so continue.
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   132
        } catch (IOException ex) {
14779
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   133
            throw new RuntimeException("Test failed: Expected exception "
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   134
                    + "was not a NoSuchFileException", ex);
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   135
        }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   136
    }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   137
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   138
    /**
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   139
     * Setup all the files and directories needed for the tests
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   140
     *
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   141
     * @return writable directory created that needs to be deleted when done
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   142
     * @throws RuntimeException
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   143
     */
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   144
    private static File setup() throws RuntimeException {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   145
        // First do some setup in the temporary directory (using same logic as
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   146
        // FileHandler for %t pattern)
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   147
        String tmpDir = System.getProperty("java.io.tmpdir"); // i.e. %t
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   148
        if (tmpDir == null) {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   149
            tmpDir = System.getProperty("user.home");
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   150
        }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   151
        File tmpOrHomeDir = new File(tmpDir);
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   152
        // Create a writable directory here (%t/writable-dir)
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   153
        File writableDir = new File(tmpOrHomeDir, WRITABLE_DIR);
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   154
        if (!createFile(writableDir, true)) {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   155
            throw new RuntimeException("Test setup failed: unable to create"
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   156
                    + " writable working directory "
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   157
                    + writableDir.getAbsolutePath() );
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   158
        }
39566
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   159
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   160
        if (!writableDir.canRead()) {
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   161
            throw new RuntimeException("Test setup failed: can't read "
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   162
                    + " writable working directory "
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   163
                    + writableDir.getAbsolutePath() );
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   164
        }
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   165
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   166
        // writableDirectory and its contents will be deleted after the test
39566
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   167
        // that uses it.
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   168
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   169
        // check that we can write in the new writable dir.
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   170
        File dummyFile = new File(writableDir, UUID.randomUUID().toString() + ".txt" );
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   171
        try {
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   172
            if (!dummyFile.createNewFile()) {
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   173
                throw new RuntimeException("Test setup failed: can't create "
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   174
                        + " dummy file in writable working directory "
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   175
                        + dummyFile.getAbsolutePath() );
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   176
            }
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   177
            try (OutputStream os = new FileOutputStream(dummyFile)) {
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   178
                os.write('A');
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   179
            } finally {
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   180
                dummyFile.delete();
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   181
            }
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   182
            if (dummyFile.canRead()) {
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   183
                throw new RuntimeException("Test setup failed: can't delete "
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   184
                        + " dummy file in writable working directory "
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   185
                        + dummyFile.getAbsolutePath() );
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   186
            }
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   187
            System.out.println("Successfully created and deleted dummy file: " +
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   188
                dummyFile.getAbsolutePath());
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   189
        } catch(IOException x) {
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   190
            throw new RuntimeException("Test setup failed: can't write "
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   191
                        + " or delete dummy file in writable working directory "
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   192
                        + dummyFile.getAbsolutePath(), x);
fb9192e776ba 8056285: java/util/logging/CheckLockLocationTest.java java.lang.RuntimeException: Test failed: should have been able to create FileHandler for %t/writable-dir/log.log in writable directory.
dfuchs
parents: 23010
diff changeset
   193
        }
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   194
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   195
        // Create a plain file which we will attempt to use as a directory
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   196
        // (%t/not-a-dir)
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   197
        File notAdir = new File(tmpOrHomeDir, NOT_A_DIR);
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   198
        if (!createFile(notAdir, false)) {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   199
            throw new RuntimeException("Test setup failed: unable to a plain"
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   200
                    + " working file " + notAdir.getAbsolutePath() );
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   201
        }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   202
        notAdir.deleteOnExit();
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   203
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   204
        // Create a non-writable directory (%t/non-writable-dir)
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   205
        File nonWritableDir = new File(tmpOrHomeDir, NON_WRITABLE_DIR);
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   206
        if (!createFile(nonWritableDir, true)) {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   207
            throw new RuntimeException("Test setup failed: unable to create"
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   208
                    + " a non-"
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   209
                    + "writable working directory "
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   210
                    + nonWritableDir.getAbsolutePath() );
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   211
        }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   212
        nonWritableDir.deleteOnExit();
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   213
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   214
        // make it non-writable
21825
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   215
        Path path = nonWritableDir.toPath();
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   216
        final boolean nonWritable = nonWritableDir.setWritable(false);
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   217
        final boolean isWritable = Files.isWritable(path);
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   218
        if (nonWritable && !isWritable) {
14757
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
   219
            runNonWritableDirTest = true;
21825
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   220
            System.out.println("Created non writable dir for "
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   221
                    + getOwner(path) + " at: " + path.toString());
14757
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
   222
        } else {
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
   223
            runNonWritableDirTest = false;
1da20d79c7c5 8003596: TEST_BUG: java/util/logging/CheckLockLocationTest.java failing [win]
jgish
parents: 14509
diff changeset
   224
            System.out.println( "Test Setup WARNING: unable to make"
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   225
                    + " working directory " + nonWritableDir.getAbsolutePath()
21825
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   226
                    + "\n\t non-writable for " + getOwner(path)
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   227
                    +  " on platform " + System.getProperty("os.name"));
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   228
        }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   229
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   230
        // make sure non-existent directory really doesn't exist
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   231
        File nonExistentDir = new File(tmpOrHomeDir, NON_EXISTENT_DIR);
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   232
        if (nonExistentDir.exists()) {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   233
            nonExistentDir.delete();
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   234
        }
21825
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   235
        System.out.println("Setup completed - writableDir is: " + writableDir.getPath());
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   236
        return writableDir;
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   237
    }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   238
21825
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   239
    private static String getOwner(Path path) {
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   240
        UserPrincipal user = null;
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   241
        try {
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   242
            user = Files.getOwner(path);
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   243
        } catch (Exception x) {
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   244
            System.err.println("Failed to get owner of: " + path);
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   245
            System.err.println("\terror is: " + x);
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   246
        }
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   247
        return user == null ? "???" : user.getName();
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   248
    }
b221b57b93bc 8005202: java/util/logging/CheckLockLocationTest.java fail on solars_10
dfuchs
parents: 14779
diff changeset
   249
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   250
    /**
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   251
     * @param newFile
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   252
     * @return true if file already exists or creation succeeded
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   253
     */
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   254
    private static boolean createFile(File newFile, boolean makeDirectory) {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   255
        if (newFile.exists()) {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   256
            return true;
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   257
        }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   258
        if (makeDirectory) {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   259
            return newFile.mkdir();
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   260
        } else {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   261
            try {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   262
                return newFile.createNewFile();
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   263
            } catch (IOException ioex) {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   264
                ioex.printStackTrace();
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   265
                return false;
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   266
            }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   267
        }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   268
    }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   269
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   270
    /*
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   271
     * Recursively delete all files starting at specified file
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   272
     */
14779
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   273
    private static void delete(File f) {
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   274
        if (f != null && f.isDirectory()) {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   275
            for (File c : f.listFiles())
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   276
                delete(c);
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   277
        }
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   278
        if (!f.delete())
14779
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   279
            System.err.println(
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   280
                    "WARNING: unable to delete/cleanup writable test directory: "
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   281
                    + f );
f666fdc36388 8004651: TEST: java/util/logging/CheckLockLocationTest.java failed to delete file (win)
jgish
parents: 14757
diff changeset
   282
        }
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
diff changeset
   283
}