test/jdk/java/util/logging/FileHandlerPatternExceptions.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:
26874
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
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.
26874
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
     4
 *
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
     8
 *
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    14
 *
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    18
 *
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    21
 * questions.
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    22
 */
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    23
import java.io.ByteArrayInputStream;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    24
import java.io.ByteArrayOutputStream;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    25
import java.io.IOException;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    26
import java.nio.file.Files;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    27
import java.nio.file.Paths;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    28
import java.security.AccessControlException;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    29
import java.security.CodeSource;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    30
import java.security.Permission;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    31
import java.security.PermissionCollection;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    32
import java.security.Permissions;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    33
import java.security.Policy;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    34
import java.security.ProtectionDomain;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    35
import java.util.Arrays;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    36
import java.util.Collections;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    37
import java.util.Enumeration;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    38
import java.util.List;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    39
import java.util.Properties;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    40
import java.util.UUID;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    41
import java.util.concurrent.atomic.AtomicBoolean;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    42
import java.util.logging.FileHandler;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    43
import java.util.logging.LogManager;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    44
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    45
/**
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    46
 * @test
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    47
 * @bug 8025690
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    48
 * @summary tests that an empty or null pattern always result in an exception.
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    49
 * @run main/othervm FileHandlerPatternExceptions UNSECURE
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    50
 * @run main/othervm FileHandlerPatternExceptions SECURE
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    51
 * @author danielfuchs
30046
cf2c86e1819e 8078334: Mark regression tests using randomness
darcy
parents: 26874
diff changeset
    52
 * @key randomness
26874
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    53
 */
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    54
public class FileHandlerPatternExceptions {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    55
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    56
    /**
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    57
     * We will test null/empty pattern in two configurations.
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    58
     * UNSECURE: No security manager.
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    59
     * SECURE: With the security manager present - and the required
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    60
     *         permissions granted.
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    61
     */
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    62
    public static enum TestCase {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    63
        UNSECURE, SECURE;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    64
        public void run(Properties propertyFile) throws Exception {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    65
            System.out.println("Running test case: " + name());
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    66
            Configure.setUp(this, propertyFile);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    67
            test(this.name() + " " + propertyFile.getProperty("test.name"));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    68
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    69
    }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    70
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    71
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    72
    private static final String PREFIX =
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    73
            "FileHandler-" + UUID.randomUUID() + ".log";
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    74
    private static final String userDir = System.getProperty("user.dir", ".");
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    75
    private static final boolean userDirWritable = Files.isWritable(Paths.get(userDir));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    76
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    77
    private static final List<Properties> properties;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    78
    static {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    79
        Properties props1 = new Properties();
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    80
        Properties props2 = new Properties();
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    81
        props1.setProperty("test.name", "with count=1");
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    82
        props1.setProperty(FileHandler.class.getName() + ".pattern", "");
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    83
        props1.setProperty(FileHandler.class.getName() + ".count", "1");
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    84
        props2.setProperty("test.name", "with count=2");
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    85
        props2.setProperty(FileHandler.class.getName() + ".pattern", "");
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    86
        props2.setProperty(FileHandler.class.getName() + ".count", "2");
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    87
        properties = Collections.unmodifiableList(Arrays.asList(
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    88
                    props1,
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    89
                    props2));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    90
    }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    91
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    92
    public static void main(String... args) throws Exception {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    93
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    94
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    95
        if (args == null || args.length == 0) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    96
            args = new String[] {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    97
                TestCase.UNSECURE.name(),
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    98
                TestCase.SECURE.name(),
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
    99
            };
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   100
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   101
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   102
        try {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   103
            for (String testName : args) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   104
                for (Properties propertyFile : properties) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   105
                    TestCase test = TestCase.valueOf(testName);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   106
                    test.run(propertyFile);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   107
                }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   108
            }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   109
        } finally {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   110
            if (userDirWritable) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   111
                Configure.doPrivileged(() -> {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   112
                    // cleanup - delete files that have been created
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   113
                    try {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   114
                        Files.list(Paths.get(userDir))
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   115
                            .filter((f) -> f.toString().contains(PREFIX))
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   116
                            .forEach((f) -> {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   117
                                try {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   118
                                    System.out.println("deleting " + f);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   119
                                    Files.delete(f);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   120
                                } catch(Throwable t) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   121
                                    System.err.println("Failed to delete " + f + ": " + t);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   122
                                }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   123
                            });
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   124
                    } catch(Throwable t) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   125
                        System.err.println("Cleanup failed to list files: " + t);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   126
                        t.printStackTrace();
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   127
                    }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   128
                });
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   129
            }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   130
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   131
    }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   132
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   133
    static class Configure {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   134
        static Policy policy = null;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   135
        static final AtomicBoolean allowAll = new AtomicBoolean(false);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   136
        static void setUp(TestCase test, Properties propertyFile) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   137
            switch (test) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   138
                case SECURE:
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   139
                    if (policy == null && System.getSecurityManager() != null) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   140
                        throw new IllegalStateException("SecurityManager already set");
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   141
                    } else if (policy == null) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   142
                        policy = new SimplePolicy(TestCase.SECURE, allowAll);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   143
                        Policy.setPolicy(policy);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   144
                        System.setSecurityManager(new SecurityManager());
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   145
                    }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   146
                    if (System.getSecurityManager() == null) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   147
                        throw new IllegalStateException("No SecurityManager.");
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   148
                    }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   149
                    if (policy == null) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   150
                        throw new IllegalStateException("policy not configured");
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   151
                    }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   152
                    break;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   153
                case UNSECURE:
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   154
                    if (System.getSecurityManager() != null) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   155
                        throw new IllegalStateException("SecurityManager already set");
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   156
                    }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   157
                    break;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   158
                default:
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   159
                    new InternalError("No such testcase: " + test);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   160
            }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   161
            doPrivileged(() -> {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   162
                try {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   163
                    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   164
                    propertyFile.store(bytes, propertyFile.getProperty("test.name"));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   165
                    ByteArrayInputStream bais = new ByteArrayInputStream(bytes.toByteArray());
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   166
                    LogManager.getLogManager().readConfiguration(bais);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   167
                } catch (IOException ex) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   168
                    throw new RuntimeException(ex);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   169
                }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   170
            });
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   171
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   172
        static void doPrivileged(Runnable run) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   173
            allowAll.set(true);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   174
            try {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   175
                run.run();
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   176
            } finally {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   177
                allowAll.set(false);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   178
            }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   179
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   180
    }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   181
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   182
    @FunctionalInterface
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   183
    public static interface FileHandlerSupplier {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   184
        public FileHandler test() throws Exception;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   185
    }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   186
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   187
    private static void checkException(Class<? extends Exception> type, FileHandlerSupplier test) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   188
        Throwable t = null;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   189
        FileHandler f = null;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   190
        try {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   191
            f = test.test();
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   192
        } catch (Throwable x) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   193
            t = x;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   194
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   195
        try {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   196
            if (type != null && t == null) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   197
                throw new RuntimeException("Expected " + type.getName() + " not thrown");
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   198
            } else if (type != null && t != null) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   199
                if (type.isInstance(t)) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   200
                    System.out.println("Recieved expected exception: " + t);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   201
                } else {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   202
                    throw new RuntimeException("Exception type mismatch: "
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   203
                        + type.getName() + " expected, "
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   204
                        + t.getClass().getName() + " received.", t);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   205
                }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   206
            } else if (t != null) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   207
                throw new RuntimeException("Unexpected exception received: " + t, t);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   208
            }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   209
        } finally {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   210
            if (f != null) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   211
                // f should always be null when an exception is expected,
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   212
                // but in case the test doesn't behave as expected we will
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   213
                // want to close f.
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   214
                try { f.close(); } catch (Throwable x) {};
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   215
            }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   216
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   217
    }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   218
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   219
    public static void test(String name) throws Exception {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   220
        System.out.println("Testing: " + name);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   221
        checkException(RuntimeException.class, () -> new FileHandler());
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   222
        checkException(IllegalArgumentException.class, () -> new FileHandler(""));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   223
        checkException(NullPointerException.class, () -> new FileHandler(null));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   224
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   225
        checkException(IllegalArgumentException.class, () -> new FileHandler("", true));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   226
        checkException(IllegalArgumentException.class, () -> new FileHandler("", false));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   227
        checkException(NullPointerException.class, () -> new FileHandler(null, true));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   228
        checkException(NullPointerException.class, () -> new FileHandler(null, false));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   229
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   230
        checkException(IllegalArgumentException.class, () -> new FileHandler("", 1, 1));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   231
        checkException(IllegalArgumentException.class, () -> new FileHandler(PREFIX, 0, 0));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   232
        checkException(IllegalArgumentException.class, () -> new FileHandler(PREFIX, -1, 1));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   233
        checkException(IllegalArgumentException.class, () -> new FileHandler("", 0, 0));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   234
        checkException(IllegalArgumentException.class, () -> new FileHandler("", -1, 1));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   235
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   236
        checkException(IllegalArgumentException.class, () -> new FileHandler("", 1, 1, true));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   237
        checkException(IllegalArgumentException.class, () -> new FileHandler(PREFIX, 0, 0, true));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   238
        checkException(IllegalArgumentException.class, () -> new FileHandler(PREFIX, -1, 1, true));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   239
        checkException(IllegalArgumentException.class, () -> new FileHandler("", 0, 0, true));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   240
        checkException(IllegalArgumentException.class, () -> new FileHandler("", -1, 1, true));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   241
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   242
        checkException(IllegalArgumentException.class, () -> new FileHandler("", 1, 1, false));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   243
        checkException(IllegalArgumentException.class, () -> new FileHandler(PREFIX, 0, 0, false));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   244
        checkException(IllegalArgumentException.class, () -> new FileHandler(PREFIX, -1, 1, false));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   245
        checkException(IllegalArgumentException.class, () -> new FileHandler("", 0, 0, false));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   246
        checkException(IllegalArgumentException.class, () -> new FileHandler("", -1, 1, false));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   247
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   248
        final Class<? extends Exception> expectedException =
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   249
                System.getSecurityManager() != null ? AccessControlException.class : null;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   250
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   251
        if (userDirWritable || expectedException != null) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   252
            // These calls will create files in user.dir in the UNSECURE case.
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   253
            // The file name contain a random UUID (PREFIX) which identifies them
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   254
            // and allow us to remove them cleanly at the end (see finally block
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   255
            // in main()).
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   256
            checkException(expectedException,
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   257
                           () -> new FileHandler(PREFIX, 0, 1, true));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   258
            checkException(expectedException,
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   259
                           () -> new FileHandler(PREFIX, 1, 2, true));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   260
            checkException(expectedException,
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   261
                           () -> new FileHandler(PREFIX, 0, 1, false));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   262
            checkException(expectedException,
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   263
                           () -> new FileHandler(PREFIX, 1, 2, false));
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   264
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   265
    }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   266
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   267
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30046
diff changeset
   268
    static final class PermissionsBuilder {
26874
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   269
        final Permissions perms;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   270
        public PermissionsBuilder() {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   271
            this(new Permissions());
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   272
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   273
        public PermissionsBuilder(Permissions perms) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   274
            this.perms = perms;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   275
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   276
        public PermissionsBuilder add(Permission p) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   277
            perms.add(p);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   278
            return this;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   279
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   280
        public PermissionsBuilder addAll(PermissionCollection col) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   281
            if (col != null) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   282
                for (Enumeration<Permission> e = col.elements(); e.hasMoreElements(); ) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   283
                    perms.add(e.nextElement());
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   284
                }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   285
            }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   286
            return this;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   287
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   288
        public Permissions toPermissions() {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   289
            final PermissionsBuilder builder = new PermissionsBuilder();
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   290
            builder.addAll(perms);
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   291
            return builder.perms;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   292
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   293
    }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   294
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   295
    public static class SimplePolicy extends Policy {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   296
55462
6dfdcd31463d 8185139: [Graal] Tests which set too restrictive security manager fail with Graal
kvn
parents: 47216
diff changeset
   297
        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
   298
26874
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   299
        final Permissions permissions;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   300
        final Permissions allPermissions;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   301
        final AtomicBoolean allowAll;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   302
        public SimplePolicy(TestCase test, AtomicBoolean allowAll) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   303
            this.allowAll = allowAll;
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   304
            // we don't actually need any permission to create our
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   305
            // FileHandlers because we're passing invalid parameters
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   306
            // which will make the creation fail...
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   307
            permissions = new Permissions();
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   308
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   309
            // these are used for configuring the test itself...
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   310
            allPermissions = new Permissions();
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   311
            allPermissions.add(new java.security.AllPermission());
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   312
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   313
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   314
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   315
        @Override
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   316
        public boolean implies(ProtectionDomain domain, Permission permission) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   317
            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
   318
            return permissions.implies(permission) || DEFAULT_POLICY.implies(domain, permission);
26874
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   319
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   320
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   321
        @Override
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   322
        public PermissionCollection getPermissions(CodeSource codesource) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   323
            return new PermissionsBuilder().addAll(allowAll.get()
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   324
                    ? allPermissions : permissions).toPermissions();
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   325
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   326
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   327
        @Override
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   328
        public PermissionCollection getPermissions(ProtectionDomain domain) {
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   329
            return new PermissionsBuilder().addAll(allowAll.get()
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   330
                    ? allPermissions : permissions).toPermissions();
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   331
        }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   332
    }
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   333
5ff3fbb88d3c 8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
diff changeset
   334
}