< prev index next >

test/java/lang/System/LoggerFinder/internal/LoggerBridgeTest/LoggerBridgeTest.java

Print this page

        

*** 49,58 **** --- 49,59 ---- import java.lang.System.LoggerFinder; import java.lang.System.Logger; import java.lang.System.Logger.Level; import java.util.stream.Stream; import sun.util.logging.PlatformLogger; + import java.lang.reflect.Module; /** * @test * @bug 8140364 * @summary JDK implementation specific unit test for JDK internal artifacts.
*** 162,171 **** --- 163,173 ---- String key, Throwable thrown, Object... params) { return LogEvent.of(sequenceNumber, isLoggable, name, null, null, level, bundle, key, thrown, params); } + public static LogEvent of(long sequenceNumber, boolean isLoggable, String name, sun.util.logging.PlatformLogger.Level level, ResourceBundle bundle, Supplier<String> supplier, Throwable thrown, Object... params) { return LogEvent.of(sequenceNumber, isLoggable, name,
*** 229,239 **** static final Class<?> providerClass; static { try { // Preload classes before the security manager is on. providerClass = ClassLoader.getSystemClassLoader().loadClass("LoggerBridgeTest$LogProducerFinder"); ! ((LoggerFinder)providerClass.newInstance()).getLogger("foo", providerClass); } catch (Exception ex) { throw new ExceptionInInitializerError(ex); } } --- 231,241 ---- static final Class<?> providerClass; static { try { // Preload classes before the security manager is on. providerClass = ClassLoader.getSystemClassLoader().loadClass("LoggerBridgeTest$LogProducerFinder"); ! ((LoggerFinder)providerClass.newInstance()).getLogger("foo", providerClass.getModule()); } catch (Exception ex) { throw new ExceptionInInitializerError(ex); } }
*** 413,423 **** } } @Override ! public Logger getLogger(String name, Class<?> caller) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(LOGGERFINDER_PERMISSION); } PrivilegedAction<ClassLoader> pa = () -> caller.getClassLoader(); --- 415,425 ---- } } @Override ! public Logger getLogger(String name, Module caller) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(LOGGERFINDER_PERMISSION); } PrivilegedAction<ClassLoader> pa = () -> caller.getClassLoader();
*** 428,437 **** --- 430,448 ---- return user.computeIfAbsent(name, (n) -> new LoggerImpl(n)); } } } + static ClassLoader getClassLoader(Module m) { + final boolean before = allowAll.get().getAndSet(true); + try { + return m.getClassLoader(); + } finally { + allowAll.get().set(before); + } + } + static final sun.util.logging.PlatformLogger.Level[] julLevels = { sun.util.logging.PlatformLogger.Level.ALL, sun.util.logging.PlatformLogger.Level.FINEST, sun.util.logging.PlatformLogger.Level.FINER, sun.util.logging.PlatformLogger.Level.FINE,
*** 495,512 **** static { // jdk.internal.logging.LoggerBridge.getLogger(name, caller) try { Class<?> bridgeClass = Class.forName("jdk.internal.logger.LazyLoggers"); lazyGetLogger = bridgeClass.getDeclaredMethod("getLogger", ! String.class, Class.class); lazyGetLogger.setAccessible(true); } catch (Throwable ex) { throw new ExceptionInInitializerError(ex); } } ! static Logger getLogger(LoggerFinder provider, String name, Class<?> caller) { Logger logger; try { logger = Logger.class.cast(lazyGetLogger.invoke(null, name, caller)); } catch (Throwable x) { Throwable t = (x instanceof InvocationTargetException) ? --- 506,523 ---- static { // jdk.internal.logging.LoggerBridge.getLogger(name, caller) try { Class<?> bridgeClass = Class.forName("jdk.internal.logger.LazyLoggers"); lazyGetLogger = bridgeClass.getDeclaredMethod("getLogger", ! String.class, Module.class); lazyGetLogger.setAccessible(true); } catch (Throwable ex) { throw new ExceptionInInitializerError(ex); } } ! static Logger getLogger(LoggerFinder provider, String name, Module caller) { Logger logger; try { logger = Logger.class.cast(lazyGetLogger.invoke(null, name, caller)); } catch (Throwable x) { Throwable t = (x instanceof InvocationTargetException) ?
*** 520,537 **** } } // The method above does not throw exception... // call the provider here to verify that an exception would have // been thrown by the provider. ! if (logger != null && caller == Thread.class) { Logger log = provider.getLogger(name, caller); } return logger; } ! static Logger getLogger(LoggerFinder provider, String name, ResourceBundle bundle, Class<?> caller) { ! if (caller.getClassLoader() != null) { return System.getLogger(name,bundle); } else { return provider.getLocalizedLogger(name, bundle, caller); } } --- 531,548 ---- } } // The method above does not throw exception... // call the provider here to verify that an exception would have // been thrown by the provider. ! if (logger != null && caller == Thread.class.getModule()) { Logger log = provider.getLogger(name, caller); } return logger; } ! static Logger getLogger(LoggerFinder provider, String name, ResourceBundle bundle, Module caller) { ! if (getClassLoader(caller) != null) { return System.getLogger(name,bundle); } else { return provider.getLocalizedLogger(name, bundle, caller); } }
*** 612,627 **** ResourceBundle loggerBundle = ResourceBundle.getBundle(MyLoggerBundle.class.getName()); final Map<Object, String> loggerDescMap = new HashMap<>(); Logger appLogger1 = System.getLogger("foo"); ! loggerDescMap.put(appLogger1, "LogProducer.getApplicationLogger(\"foo\")"); Logger sysLogger1 = null; try { ! sysLogger1 = getLogger(provider, "foo", Thread.class); ! loggerDescMap.put(sysLogger1, "LogProducer.getSystemLogger(\"foo\")"); if (!hasRequiredPermissions) { throw new RuntimeException("Managed to obtain a system logger without permission"); } } catch (AccessControlException acx) { if (hasRequiredPermissions) { --- 623,638 ---- ResourceBundle loggerBundle = ResourceBundle.getBundle(MyLoggerBundle.class.getName()); final Map<Object, String> loggerDescMap = new HashMap<>(); Logger appLogger1 = System.getLogger("foo"); ! loggerDescMap.put(appLogger1, "System.getLogger(\"foo\")"); Logger sysLogger1 = null; try { ! sysLogger1 = getLogger(provider, "foo", Thread.class.getModule()); ! loggerDescMap.put(sysLogger1, "provider.getLogger(\"foo\", Thread.class.getModule())"); if (!hasRequiredPermissions) { throw new RuntimeException("Managed to obtain a system logger without permission"); } } catch (AccessControlException acx) { if (hasRequiredPermissions) {
*** 634,649 **** } Logger appLogger2 = System.getLogger("foo", loggerBundle); ! loggerDescMap.put(appLogger2, "LogProducer.getApplicationLogger(\"foo\", loggerBundle)"); Logger sysLogger2 = null; try { ! sysLogger2 = getLogger(provider, "foo", loggerBundle, Thread.class); ! loggerDescMap.put(sysLogger2, "provider.getSystemLogger(\"foo\", loggerBundle)"); if (!hasRequiredPermissions) { throw new RuntimeException("Managed to obtain a system logger without permission"); } } catch (AccessControlException acx) { if (hasRequiredPermissions) { --- 645,660 ---- } Logger appLogger2 = System.getLogger("foo", loggerBundle); ! loggerDescMap.put(appLogger2, "System.getLogger(\"foo\", loggerBundle)"); Logger sysLogger2 = null; try { ! sysLogger2 = getLogger(provider, "foo", loggerBundle, Thread.class.getModule()); ! loggerDescMap.put(sysLogger2, "provider.getLogger(\"foo\", loggerBundle, Thread.class.getModule())"); if (!hasRequiredPermissions) { throw new RuntimeException("Managed to obtain a system logger without permission"); } } catch (AccessControlException acx) { if (hasRequiredPermissions) {
*** 669,681 **** final LogProducerFinder.LoggerImpl sysSink; boolean old = allowControl.get().get(); allowControl.get().set(true); try { appSink = LogProducerFinder.LoggerImpl.class.cast( ! provider.getLogger("foo", LoggerBridgeTest.class)); sysSink = LogProducerFinder.LoggerImpl.class.cast( ! provider.getLogger("foo", Thread.class)); } finally { allowControl.get().set(old); } testLogger(provider, loggerDescMap, "foo", null, convert(appLogger1), appSink); --- 680,692 ---- final LogProducerFinder.LoggerImpl sysSink; boolean old = allowControl.get().get(); allowControl.get().set(true); try { appSink = LogProducerFinder.LoggerImpl.class.cast( ! provider.getLogger("foo", LoggerBridgeTest.class.getModule())); sysSink = LogProducerFinder.LoggerImpl.class.cast( ! provider.getLogger("foo", Thread.class.getModule())); } finally { allowControl.get().set(old); } testLogger(provider, loggerDescMap, "foo", null, convert(appLogger1), appSink);
< prev index next >