test/jdk/java/lang/System/LoggerFinder/internal/BasePlatformLoggerTest/BasePlatformLoggerTest.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
53 * @bug 8140364 |
53 * @bug 8140364 |
54 * @summary JDK implementation specific unit test for JDK internal API. |
54 * @summary JDK implementation specific unit test for JDK internal API. |
55 * Tests a naive implementation of System.Logger, and in particular |
55 * Tests a naive implementation of System.Logger, and in particular |
56 * the default mapping provided by PlatformLogger. |
56 * the default mapping provided by PlatformLogger. |
57 * @modules java.base/sun.util.logging |
57 * @modules java.base/sun.util.logging |
58 * @build CustomSystemClassLoader BasePlatformLoggerTest |
58 * @build CustomSystemClassLoader BaseLoggerFinder BasePlatformLoggerTest |
59 * @run main/othervm -Djava.system.class.loader=CustomSystemClassLoader BasePlatformLoggerTest NOSECURITY |
59 * @run main/othervm -Djava.system.class.loader=CustomSystemClassLoader BasePlatformLoggerTest NOSECURITY |
60 * @run main/othervm -Djava.system.class.loader=CustomSystemClassLoader BasePlatformLoggerTest NOPERMISSIONS |
60 * @run main/othervm -Djava.system.class.loader=CustomSystemClassLoader BasePlatformLoggerTest NOPERMISSIONS |
61 * @run main/othervm -Djava.system.class.loader=CustomSystemClassLoader BasePlatformLoggerTest WITHPERMISSIONS |
61 * @run main/othervm -Djava.system.class.loader=CustomSystemClassLoader BasePlatformLoggerTest WITHPERMISSIONS |
62 * @author danielfuchs |
62 * @author danielfuchs |
63 */ |
63 */ |
88 }; |
88 }; |
89 |
89 |
90 static final Class<?> providerClass; |
90 static final Class<?> providerClass; |
91 static { |
91 static { |
92 try { |
92 try { |
93 providerClass = ClassLoader.getSystemClassLoader().loadClass("BasePlatformLoggerTest$BaseLoggerFinder"); |
93 providerClass = ClassLoader.getSystemClassLoader().loadClass("BaseLoggerFinder"); |
94 } catch (ClassNotFoundException ex) { |
94 } catch (ClassNotFoundException ex) { |
95 throw new ExceptionInInitializerError(ex); |
95 throw new ExceptionInInitializerError(ex); |
96 } |
96 } |
97 } |
97 } |
98 |
98 |
326 log(LogEvent.of(isLoggable(level), name, level, thrown, msgSupplier)); |
326 log(LogEvent.of(isLoggable(level), name, level, thrown, msgSupplier)); |
327 } |
327 } |
328 } |
328 } |
329 |
329 |
330 public Logger getLogger(String name, Module caller); |
330 public Logger getLogger(String name, Module caller); |
331 } |
|
332 |
|
333 public static class BaseLoggerFinder extends LoggerFinder implements TestLoggerFinder { |
|
334 @Override |
|
335 public Logger getLogger(String name, Module caller) { |
|
336 SecurityManager sm = System.getSecurityManager(); |
|
337 if (sm != null) { |
|
338 sm.checkPermission(LOGGERFINDER_PERMISSION); |
|
339 } |
|
340 PrivilegedAction<ClassLoader> pa = () -> caller.getClassLoader(); |
|
341 ClassLoader callerLoader = AccessController.doPrivileged(pa); |
|
342 if (callerLoader == null) { |
|
343 return system.computeIfAbsent(name, (n) -> new LoggerImpl(n)); |
|
344 } else { |
|
345 return user.computeIfAbsent(name, (n) -> new LoggerImpl(n)); |
|
346 } |
|
347 } |
|
348 } |
331 } |
349 |
332 |
350 static PlatformLogger getPlatformLogger(String name) { |
333 static PlatformLogger getPlatformLogger(String name) { |
351 boolean old = allowAccess.get().get(); |
334 boolean old = allowAccess.get().get(); |
352 allowAccess.get().set(true); |
335 allowAccess.get().set(true); |