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 when the test method is called |
|
28 * and then its classloader can be used to find a property bundle in the same |
|
29 * directory as the class. However, Logger is not allowed |
|
30 * to find the bundle by looking up the stack for this classloader. |
|
31 * We verify that this cannot happen. |
|
32 * |
|
33 * @author Jim Gish |
|
34 */ |
|
35 public class LoadItUp { |
|
36 |
|
37 private final static boolean DEBUG = false; |
|
38 |
|
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 |
|
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("NestedLogger", rbName); |
|
50 } catch (MissingResourceException re) { |
|
51 if (DEBUG) { |
|
52 System.out.println( |
|
53 "As expected, LoadItUp.lookupBundle() did not find the bundle " |
|
54 + rbName); |
|
55 } |
|
56 return false; |
|
57 } |
|
58 System.out.println("FAILED: LoadItUp.lookupBundle() found the bundle " |
|
59 + rbName + " using a stack search."); |
|
60 return true; |
|
61 } |
|
62 } |
|