jdk/test/java/util/logging/bundlesearch/LoadItUp.java
author jgish
Thu, 18 Apr 2013 16:33:11 -0400
changeset 17159 bb566a21b661
permissions -rw-r--r--
8012005: LogManager needs test to ensure stack trace is not being done to find bundle Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17159
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
     1
/*
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
     4
 *
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
     8
 *
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    13
 * accompanied this code).
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    14
 *
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    18
 *
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    21
 * questions.
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    22
 */
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    23
import java.util.MissingResourceException;
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    24
import java.util.logging.Logger;
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    25
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    26
/*
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    27
 * This class is loaded onto the call stack when the test method is called
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    28
 * and then its classloader can be used to find a property bundle in the same
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    29
 * directory as the class.  However, Logger is not allowed
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    30
 * to find the bundle by looking up the stack for this classloader.
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    31
 * We verify that this cannot happen.
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    32
 *
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    33
 * @author Jim Gish
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    34
 */
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    35
public class LoadItUp {
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    36
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    37
    private final static boolean DEBUG = false;
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    38
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    39
    public Boolean test(String rbName) throws Exception {
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    40
        // we should not be able to find the resource in this directory via
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    41
        // getLogger calls.  The only way that would be possible given this setup
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    42
        // is that if Logger.getLogger searched up the call stack
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    43
        return lookupBundle(rbName);
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    44
    }
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    45
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    46
    private boolean lookupBundle(String rbName) {
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    47
        // See if Logger.getLogger can find the resource in this directory
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    48
        try {
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    49
            Logger aLogger = Logger.getLogger("NestedLogger", rbName);
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    50
        } catch (MissingResourceException re) {
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    51
            if (DEBUG) {
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    52
                System.out.println(
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    53
                    "As expected, LoadItUp.lookupBundle() did not find the bundle "
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    54
                    + rbName);
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    55
            }
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    56
            return false;
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    57
        }
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    58
        System.out.println("FAILED: LoadItUp.lookupBundle() found the bundle "
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    59
                + rbName + " using a stack search.");
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    60
        return true;
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    61
    }
bb566a21b661 8012005: LogManager needs test to ensure stack trace is not being done to find bundle
jgish
parents:
diff changeset
    62
}