test/jdk/java/util/logging/FileHandlerPath.java
author mikael
Mon, 29 Jul 2019 09:59:04 -0700
changeset 57584 9d82a35b6ff7
parent 55462 6dfdcd31463d
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26864
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
     1
/*
55462
6dfdcd31463d 8185139: [Graal] Tests which set too restrictive security manager fail with Graal
kvn
parents: 47216
diff changeset
     2
 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
26864
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
     4
 *
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
     8
 *
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    14
 *
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    18
 *
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    21
 * questions.
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    22
 */
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    23
import java.io.ByteArrayInputStream;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    24
import java.io.ByteArrayOutputStream;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    25
import java.io.File;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    26
import java.io.FilePermission;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    27
import java.io.IOException;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    28
import java.nio.channels.FileChannel;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    29
import java.nio.file.Files;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    30
import java.nio.file.Paths;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    31
import static java.nio.file.StandardOpenOption.CREATE_NEW;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    32
import static java.nio.file.StandardOpenOption.WRITE;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    33
import java.security.CodeSource;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    34
import java.security.Permission;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    35
import java.security.PermissionCollection;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    36
import java.security.Permissions;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    37
import java.security.Policy;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    38
import java.security.ProtectionDomain;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    39
import java.util.Arrays;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    40
import java.util.Collections;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    41
import java.util.Enumeration;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    42
import java.util.List;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    43
import java.util.Properties;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    44
import java.util.PropertyPermission;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    45
import java.util.UUID;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    46
import java.util.concurrent.atomic.AtomicBoolean;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    47
import java.util.logging.FileHandler;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    48
import java.util.logging.LogManager;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    49
import java.util.logging.LoggingPermission;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    50
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    51
/**
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    52
 * @test
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    53
 * @bug 8059269
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    54
 * @summary tests that using a simple (non composite) pattern does not lead
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    55
 *        to NPE when the lock file already exists.
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    56
 * @run main/othervm FileHandlerPath UNSECURE
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    57
 * @run main/othervm FileHandlerPath SECURE
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    58
 * @author danielfuchs
30046
cf2c86e1819e 8078334: Mark regression tests using randomness
darcy
parents: 26864
diff changeset
    59
 * @key randomness
26864
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    60
 */
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    61
public class FileHandlerPath {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    62
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    63
    /**
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    64
     * We will test the simple pattern in two configurations.
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    65
     * UNSECURE: No security manager.
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    66
     * SECURE: With the security manager present - and the required
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    67
     *         permissions granted.
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    68
     */
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    69
    public static enum TestCase {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    70
        UNSECURE, SECURE;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    71
        public void run(Properties propertyFile) throws Exception {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    72
            System.out.println("Running test case: " + name());
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    73
            Configure.setUp(this, propertyFile);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    74
            test(this.name() + " " + propertyFile.getProperty("test.name"), propertyFile);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    75
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    76
    }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    77
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    78
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    79
    // Use a random name provided by UUID to avoid collision with other tests
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30046
diff changeset
    80
    static final String logFile = FileHandlerPath.class.getSimpleName() + "_"
26864
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    81
                + UUID.randomUUID().toString() + ".log";
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30046
diff changeset
    82
    static final String tmpLogFile;
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30046
diff changeset
    83
    static final String userDir = System.getProperty("user.dir");
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30046
diff changeset
    84
    static final String tmpDir = System.getProperty("java.io.tmpdir");
26864
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    85
    private static final List<Properties> properties;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    86
    static {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    87
        tmpLogFile = new File(tmpDir, logFile).toString();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    88
        Properties props1 = new Properties();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    89
        Properties props2 = new Properties();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    90
        props1.setProperty("test.name", "relative file");
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    91
        props1.setProperty("test.file.name", logFile);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    92
        props1.setProperty(FileHandler.class.getName() + ".pattern", logFile);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    93
        props1.setProperty(FileHandler.class.getName() + ".count", "1");
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    94
        props2.setProperty("test.name", "absoluste file");
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    95
        props2.setProperty("test.file.name", tmpLogFile);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    96
        props2.setProperty(FileHandler.class.getName() + ".pattern", "%t/" + logFile);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    97
        props2.setProperty(FileHandler.class.getName() + ".count", "1");
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    98
        properties = Collections.unmodifiableList(Arrays.asList(
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
    99
                    props1,
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   100
                    props2));
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   101
    }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   102
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   103
    public static void main(String... args) throws Exception {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   104
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   105
        if (args == null || args.length == 0) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   106
            args = new String[] {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   107
                TestCase.UNSECURE.name(),
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   108
                TestCase.SECURE.name(),
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   109
            };
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   110
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   111
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   112
        // Sanity checks
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   113
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   114
        if (!Files.isWritable(Paths.get(userDir))) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   115
            throw new RuntimeException(userDir +
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   116
                    ": user.dir is not writable - can't run test.");
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   117
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   118
        if (!Files.isWritable(Paths.get(tmpDir))) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   119
            throw new RuntimeException(tmpDir +
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   120
                    ": java.io.tmpdir is not writable - can't run test.");
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   121
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   122
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   123
        File[] files = {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   124
            new File(logFile),
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   125
            new File(tmpLogFile),
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   126
            new File(logFile+".1"),
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   127
            new File(tmpLogFile+".1"),
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   128
            new File(logFile+".lck"),
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   129
            new File(tmpLogFile+".lck"),
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   130
            new File(logFile+".1.lck"),
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   131
            new File(tmpLogFile+".1.lck")
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   132
        };
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   133
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   134
        for (File log : files) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   135
            if (log.exists()) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   136
                throw new Exception(log +": file already exists - can't run test.");
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   137
            }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   138
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   139
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   140
        // Now start the real test
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   141
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   142
        try {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   143
            for (String testName : args) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   144
                for (Properties propertyFile : properties) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   145
                    TestCase test = TestCase.valueOf(testName);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   146
                    test.run(propertyFile);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   147
                }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   148
            }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   149
        } finally {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   150
            // Cleanup...
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   151
            Configure.doPrivileged(() -> {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   152
                for(File log : files) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   153
                    try {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   154
                        final boolean isLockFile = log.getName().endsWith(".lck");
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   155
                        // lock file should already be deleted, except if the
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   156
                        // test failed in exception.
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   157
                        // log file should all be present, except if the test
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   158
                        // failed in exception.
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   159
                        if (log.exists()) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   160
                            if (!isLockFile) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   161
                                System.out.println("deleting "+log.toString());
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   162
                            } else {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   163
                                System.err.println("deleting lock file "+log.toString());
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   164
                            }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   165
                            log.delete();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   166
                        } else {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   167
                            if (!isLockFile) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   168
                                System.err.println(log.toString() + ": not found.");
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   169
                            }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   170
                        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   171
                    } catch (Throwable t) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   172
                        // should not happen
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   173
                        t.printStackTrace();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   174
                    }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   175
                }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   176
            });
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   177
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   178
    }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   179
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   180
    static class Configure {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   181
        static Policy policy = null;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   182
        static final AtomicBoolean allowAll = new AtomicBoolean(false);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   183
        static void setUp(TestCase test, Properties propertyFile) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   184
            switch (test) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   185
                case SECURE:
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   186
                    if (policy == null && System.getSecurityManager() != null) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   187
                        throw new IllegalStateException("SecurityManager already set");
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   188
                    } else if (policy == null) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   189
                        policy = new SimplePolicy(TestCase.SECURE, allowAll);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   190
                        Policy.setPolicy(policy);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   191
                        System.setSecurityManager(new SecurityManager());
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   192
                    }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   193
                    if (System.getSecurityManager() == null) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   194
                        throw new IllegalStateException("No SecurityManager.");
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   195
                    }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   196
                    if (policy == null) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   197
                        throw new IllegalStateException("policy not configured");
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   198
                    }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   199
                    break;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   200
                case UNSECURE:
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   201
                    if (System.getSecurityManager() != null) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   202
                        throw new IllegalStateException("SecurityManager already set");
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   203
                    }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   204
                    break;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   205
                default:
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   206
                    new InternalError("No such testcase: " + test);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   207
            }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   208
            doPrivileged(() -> {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   209
                try {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   210
                    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   211
                    propertyFile.store(bytes, propertyFile.getProperty("test.name"));
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   212
                    ByteArrayInputStream bais = new ByteArrayInputStream(bytes.toByteArray());
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   213
                    LogManager.getLogManager().readConfiguration(bais);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   214
                } catch (IOException ex) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   215
                    throw new RuntimeException(ex);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   216
                }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   217
            });
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   218
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   219
        static void doPrivileged(Runnable run) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   220
            allowAll.set(true);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   221
            try {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   222
                run.run();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   223
            } finally {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   224
                allowAll.set(false);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   225
            }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   226
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   227
    }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   228
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   229
    public static void test(String name, Properties props) throws Exception {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   230
        System.out.println("Testing: " + name);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   231
        String file = props.getProperty("test.file.name");
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   232
        // create the lock files first - in order to take the path that
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   233
        // used to trigger the NPE
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   234
        Files.createFile(Paths.get(file + ".lck"));
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   235
        Files.createFile(Paths.get(file + ".1.lck"));
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   236
        final FileHandler f1 = new FileHandler();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   237
        final FileHandler f2 = new FileHandler();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   238
        f1.close();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   239
        f2.close();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   240
        System.out.println("Success for " + name);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   241
    }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   242
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   243
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30046
diff changeset
   244
    static final class PermissionsBuilder {
26864
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   245
        final Permissions perms;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   246
        public PermissionsBuilder() {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   247
            this(new Permissions());
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   248
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   249
        public PermissionsBuilder(Permissions perms) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   250
            this.perms = perms;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   251
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   252
        public PermissionsBuilder add(Permission p) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   253
            perms.add(p);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   254
            return this;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   255
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   256
        public PermissionsBuilder addAll(PermissionCollection col) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   257
            if (col != null) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   258
                for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   259
                    perms.add(e.nextElement());
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   260
                }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   261
            }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   262
            return this;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   263
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   264
        public Permissions toPermissions() {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   265
            final PermissionsBuilder builder = new PermissionsBuilder();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   266
            builder.addAll(perms);
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   267
            return builder.perms;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   268
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   269
    }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   270
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   271
    public static class SimplePolicy extends Policy {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   272
55462
6dfdcd31463d 8185139: [Graal] Tests which set too restrictive security manager fail with Graal
kvn
parents: 47216
diff changeset
   273
        static final Policy DEFAULT_POLICY = Policy.getPolicy();
6dfdcd31463d 8185139: [Graal] Tests which set too restrictive security manager fail with Graal
kvn
parents: 47216
diff changeset
   274
26864
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   275
        final Permissions permissions;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   276
        final Permissions allPermissions;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   277
        final AtomicBoolean allowAll;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   278
        public SimplePolicy(TestCase test, AtomicBoolean allowAll) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   279
            this.allowAll = allowAll;
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   280
            permissions = new Permissions();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   281
            permissions.add(new LoggingPermission("control", null)); // needed by new FileHandler()
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   282
            permissions.add(new FilePermission("<<ALL FILES>>", "read")); // needed by new FileHandler()
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   283
            permissions.add(new FilePermission(logFile, "write,delete")); // needed by new FileHandler()
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   284
            permissions.add(new FilePermission(logFile+".lck", "write,delete")); // needed by FileHandler.close()
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   285
            permissions.add(new FilePermission(logFile+".1", "write,delete")); // needed by new FileHandler()
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   286
            permissions.add(new FilePermission(logFile+".1.lck", "write,delete")); // needed by FileHandler.close()
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   287
            permissions.add(new FilePermission(tmpLogFile, "write,delete")); // needed by new FileHandler()
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   288
            permissions.add(new FilePermission(tmpLogFile+".lck", "write,delete")); // needed by FileHandler.close()
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   289
            permissions.add(new FilePermission(tmpLogFile+".1", "write,delete")); // needed by new FileHandler()
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   290
            permissions.add(new FilePermission(tmpLogFile+".1.lck", "write,delete")); // needed by FileHandler.close()
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   291
            permissions.add(new FilePermission(userDir, "write")); // needed by new FileHandler()
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   292
            permissions.add(new FilePermission(tmpDir, "write")); // needed by new FileHandler()
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   293
            permissions.add(new PropertyPermission("user.dir", "read"));
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   294
            permissions.add(new PropertyPermission("java.io.tmpdir", "read"));
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   295
            allPermissions = new Permissions();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   296
            allPermissions.add(new java.security.AllPermission());
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   297
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   298
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   299
        @Override
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   300
        public boolean implies(ProtectionDomain domain, Permission permission) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   301
            if (allowAll.get()) return allPermissions.implies(permission);
55462
6dfdcd31463d 8185139: [Graal] Tests which set too restrictive security manager fail with Graal
kvn
parents: 47216
diff changeset
   302
            return permissions.implies(permission) || DEFAULT_POLICY.implies(domain, permission);
26864
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   303
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   304
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   305
        @Override
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   306
        public PermissionCollection getPermissions(CodeSource codesource) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   307
            return new PermissionsBuilder().addAll(allowAll.get()
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   308
                    ? allPermissions : permissions).toPermissions();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   309
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   310
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   311
        @Override
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   312
        public PermissionCollection getPermissions(ProtectionDomain domain) {
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   313
            return new PermissionsBuilder().addAll(allowAll.get()
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   314
                    ? allPermissions : permissions).toPermissions();
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   315
        }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   316
    }
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   317
3383e655118e 8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
diff changeset
   318
}