jdk/test/java/util/logging/LogManager/Configuration/InvalidEscapeConfigurationTest.java
author dfuchs
Thu, 02 Apr 2015 11:42:07 +0200
changeset 29739 3966f5f6a6fd
permissions -rw-r--r--
8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException Summary: LogManager.readConfiguration will wrap the IllegalArgumentException thrown by Properties.load inside an IOException. Reviewed-by: lancea, mchung, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29739
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
     1
/*
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
     4
 *
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
     8
 *
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    14
 *
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    18
 *
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    21
 * questions.
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    22
 */
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    23
import java.io.ByteArrayInputStream;
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    24
import java.io.ByteArrayOutputStream;
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    25
import java.io.FileInputStream;
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    26
import java.io.IOException;
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    27
import java.io.InputStream;
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    28
import java.io.UncheckedIOException;
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    29
import java.io.UnsupportedEncodingException;
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    30
import java.nio.file.Files;
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    31
import java.nio.file.Paths;
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    32
import java.util.Properties;
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    33
import java.util.logging.LogManager;
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    34
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    35
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    36
/**
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    37
 * @test
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    38
 * @bug 8075810
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    39
 * @run main/othervm InvalidEscapeConfigurationTest
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    40
 * @author danielfuchs
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    41
 */
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    42
public class InvalidEscapeConfigurationTest {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    43
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    44
    public static void main(String[] args)
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    45
            throws UnsupportedEncodingException, IOException {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    46
        String[] validEscapes = {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    47
            "com.f\\u006fo.level = INF\\u004f",
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    48
            "com.f\\u006fo.level = INFO",
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    49
            "com.foo.level = INF\\u004f"
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    50
        };
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    51
        String[] invalidEscapes = {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    52
            "com.fo\\u0O6f.level = INF\\u0O4f",
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    53
            "com.fo\\u0O6f.level = INFO",
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    54
            "com.foo.level = INF\\u0O4f"
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    55
        };
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    56
        for (String line : validEscapes) {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    57
            test(line, true);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    58
        }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    59
        for (String line : invalidEscapes) {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    60
            test(line, false);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    61
        }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    62
        try {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    63
            Properties props = new Properties();
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    64
            props.load((InputStream)null);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    65
            throw new RuntimeException("Properties.load(null): "
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    66
                    + "NullPointerException exception not raised");
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    67
        } catch (NullPointerException x) {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    68
            System.out.println("Properties.load(null): "
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    69
                    + "got expected exception: " + x);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    70
        }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    71
        try {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    72
            LogManager.getLogManager().readConfiguration(null);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    73
            throw new RuntimeException("LogManager.readConfiguration(null): "
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    74
                    + "NullPointerException exception not raised");
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    75
        } catch (NullPointerException x) {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    76
            System.out.println("LogManager.readConfiguration(null): "
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    77
                    + "got expected exception: " + x);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    78
        }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    79
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    80
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    81
    }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    82
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    83
    public static void test(String line, boolean valid) throws IOException {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    84
        String test = (valid ? "valid" : "invalid")
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    85
                + " line \"" +line + "\"";
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    86
        System.out.println("Testing " + test);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    87
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    88
        // First verify that we get the expected result from Properties.load()
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    89
        try {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    90
            ByteArrayInputStream bais =
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    91
                    new ByteArrayInputStream(line.getBytes("UTF-8"));
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    92
            Properties props = new Properties();
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    93
            props.load(bais);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    94
            if (!valid) {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    95
                throw new RuntimeException(test
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    96
                        + "\n\tProperties.load: expected exception not raised");
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    97
            } else {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    98
                System.out.println("Properties.load passed for " + test);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
    99
            }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   100
        } catch(IllegalArgumentException x) {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   101
            if (!valid) {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   102
                System.out.println(
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   103
                        "Properties.load: Got expected exception: "
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   104
                        + x + "\n\tfor " + test);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   105
            } else {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   106
                throw x;
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   107
            }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   108
        }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   109
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   110
        // Then verify that we get the expected result from
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   111
        // LogManager.readConfiguration
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   112
        try {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   113
            String content = defaultConfiguration() + '\n' + line + '\n';
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   114
            ByteArrayInputStream bais =
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   115
                    new ByteArrayInputStream(content.getBytes("UTF-8"));
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   116
            LogManager.getLogManager().readConfiguration(bais);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   117
            if (!valid) {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   118
                throw new RuntimeException(test
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   119
                        + "\n\tLogManager.readConfiguration: "
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   120
                        + "expected exception not raised");
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   121
            } else {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   122
                System.out.println("LogManager.readConfiguration passed for "
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   123
                        + test);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   124
            }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   125
        } catch(IOException x) {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   126
            if (!valid) {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   127
                System.out.println(
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   128
                        "LogManager.readConfiguration: Got expected exception: "
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   129
                        + x + "\n\tfor " + test);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   130
            } else {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   131
                throw x;
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   132
            }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   133
        }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   134
    }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   135
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   136
    static String getConfigurationFileName() {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   137
        String fname = System.getProperty("java.util.logging.config.file");
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   138
        if (fname == null) {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   139
            fname = System.getProperty("java.home");
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   140
            if (fname == null) {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   141
                throw new Error("Can't find java.home ??");
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   142
            }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   143
            fname = Paths.get(fname, "conf", "logging.properties")
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   144
                    .toAbsolutePath().normalize().toString();
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   145
        }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   146
        return fname;
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   147
    }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   148
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   149
    static String defaultConfiguration() throws IOException {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   150
        Properties props = new Properties();
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   151
        String fileName = getConfigurationFileName();
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   152
        if (Files.exists(Paths.get(fileName))) {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   153
            try (InputStream is = new FileInputStream(fileName);) {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   154
                props.load(is);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   155
            } catch(IOException x) {
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   156
                throw new UncheckedIOException(x);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   157
            }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   158
        }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   159
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   160
        props.store(bos, null);
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   161
        return bos.toString();
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   162
    }
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   163
3966f5f6a6fd 8075810: LogManager.readConfiguration may throw undocumented IllegalArgumentException
dfuchs
parents:
diff changeset
   164
}