1 /*
2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 import java.util.MissingResourceException;
24 import java.util.logging.Logger;
25 
26 /*
27  * This class is loaded onto the call stack by LoadItUp2Invoker from a separate
28  * classloader.  LoadItUp2Invoker was loaded by a class loader that does have
29  * access to the bundle, but the class loader used to load this class does not.
30  * Thus the logging code should not be able to see the resource bundle unless
31  * it has more than a single level stack crawl, which is not allowed.
32  *
33  * @author Jim Gish
34  */
35 public class LoadItUp2 {
36 
37     private final static boolean DEBUG = false;
38 
test(String rbName)39     public Boolean test(String rbName) throws Exception {
40         // we should not be able to find the resource in this directory via
41         // getLogger calls.  The only way that would be possible given this setup
42         // is that if Logger.getLogger searched up the call stack
43         return lookupBundle(rbName);
44     }
45 
lookupBundle(String rbName)46     private boolean lookupBundle(String rbName) {
47         // See if Logger.getLogger can find the resource in this directory
48         try {
49             Logger aLogger = Logger.getLogger("NestedLogger2", rbName);
50         } catch (MissingResourceException re) {
51             if (DEBUG) {
52                 System.out.println(
53                     "As expected, LoadItUp2.lookupBundle() did not find the bundle "
54                     + rbName);
55             }
56             return false;
57         }
58         System.out.println("FAILED: LoadItUp2.lookupBundle() found the bundle "
59                 + rbName + " using a stack search.");
60         return true;
61     }
62 }
63