8148568: LoggerFinder.getLogger and LoggerFinder.getLocalizedLogger should take a Module argument instead of a Class

Changes System.LoggerFinder methods to take a Module argument instead of a Class.

Reviewed-by: mchung
This commit is contained in:
Daniel Fuchs 2016-04-27 18:04:16 +02:00
parent fe4860fe5e
commit 1e0d1458a2
25 changed files with 342 additions and 250 deletions

View File

@ -1155,8 +1155,9 @@ public final class System {
* @param level the log message level. * @param level the log message level.
* @param msg the string message (or a key in the message catalog, if * @param msg the string message (or a key in the message catalog, if
* this logger is a {@link * this logger is a {@link
* LoggerFinder#getLocalizedLogger(java.lang.String, java.util.ResourceBundle, java.lang.Class) * LoggerFinder#getLocalizedLogger(java.lang.String,
* localized logger}); can be {@code null}. * java.util.ResourceBundle, java.lang.reflect.Module) localized logger});
* can be {@code null}.
* *
* @throws NullPointerException if {@code level} is {@code null}. * @throws NullPointerException if {@code level} is {@code null}.
*/ */
@ -1222,8 +1223,9 @@ public final class System {
* @param level the log message level. * @param level the log message level.
* @param msg the string message (or a key in the message catalog, if * @param msg the string message (or a key in the message catalog, if
* this logger is a {@link * this logger is a {@link
* LoggerFinder#getLocalizedLogger(java.lang.String, java.util.ResourceBundle, java.lang.Class) * LoggerFinder#getLocalizedLogger(java.lang.String,
* localized logger}); can be {@code null}. * java.util.ResourceBundle, java.lang.reflect.Module) localized logger});
* can be {@code null}.
* @param thrown a {@code Throwable} associated with the log message; * @param thrown a {@code Throwable} associated with the log message;
* can be {@code null}. * can be {@code null}.
* *
@ -1270,8 +1272,9 @@ public final class System {
* @param format the string message format in {@link * @param format the string message format in {@link
* java.text.MessageFormat} format, (or a key in the message * java.text.MessageFormat} format, (or a key in the message
* catalog, if this logger is a {@link * catalog, if this logger is a {@link
* LoggerFinder#getLocalizedLogger(java.lang.String, java.util.ResourceBundle, java.lang.Class) * LoggerFinder#getLocalizedLogger(java.lang.String,
* localized logger}); can be {@code null}. * java.util.ResourceBundle, java.lang.reflect.Module) localized logger});
* can be {@code null}.
* @param params an optional list of parameters to the message (may be * @param params an optional list of parameters to the message (may be
* none). * none).
* *
@ -1453,30 +1456,30 @@ public final class System {
/** /**
* Returns an instance of {@link Logger Logger} * Returns an instance of {@link Logger Logger}
* for the given {@code caller}. * for the given {@code module}.
* *
* @param name the name of the logger. * @param name the name of the logger.
* @param caller the class for which the logger is being requested. * @param module the module for which the logger is being requested.
* *
* @return a {@link Logger logger} suitable for the given caller's * @return a {@link Logger logger} suitable for use within the given
* use. * module.
* @throws NullPointerException if {@code name} is {@code null} or * @throws NullPointerException if {@code name} is {@code null} or
* {@code caller} is {@code null}. * {@code module} is {@code null}.
* @throws SecurityException if a security manager is present and its * @throws SecurityException if a security manager is present and its
* {@code checkPermission} method doesn't allow the * {@code checkPermission} method doesn't allow the
* {@code RuntimePermission("loggerFinder")}. * {@code RuntimePermission("loggerFinder")}.
*/ */
public abstract Logger getLogger(String name, /* Module */ Class<?> caller); public abstract Logger getLogger(String name, Module module);
/** /**
* Returns a localizable instance of {@link Logger Logger} * Returns a localizable instance of {@link Logger Logger}
* for the given {@code caller}. * for the given {@code module}.
* The returned logger will use the provided resource bundle for * The returned logger will use the provided resource bundle for
* message localization. * message localization.
* *
* @implSpec By default, this method calls {@link * @implSpec By default, this method calls {@link
* #getLogger(java.lang.String, java.lang.Class) * #getLogger(java.lang.String, java.lang.reflect.Module)
* this.getLogger(name, caller)} to obtain a logger, then wraps that * this.getLogger(name, module)} to obtain a logger, then wraps that
* logger in a {@link Logger} instance where all methods that do not * logger in a {@link Logger} instance where all methods that do not
* take a {@link ResourceBundle} as parameter are redirected to one * take a {@link ResourceBundle} as parameter are redirected to one
* which does - passing the given {@code bundle} for * which does - passing the given {@code bundle} for
@ -1499,19 +1502,19 @@ public final class System {
* *
* @param name the name of the logger. * @param name the name of the logger.
* @param bundle a resource bundle; can be {@code null}. * @param bundle a resource bundle; can be {@code null}.
* @param caller the class for which the logger is being requested. * @param module the module for which the logger is being requested.
* @return an instance of {@link Logger Logger} which will use the * @return an instance of {@link Logger Logger} which will use the
* provided resource bundle for message localization. * provided resource bundle for message localization.
* *
* @throws NullPointerException if {@code name} is {@code null} or * @throws NullPointerException if {@code name} is {@code null} or
* {@code caller} is {@code null}. * {@code module} is {@code null}.
* @throws SecurityException if a security manager is present and its * @throws SecurityException if a security manager is present and its
* {@code checkPermission} method doesn't allow the * {@code checkPermission} method doesn't allow the
* {@code RuntimePermission("loggerFinder")}. * {@code RuntimePermission("loggerFinder")}.
*/ */
public Logger getLocalizedLogger(String name, ResourceBundle bundle, public Logger getLocalizedLogger(String name, ResourceBundle bundle,
/* Module */ Class<?> caller) { Module module) {
return new LocalizedLoggerWrapper<>(getLogger(name, caller), bundle); return new LocalizedLoggerWrapper<>(getLogger(name, module), bundle);
} }
/** /**
@ -1558,12 +1561,13 @@ public final class System {
* *
* @implSpec * @implSpec
* Instances returned by this method route messages to loggers * Instances returned by this method route messages to loggers
* obtained by calling {@link LoggerFinder#getLogger(java.lang.String, java.lang.Class) * obtained by calling {@link LoggerFinder#getLogger(java.lang.String,
* LoggerFinder.getLogger(name, caller)}. * java.lang.reflect.Module) LoggerFinder.getLogger(name, module)}, where
* {@code module} is the caller's module.
* *
* @apiNote * @apiNote
* This method may defer calling the {@link * This method may defer calling the {@link
* LoggerFinder#getLogger(java.lang.String, java.lang.Class) * LoggerFinder#getLogger(java.lang.String, java.lang.reflect.Module)
* LoggerFinder.getLogger} method to create an actual logger supplied by * LoggerFinder.getLogger} method to create an actual logger supplied by
* the logging backend, for instance, to allow loggers to be obtained during * the logging backend, for instance, to allow loggers to be obtained during
* the system initialization time. * the system initialization time.
@ -1579,7 +1583,7 @@ public final class System {
public static Logger getLogger(String name) { public static Logger getLogger(String name) {
Objects.requireNonNull(name); Objects.requireNonNull(name);
final Class<?> caller = Reflection.getCallerClass(); final Class<?> caller = Reflection.getCallerClass();
return LazyLoggers.getLogger(name, caller); return LazyLoggers.getLogger(name, caller.getModule());
} }
/** /**
@ -1591,8 +1595,9 @@ public final class System {
* @implSpec * @implSpec
* The returned logger will perform message localization as specified * The returned logger will perform message localization as specified
* by {@link LoggerFinder#getLocalizedLogger(java.lang.String, * by {@link LoggerFinder#getLocalizedLogger(java.lang.String,
* java.util.ResourceBundle, java.lang.Class) * java.util.ResourceBundle, java.lang.reflect.Module)
* LoggerFinder.getLocalizedLogger(name, bundle, caller}. * LoggerFinder.getLocalizedLogger(name, bundle, module}, where
* {@code module} is the caller's module.
* *
* @apiNote * @apiNote
* This method is intended to be used after the system is fully initialized. * This method is intended to be used after the system is fully initialized.
@ -1624,12 +1629,14 @@ public final class System {
// Bootstrap sensitive classes in the JDK do not use resource bundles // Bootstrap sensitive classes in the JDK do not use resource bundles
// when logging. This could be revisited later, if it needs to. // when logging. This could be revisited later, if it needs to.
if (sm != null) { if (sm != null) {
return AccessController.doPrivileged((PrivilegedAction<Logger>) final PrivilegedAction<Logger> pa =
() -> LoggerFinder.accessProvider().getLocalizedLogger(name, rb, caller), () -> LoggerFinder.accessProvider()
null, .getLocalizedLogger(name, rb, caller.getModule());
return AccessController.doPrivileged(pa, null,
LoggerFinder.LOGGERFINDER_PERMISSION); LoggerFinder.LOGGERFINDER_PERMISSION);
} }
return LoggerFinder.accessProvider().getLocalizedLogger(name, rb, caller); return LoggerFinder.accessProvider()
.getLocalizedLogger(name, rb, caller.getModule());
} }
/** /**

View File

@ -33,6 +33,9 @@ import java.util.function.Function;
import java.lang.System.LoggerFinder; import java.lang.System.LoggerFinder;
import java.lang.System.Logger; import java.lang.System.Logger;
import java.lang.ref.ReferenceQueue; import java.lang.ref.ReferenceQueue;
import java.lang.reflect.Module;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collection; import java.util.Collection;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@ -129,41 +132,49 @@ public class DefaultLoggerFinder extends LoggerFinder {
return w; return w;
} }
final static SharedLoggers system = new SharedLoggers(); final static SharedLoggers system = new SharedLoggers();
final static SharedLoggers application = new SharedLoggers(); final static SharedLoggers application = new SharedLoggers();
} }
public static boolean isSystem(Module m) {
ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<>() {
@Override @Override
public final Logger getLogger(String name, /* Module */ Class<?> caller) { public ClassLoader run() {
return m.getClassLoader();
}
});
return cl == null;
}
@Override
public final Logger getLogger(String name, Module module) {
checkPermission(); checkPermission();
return demandLoggerFor(name, caller); return demandLoggerFor(name, module);
} }
@Override @Override
public final Logger getLocalizedLogger(String name, ResourceBundle bundle, public final Logger getLocalizedLogger(String name, ResourceBundle bundle,
/* Module */ Class<?> caller) { Module module) {
return super.getLocalizedLogger(name, bundle, caller); return super.getLocalizedLogger(name, bundle, module);
} }
/** /**
* Returns a {@link Logger logger} suitable for the caller usage. * Returns a {@link Logger logger} suitable for use within the
* given {@code module}.
* *
* @implSpec The default implementation for this method is to return a * @implSpec The default implementation for this method is to return a
* simple logger that will print all messages of INFO level and above * simple logger that will print all messages of INFO level and above
* to the console. That simple logger is not configurable. * to the console. That simple logger is not configurable.
* *
* @param name The name of the logger. * @param name The name of the logger.
* @param caller The class on behalf of which the logger is created. * @param module The module on behalf of which the logger is created.
* @return A {@link Logger logger} suitable for the application usage. * @return A {@link Logger logger} suitable for the application usage.
* @throws SecurityException if the calling code does not have the * @throws SecurityException if the calling code does not have the
* {@code RuntimePermission("loggerFinder")}. * {@code RuntimePermission("loggerFinder")}.
*/ */
protected Logger demandLoggerFor(String name, /* Module */ Class<?> caller) { protected Logger demandLoggerFor(String name, Module module) {
checkPermission(); checkPermission();
if (caller.getClassLoader() == null) { if (isSystem(module)) {
return SharedLoggers.system.get(SimpleConsoleLogger::makeSimpleLogger, name); return SharedLoggers.system.get(SimpleConsoleLogger::makeSimpleLogger, name);
} else { } else {
return SharedLoggers.application.get(SimpleConsoleLogger::makeSimpleLogger, name); return SharedLoggers.application.get(SimpleConsoleLogger::makeSimpleLogger, name);

View File

@ -31,6 +31,7 @@ import java.util.function.BiFunction;
import java.lang.System.LoggerFinder; import java.lang.System.LoggerFinder;
import java.lang.System.Logger; import java.lang.System.Logger;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.lang.reflect.Module;
import java.util.Objects; import java.util.Objects;
import jdk.internal.misc.VM; import jdk.internal.misc.VM;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
@ -59,15 +60,15 @@ public final class LazyLoggers {
* A factory method to create an SPI logger. * A factory method to create an SPI logger.
* Usually, this will be something like LazyLoggers::getSystemLogger. * Usually, this will be something like LazyLoggers::getSystemLogger.
*/ */
final BiFunction<String, Class<?>, L> loggerSupplier; final BiFunction<String, Module, L> loggerSupplier;
public LazyLoggerFactories(BiFunction<String, Class<?>, L> loggerSupplier) { public LazyLoggerFactories(BiFunction<String, Module, L> loggerSupplier) {
this(Objects.requireNonNull(loggerSupplier), this(Objects.requireNonNull(loggerSupplier),
(Void)null); (Void)null);
} }
private LazyLoggerFactories(BiFunction<String, Class<?>, L> loggerSupplier, private LazyLoggerFactories(BiFunction<String, Module, L> loggerSupplier,
Void unused) { Void unused) {
this.loggerSupplier = loggerSupplier; this.loggerSupplier = loggerSupplier;
} }
@ -107,8 +108,8 @@ public final class LazyLoggers {
// The factories that will be used to create the logger lazyly // The factories that will be used to create the logger lazyly
final LazyLoggerFactories<? extends Logger> factories; final LazyLoggerFactories<? extends Logger> factories;
// We need to pass the actual caller when creating the logger. // We need to pass the actual caller module when creating the logger.
private final WeakReference<Class<?>> callerRef; private final WeakReference<Module> moduleRef;
// The name of the logger that will be created lazyly // The name of the logger that will be created lazyly
final String name; final String name;
@ -121,17 +122,17 @@ public final class LazyLoggers {
private LazyLoggerAccessor(String name, private LazyLoggerAccessor(String name,
LazyLoggerFactories<? extends Logger> factories, LazyLoggerFactories<? extends Logger> factories,
Class<?> caller) { Module module) {
this(Objects.requireNonNull(name), Objects.requireNonNull(factories), this(Objects.requireNonNull(name), Objects.requireNonNull(factories),
Objects.requireNonNull(caller), null); Objects.requireNonNull(module), null);
} }
private LazyLoggerAccessor(String name, private LazyLoggerAccessor(String name,
LazyLoggerFactories<? extends Logger> factories, LazyLoggerFactories<? extends Logger> factories,
Class<?> caller, Void unused) { Module module, Void unused) {
this.name = name; this.name = name;
this.factories = factories; this.factories = factories;
this.callerRef = new WeakReference<Class<?>>(caller); this.moduleRef = new WeakReference<>(module);
} }
/** /**
@ -270,12 +271,12 @@ public final class LazyLoggers {
// Creates the wrapped logger by invoking the SPI. // Creates the wrapped logger by invoking the SPI.
Logger createLogger() { Logger createLogger() {
final Class<?> caller = callerRef.get(); final Module module = moduleRef.get();
if (caller == null) { if (module == null) {
throw new IllegalStateException("The class for which this logger" throw new IllegalStateException("The module for which this logger"
+ " was created has been garbage collected"); + " was created has been garbage collected");
} }
return this.factories.loggerSupplier.apply(name, caller); return this.factories.loggerSupplier.apply(name, module);
} }
/** /**
@ -289,8 +290,8 @@ public final class LazyLoggers {
* @return A new LazyLoggerAccessor. * @return A new LazyLoggerAccessor.
*/ */
public static LazyLoggerAccessor makeAccessor(String name, public static LazyLoggerAccessor makeAccessor(String name,
LazyLoggerFactories<? extends Logger> factories, Class<?> caller) { LazyLoggerFactories<? extends Logger> factories, Module module) {
return new LazyLoggerAccessor(name, factories, caller); return new LazyLoggerAccessor(name, factories, module);
} }
} }
@ -346,11 +347,11 @@ public final class LazyLoggers {
// Avoid using lambda here as lazy loggers could be created early // Avoid using lambda here as lazy loggers could be created early
// in the bootstrap sequence... // in the bootstrap sequence...
private static final BiFunction<String, Class<?>, Logger> loggerSupplier = private static final BiFunction<String, Module, Logger> loggerSupplier =
new BiFunction<>() { new BiFunction<>() {
@Override @Override
public Logger apply(String name, Class<?> caller) { public Logger apply(String name, Module module) {
return LazyLoggers.getLoggerFromFinder(name, caller); return LazyLoggers.getLoggerFromFinder(name, module);
} }
}; };
@ -367,8 +368,8 @@ public final class LazyLoggers {
// logger provider until the VM has finished booting. // logger provider until the VM has finished booting.
// //
private static final class JdkLazyLogger extends LazyLoggerWrapper { private static final class JdkLazyLogger extends LazyLoggerWrapper {
JdkLazyLogger(String name, Class<?> caller) { JdkLazyLogger(String name, Module module) {
this(LazyLoggerAccessor.makeAccessor(name, factories, caller), this(LazyLoggerAccessor.makeAccessor(name, factories, module),
(Void)null); (Void)null);
} }
private JdkLazyLogger(LazyLoggerAccessor holder, Void unused) { private JdkLazyLogger(LazyLoggerAccessor holder, Void unused) {
@ -380,16 +381,16 @@ public final class LazyLoggers {
* Gets a logger from the LoggerFinder. Creates the actual concrete * Gets a logger from the LoggerFinder. Creates the actual concrete
* logger. * logger.
* @param name name of the logger * @param name name of the logger
* @param caller class on behalf of which the logger is created * @param module module on behalf of which the logger is created
* @return The logger returned by the LoggerFinder. * @return The logger returned by the LoggerFinder.
*/ */
static Logger getLoggerFromFinder(String name, Class<?> caller) { static Logger getLoggerFromFinder(String name, Module module) {
final SecurityManager sm = System.getSecurityManager(); final SecurityManager sm = System.getSecurityManager();
if (sm == null) { if (sm == null) {
return accessLoggerFinder().getLogger(name, caller); return accessLoggerFinder().getLogger(name, module);
} else { } else {
return AccessController.doPrivileged((PrivilegedAction<Logger>) return AccessController.doPrivileged((PrivilegedAction<Logger>)
() -> {return accessLoggerFinder().getLogger(name, caller);}, () -> {return accessLoggerFinder().getLogger(name, module);},
null, LOGGERFINDER_PERMISSION); null, LOGGERFINDER_PERMISSION);
} }
} }
@ -398,22 +399,22 @@ public final class LazyLoggers {
* Returns a (possibly lazy) Logger for the caller. * Returns a (possibly lazy) Logger for the caller.
* *
* @param name the logger name * @param name the logger name
* @param caller The class on behalf of which the logger is created. * @param module The module on behalf of which the logger is created.
* If the caller is not loaded from the Boot ClassLoader, * If the module is not loaded from the Boot ClassLoader,
* the LoggerFinder is accessed and the logger returned * the LoggerFinder is accessed and the logger returned
* by {@link LoggerFinder#getLogger(java.lang.String, java.lang.Class)} * by {@link LoggerFinder#getLogger(java.lang.String, java.lang.reflect.Module)}
* is returned to the caller directly. * is returned to the caller directly.
* Otherwise, the logger returned by * Otherwise, the logger returned by
* {@link #getLazyLogger(java.lang.String, java.lang.Class)} * {@link #getLazyLogger(java.lang.String, java.lang.reflect.Module)}
* is returned to the caller. * is returned to the caller.
* *
* @return a (possibly lazy) Logger instance. * @return a (possibly lazy) Logger instance.
*/ */
public static final Logger getLogger(String name, Class<?> caller) { public static final Logger getLogger(String name, Module module) {
if (caller.getClassLoader() == null) { if (DefaultLoggerFinder.isSystem(module)) {
return getLazyLogger(name, caller); return getLazyLogger(name, module);
} else { } else {
return getLoggerFromFinder(name, caller); return getLoggerFromFinder(name, module);
} }
} }
@ -423,10 +424,10 @@ public final class LazyLoggers {
* returned by {@link BootstrapLogger#useLazyLoggers()}. * returned by {@link BootstrapLogger#useLazyLoggers()}.
* *
* @param name the logger name * @param name the logger name
* @param caller the class on behalf of which the logger is created. * @param module the module on behalf of which the logger is created.
* @return a (possibly lazy) Logger instance. * @return a (possibly lazy) Logger instance.
*/ */
public static final Logger getLazyLogger(String name, Class<?> caller) { public static final Logger getLazyLogger(String name, Module module) {
// BootstrapLogger has the logic to determine whether a LazyLogger // BootstrapLogger has the logic to determine whether a LazyLogger
// should be used. Usually, it is worth it only if: // should be used. Usually, it is worth it only if:
@ -438,10 +439,10 @@ public final class LazyLoggers {
// configuration, we're not going to delay the creation of loggers... // configuration, we're not going to delay the creation of loggers...
final boolean useLazyLogger = BootstrapLogger.useLazyLoggers(); final boolean useLazyLogger = BootstrapLogger.useLazyLoggers();
if (useLazyLogger) { if (useLazyLogger) {
return new JdkLazyLogger(name, caller); return new JdkLazyLogger(name, module);
} else { } else {
// Directly invoke the LoggerFinder. // Directly invoke the LoggerFinder.
return getLoggerFromFinder(name, caller); return getLoggerFromFinder(name, module);
} }
} }

View File

@ -286,12 +286,15 @@ public class PlatformLogger {
} }
if (log == null) { if (log == null) {
log = new PlatformLogger(PlatformLogger.Bridge.convert( log = new PlatformLogger(PlatformLogger.Bridge.convert(
// We pass PlatformLogger.class rather than the actual caller // We pass PlatformLogger.class.getModule() (java.base)
// rather than the actual module of the caller
// because we want PlatformLoggers to be system loggers: we // because we want PlatformLoggers to be system loggers: we
// won't need to resolve any resource bundles anyway. // won't need to resolve any resource bundles anyway.
// Note: Many unit tests depend on the fact that // Note: Many unit tests depend on the fact that
// PlatformLogger.getLoggerFromFinder is not caller sensitive. // PlatformLogger.getLoggerFromFinder is not caller
LazyLoggers.getLazyLogger(name, PlatformLogger.class))); // sensitive, and this strategy ensure that the tests
// still pass.
LazyLoggers.getLazyLogger(name, PlatformLogger.class.getModule())));
loggers.put(name, new WeakReference<>(log)); loggers.put(name, new WeakReference<>(log));
} }
return log; return log;

View File

@ -43,6 +43,8 @@ import java.util.stream.Stream;
import jdk.internal.misc.JavaAWTAccess; import jdk.internal.misc.JavaAWTAccess;
import jdk.internal.misc.SharedSecrets; import jdk.internal.misc.SharedSecrets;
import sun.util.logging.internal.LoggingProviderImpl; import sun.util.logging.internal.LoggingProviderImpl;
import java.lang.reflect.Module;
import static jdk.internal.logger.DefaultLoggerFinder.isSystem;
/** /**
* There is a single global LogManager object that is used to * There is a single global LogManager object that is used to
@ -503,10 +505,16 @@ public class LogManager {
// as a LogManager subclass may override the addLogger, getLogger, // as a LogManager subclass may override the addLogger, getLogger,
// readConfiguration, and other methods. // readConfiguration, and other methods.
Logger demandLogger(String name, String resourceBundleName, Class<?> caller) { Logger demandLogger(String name, String resourceBundleName, Class<?> caller) {
final Module module = caller == null ? null : caller.getModule();
return demandLogger(name, resourceBundleName, module);
}
Logger demandLogger(String name, String resourceBundleName, Module module) {
Logger result = getLogger(name); Logger result = getLogger(name);
if (result == null) { if (result == null) {
// only allocate the new logger once // only allocate the new logger once
Logger newLogger = new Logger(name, resourceBundleName, caller, this, false); Logger newLogger = new Logger(name, resourceBundleName,
module == null ? null : module, this, false);
do { do {
if (addLogger(newLogger)) { if (addLogger(newLogger)) {
// We successfully added the new Logger that we // We successfully added the new Logger that we
@ -532,9 +540,14 @@ public class LogManager {
} }
Logger demandSystemLogger(String name, String resourceBundleName, Class<?> caller) { Logger demandSystemLogger(String name, String resourceBundleName, Class<?> caller) {
final Module module = caller == null ? null : caller.getModule();
return demandSystemLogger(name, resourceBundleName, module);
}
Logger demandSystemLogger(String name, String resourceBundleName, Module module) {
// Add a system logger in the system context's namespace // Add a system logger in the system context's namespace
final Logger sysLogger = getSystemContext() final Logger sysLogger = getSystemContext()
.demandLogger(name, resourceBundleName, caller); .demandLogger(name, resourceBundleName, module);
// Add the system logger to the LogManager's namespace if not exist // Add the system logger to the LogManager's namespace if not exist
// so that there is only one single logger of the given name. // so that there is only one single logger of the given name.
@ -619,11 +632,11 @@ public class LogManager {
return global; return global;
} }
Logger demandLogger(String name, String resourceBundleName, Class<?> caller) { Logger demandLogger(String name, String resourceBundleName, Module module) {
// a LogManager subclass may have its own implementation to add and // a LogManager subclass may have its own implementation to add and
// get a Logger. So delegate to the LogManager to do the work. // get a Logger. So delegate to the LogManager to do the work.
final LogManager owner = getOwner(); final LogManager owner = getOwner();
return owner.demandLogger(name, resourceBundleName, caller); return owner.demandLogger(name, resourceBundleName, module);
} }
@ -907,11 +920,13 @@ public class LogManager {
// one single logger of the given name. System loggers are visible // one single logger of the given name. System loggers are visible
// to applications unless a logger of the same name has been added. // to applications unless a logger of the same name has been added.
@Override @Override
Logger demandLogger(String name, String resourceBundleName, Class<?> caller) { Logger demandLogger(String name, String resourceBundleName,
Module module) {
Logger result = findLogger(name); Logger result = findLogger(name);
if (result == null) { if (result == null) {
// only allocate the new system logger once // only allocate the new system logger once
Logger newLogger = new Logger(name, resourceBundleName, caller, getOwner(), true); Logger newLogger = new Logger(name, resourceBundleName,
module, getOwner(), true);
do { do {
if (addLocalLogger(newLogger)) { if (addLocalLogger(newLogger)) {
// We successfully added the new Logger that we // We successfully added the new Logger that we
@ -2622,18 +2637,18 @@ public class LogManager {
} }
/** /**
* Demands a logger on behalf of the given {@code caller}. * Demands a logger on behalf of the given {@code module}.
* <p> * <p>
* If a named logger suitable for the given caller is found * If a named logger suitable for the given module is found
* returns it. * returns it.
* Otherwise, creates a new logger suitable for the given caller. * Otherwise, creates a new logger suitable for the given module.
* *
* @param name The logger name. * @param name The logger name.
* @param caller The caller on which behalf the logger is created/retrieved. * @param module The module on which behalf the logger is created/retrieved.
* @return A logger for the given {@code caller}. * @return A logger for the given {@code module}.
* *
* @throws NullPointerException if {@code name} is {@code null} * @throws NullPointerException if {@code name} is {@code null}
* or {@code caller} is {@code null}. * or {@code module} is {@code null}.
* @throws IllegalArgumentException if {@code manager} is not the default * @throws IllegalArgumentException if {@code manager} is not the default
* LogManager. * LogManager.
* @throws SecurityException if a security manager is present and the * @throws SecurityException if a security manager is present and the
@ -2641,7 +2656,7 @@ public class LogManager {
* {@link LoggingPermission LoggingPermission("demandLogger", null)}. * {@link LoggingPermission LoggingPermission("demandLogger", null)}.
*/ */
@Override @Override
public Logger demandLoggerFor(LogManager manager, String name, /* Module */ Class<?> caller) { public Logger demandLoggerFor(LogManager manager, String name, Module module) {
if (manager != getLogManager()) { if (manager != getLogManager()) {
// having LogManager as parameter just ensures that the // having LogManager as parameter just ensures that the
// caller will have initialized the LogManager before reaching // caller will have initialized the LogManager before reaching
@ -2649,15 +2664,16 @@ public class LogManager {
throw new IllegalArgumentException("manager"); throw new IllegalArgumentException("manager");
} }
Objects.requireNonNull(name); Objects.requireNonNull(name);
Objects.requireNonNull(module);
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) { if (sm != null) {
sm.checkPermission(controlPermission); sm.checkPermission(controlPermission);
} }
if (caller.getClassLoader() == null) { if (isSystem(module)) {
return manager.demandSystemLogger(name, return manager.demandSystemLogger(name,
Logger.SYSTEM_LOGGER_RB_NAME, caller); Logger.SYSTEM_LOGGER_RB_NAME, module);
} else { } else {
return manager.demandLogger(name, null, caller); return manager.demandLogger(name, null, module);
} }
} }

View File

@ -40,6 +40,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Supplier; import java.util.function.Supplier;
import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.CallerSensitive;
import jdk.internal.reflect.Reflection; import jdk.internal.reflect.Reflection;
import static jdk.internal.logger.DefaultLoggerFinder.isSystem;
/** /**
* A Logger object is used to log messages for a specific * A Logger object is used to log messages for a specific
@ -379,7 +380,8 @@ public class Logger {
this(name, resourceBundleName, null, LogManager.getLogManager(), false); this(name, resourceBundleName, null, LogManager.getLogManager(), false);
} }
Logger(String name, String resourceBundleName, Class<?> caller, LogManager manager, boolean isSystemLogger) { Logger(String name, String resourceBundleName, Module caller,
LogManager manager, boolean isSystemLogger) {
this.manager = manager; this.manager = manager;
this.isSystemLogger = isSystemLogger; this.isSystemLogger = isSystemLogger;
setupResourceInfo(resourceBundleName, caller); setupResourceInfo(resourceBundleName, caller);
@ -387,10 +389,7 @@ public class Logger {
levelValue = Level.INFO.intValue(); levelValue = Level.INFO.intValue();
} }
private void setCallerModuleRef(Class<?> caller) { private void setCallerModuleRef(Module callerModule) {
Module callerModule = ((caller != null)
? caller.getModule()
: null);
if (callerModule != null) { if (callerModule != null) {
this.callerModuleRef = new WeakReference<>(callerModule); this.callerModuleRef = new WeakReference<>(callerModule);
} }
@ -618,7 +617,7 @@ public class Logger {
// all loggers in the system context will default to // all loggers in the system context will default to
// the system logger's resource bundle - therefore the caller won't // the system logger's resource bundle - therefore the caller won't
// be needed and can be null. // be needed and can be null.
Logger result = manager.demandSystemLogger(name, SYSTEM_LOGGER_RB_NAME, null); Logger result = manager.demandSystemLogger(name, SYSTEM_LOGGER_RB_NAME, (Module)null);
return result; return result;
} }
@ -681,8 +680,10 @@ public class Logger {
LogManager manager = LogManager.getLogManager(); LogManager manager = LogManager.getLogManager();
// cleanup some Loggers that have been GC'ed // cleanup some Loggers that have been GC'ed
manager.drainLoggerRefQueueBounded(); manager.drainLoggerRefQueueBounded();
final Class<?> callerClass = Reflection.getCallerClass();
final Module module = callerClass.getModule();
Logger result = new Logger(null, resourceBundleName, Logger result = new Logger(null, resourceBundleName,
Reflection.getCallerClass(), manager, false); module, manager, false);
result.anonymous = true; result.anonymous = true;
Logger root = manager.getLogger(""); Logger root = manager.getLogger("");
result.doSetParent(root); result.doSetParent(root);
@ -2046,6 +2047,11 @@ public class Logger {
} }
} }
private void setupResourceInfo(String name, Class<?> caller) {
final Module module = caller == null ? null : caller.getModule();
setupResourceInfo(name, module);
}
// Private utility method to initialize our one entry // Private utility method to initialize our one entry
// resource bundle name cache and the callers Module // resource bundle name cache and the callers Module
// Note: for consistency reasons, we are careful to check // Note: for consistency reasons, we are careful to check
@ -2053,7 +2059,7 @@ public class Logger {
// resourceBundleName field. // resourceBundleName field.
// Synchronized to prevent races in setting the fields. // Synchronized to prevent races in setting the fields.
private synchronized void setupResourceInfo(String name, private synchronized void setupResourceInfo(String name,
Class<?> callerClass) { Module callerModule) {
final LoggerBundle lb = loggerBundle; final LoggerBundle lb = loggerBundle;
if (lb.resourceBundleName != null) { if (lb.resourceBundleName != null) {
// this Logger already has a ResourceBundle // this Logger already has a ResourceBundle
@ -2072,8 +2078,9 @@ public class Logger {
return; return;
} }
setCallerModuleRef(callerClass); setCallerModuleRef(callerModule);
if (isSystemLogger && (callerClass != null && callerClass.getClassLoader() != null)) {
if (isSystemLogger && (callerModule != null && !isSystem(callerModule))) {
checkPermission(); checkPermission();
} }

View File

@ -32,6 +32,7 @@ import java.util.ResourceBundle;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.lang.System.LoggerFinder; import java.lang.System.LoggerFinder;
import java.lang.System.Logger; import java.lang.System.Logger;
import java.lang.reflect.Module;
import java.util.Objects; import java.util.Objects;
import java.util.logging.LogManager; import java.util.logging.LogManager;
import jdk.internal.logger.DefaultLoggerFinder; import jdk.internal.logger.DefaultLoggerFinder;
@ -398,21 +399,20 @@ public final class LoggingProviderImpl extends DefaultLoggerFinder {
} }
/** /**
* Creates a java.util.logging.Logger for the given caller. * Creates a java.util.logging.Logger for the given module.
* @param name the logger name. * @param name the logger name.
* @param caller the caller for which the logger should be created. * @param module the module for which the logger should be created.
* @return a Logger suitable for use in the given caller. * @return a Logger suitable for use in the given module.
*/ */
private static java.util.logging.Logger demandJULLoggerFor(final String name, private static java.util.logging.Logger demandJULLoggerFor(final String name,
/* Module */ Module module) {
final Class<?> caller) {
final LogManager manager = LogManager.getLogManager(); final LogManager manager = LogManager.getLogManager();
final SecurityManager sm = System.getSecurityManager(); final SecurityManager sm = System.getSecurityManager();
if (sm == null) { if (sm == null) {
return logManagerAccess.demandLoggerFor(manager, name, caller); return logManagerAccess.demandLoggerFor(manager, name, module);
} else { } else {
final PrivilegedAction<java.util.logging.Logger> pa = final PrivilegedAction<java.util.logging.Logger> pa =
() -> logManagerAccess.demandLoggerFor(manager, name, caller); () -> logManagerAccess.demandLoggerFor(manager, name, module);
return AccessController.doPrivileged(pa, null, LOGGING_CONTROL_PERMISSION); return AccessController.doPrivileged(pa, null, LOGGING_CONTROL_PERMISSION);
} }
} }
@ -429,17 +429,17 @@ public final class LoggingProviderImpl extends DefaultLoggerFinder {
* {@code RuntimePermission("loggerFinder")}. * {@code RuntimePermission("loggerFinder")}.
*/ */
@Override @Override
protected Logger demandLoggerFor(String name, /* Module */ Class<?> caller) { protected Logger demandLoggerFor(String name, Module module) {
final SecurityManager sm = System.getSecurityManager(); final SecurityManager sm = System.getSecurityManager();
if (sm != null) { if (sm != null) {
sm.checkPermission(LOGGERFINDER_PERMISSION); sm.checkPermission(LOGGERFINDER_PERMISSION);
} }
return JULWrapper.of(demandJULLoggerFor(name,caller)); return JULWrapper.of(demandJULLoggerFor(name,module));
} }
public static interface LogManagerAccess { public static interface LogManagerAccess {
java.util.logging.Logger demandLoggerFor(LogManager manager, java.util.logging.Logger demandLoggerFor(LogManager manager,
String name, /* Module */ Class<?> caller); String name, Module module);
} }
// Hook for tests // Hook for tests

View File

@ -46,6 +46,8 @@ import java.lang.System.LoggerFinder;
import java.lang.System.Logger; import java.lang.System.Logger;
import java.lang.System.Logger.Level; import java.lang.System.Logger.Level;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.lang.reflect.Module;
import java.security.AllPermission;
/** /**
* @test * @test
@ -70,6 +72,12 @@ public class CustomLoggerTest {
return new AtomicBoolean(false); return new AtomicBoolean(false);
} }
}; };
static final ThreadLocal<AtomicBoolean> allowAll = new ThreadLocal<AtomicBoolean>() {
@Override
protected AtomicBoolean initialValue() {
return new AtomicBoolean(false);
}
};
public static class MyBundle extends ResourceBundle { public static class MyBundle extends ResourceBundle {
@ -241,7 +249,7 @@ public class CustomLoggerTest {
} }
@Override @Override
public Logger getLogger(String name, Class<?> caller) { public Logger getLogger(String name, Module caller) {
// We should check the permission to obey the API contract, but // We should check the permission to obey the API contract, but
// what happens if we don't? // what happens if we don't?
// This is the main difference compared with what we test in // This is the main difference compared with what we test in
@ -251,8 +259,13 @@ public class CustomLoggerTest {
sm.checkPermission(SimplePolicy.LOGGERFINDER_PERMISSION); sm.checkPermission(SimplePolicy.LOGGERFINDER_PERMISSION);
} }
PrivilegedAction<ClassLoader> pa = () -> caller.getClassLoader(); final boolean before = allowAll.get().getAndSet(true);
ClassLoader callerLoader = AccessController.doPrivileged(pa); final ClassLoader callerLoader;
try {
callerLoader = caller.getClassLoader();
} finally {
allowAll.get().set(before);
}
if (callerLoader == null) { if (callerLoader == null) {
return system.computeIfAbsent(name, (n) -> new LoggerImpl(n)); return system.computeIfAbsent(name, (n) -> new LoggerImpl(n));
} else { } else {
@ -267,7 +280,7 @@ public class CustomLoggerTest {
static void setSecurityManager() { static void setSecurityManager() {
if (System.getSecurityManager() == null) { if (System.getSecurityManager() == null) {
Policy.setPolicy(new SimplePolicy(allowControl)); Policy.setPolicy(new SimplePolicy(allowControl, allowAll));
System.setSecurityManager(new SecurityManager()); System.setSecurityManager(new SecurityManager());
} }
} }
@ -284,9 +297,9 @@ public class CustomLoggerTest {
BaseLoggerFinder provider = BaseLoggerFinder provider =
BaseLoggerFinder.class.cast(LoggerFinder.getLoggerFinder()); BaseLoggerFinder.class.cast(LoggerFinder.getLoggerFinder());
BaseLoggerFinder.LoggerImpl appSink = BaseLoggerFinder.LoggerImpl appSink =
BaseLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", CustomLoggerTest.class)); BaseLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", CustomLoggerTest.class.getModule()));
BaseLoggerFinder.LoggerImpl sysSink = BaseLoggerFinder.LoggerImpl sysSink =
BaseLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", Thread.class)); BaseLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", Thread.class.getModule()));
Stream.of(args).map(TestCases::valueOf).forEach((testCase) -> { Stream.of(args).map(TestCases::valueOf).forEach((testCase) -> {
@ -695,34 +708,46 @@ public class CustomLoggerTest {
static final RuntimePermission LOGGERFINDER_PERMISSION = static final RuntimePermission LOGGERFINDER_PERMISSION =
new RuntimePermission("loggerFinder"); new RuntimePermission("loggerFinder");
final Permissions permissions; final Permissions permissions;
final Permissions controlPermissions;
final Permissions allPermissions; final Permissions allPermissions;
final ThreadLocal<AtomicBoolean> allowControl; final ThreadLocal<AtomicBoolean> allowControl;
public SimplePolicy(ThreadLocal<AtomicBoolean> allowControl) { final ThreadLocal<AtomicBoolean> allowAll;
public SimplePolicy(ThreadLocal<AtomicBoolean> allowControl, ThreadLocal<AtomicBoolean> allowAll) {
this.allowControl = allowControl; this.allowControl = allowControl;
this.allowAll = allowAll;
permissions = new Permissions(); permissions = new Permissions();
// these are used for configuring the test itself... // these are used for configuring the test itself...
controlPermissions = new Permissions();
controlPermissions.add(LOGGERFINDER_PERMISSION);
// these are used for simulating a doPrivileged call from
// a class in the BCL
allPermissions = new Permissions(); allPermissions = new Permissions();
allPermissions.add(LOGGERFINDER_PERMISSION); allPermissions.add(new AllPermission());
}
Permissions permissions() {
if (allowAll.get().get()) return allPermissions;
if (allowControl.get().get()) return controlPermissions;
return permissions;
} }
@Override @Override
public boolean implies(ProtectionDomain domain, Permission permission) { public boolean implies(ProtectionDomain domain, Permission permission) {
if (allowControl.get().get()) return allPermissions.implies(permission); return permissions().implies(permission);
return permissions.implies(permission);
} }
@Override @Override
public PermissionCollection getPermissions(CodeSource codesource) { public PermissionCollection getPermissions(CodeSource codesource) {
return new PermissionsBuilder().addAll(allowControl.get().get() return new PermissionsBuilder().addAll(permissions()).toPermissions();
? allPermissions : permissions).toPermissions();
} }
@Override @Override
public PermissionCollection getPermissions(ProtectionDomain domain) { public PermissionCollection getPermissions(ProtectionDomain domain) {
return new PermissionsBuilder().addAll(allowControl.get().get() return new PermissionsBuilder().addAll(permissions()).toPermissions();
? allPermissions : permissions).toPermissions();
} }
} }
} }

View File

@ -25,13 +25,14 @@ import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.lang.System.LoggerFinder; import java.lang.System.LoggerFinder;
import java.lang.System.Logger; import java.lang.System.Logger;
import java.lang.reflect.Module;
public class BaseLoggerFinder extends LoggerFinder implements TestLoggerFinder { public class BaseLoggerFinder extends LoggerFinder implements TestLoggerFinder {
static final RuntimePermission LOGGERFINDER_PERMISSION = static final RuntimePermission LOGGERFINDER_PERMISSION =
new RuntimePermission("loggerFinder"); new RuntimePermission("loggerFinder");
@Override @Override
public Logger getLogger(String name, Class<?> caller) { public Logger getLogger(String name, Module caller) {
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) { if (sm != null) {
sm.checkPermission(LOGGERFINDER_PERMISSION); sm.checkPermission(LOGGERFINDER_PERMISSION);

View File

@ -182,8 +182,8 @@ public class BaseLoggerFinderTest {
TestLoggerFinder.LoggerImpl appLogger1 = null; TestLoggerFinder.LoggerImpl appLogger1 = null;
try { try {
appLogger1 = appLogger1 =
TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", BaseLoggerFinderTest.class)); TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", BaseLoggerFinderTest.class.getModule()));
loggerDescMap.put(appLogger1, "provider.getLogger(\"foo\", BaseLoggerFinderTest.class)"); loggerDescMap.put(appLogger1, "provider.getLogger(\"foo\", BaseLoggerFinderTest.class.getModule())");
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
throw new RuntimeException("Managed to obtain a logger without permission"); throw new RuntimeException("Managed to obtain a logger without permission");
} }
@ -199,8 +199,8 @@ public class BaseLoggerFinderTest {
allowControl.get().set(true); allowControl.get().set(true);
try { try {
appLogger1 = appLogger1 =
TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", BaseLoggerFinderTest.class)); TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", BaseLoggerFinderTest.class.getModule()));
loggerDescMap.put(appLogger1, "provider.getLogger(\"foo\", BaseLoggerFinderTest.class)"); loggerDescMap.put(appLogger1, "provider.getLogger(\"foo\", BaseLoggerFinderTest.class.getModule())");
} finally { } finally {
allowControl.get().set(old); allowControl.get().set(old);
} }
@ -208,8 +208,8 @@ public class BaseLoggerFinderTest {
TestLoggerFinder.LoggerImpl sysLogger1 = null; TestLoggerFinder.LoggerImpl sysLogger1 = null;
try { try {
sysLogger1 = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", Thread.class)); sysLogger1 = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", Thread.class.getModule()));
loggerDescMap.put(sysLogger1, "provider.getLogger(\"foo\", Thread.class)"); loggerDescMap.put(sysLogger1, "provider.getLogger(\"foo\", Thread.class.getModule())");
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
throw new RuntimeException("Managed to obtain a system logger without permission"); throw new RuntimeException("Managed to obtain a system logger without permission");
} }
@ -224,8 +224,8 @@ public class BaseLoggerFinderTest {
final boolean old = allowControl.get().get(); final boolean old = allowControl.get().get();
allowControl.get().set(true); allowControl.get().set(true);
try { try {
sysLogger1 = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", Thread.class)); sysLogger1 = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", Thread.class.getModule()));
loggerDescMap.put(sysLogger1, "provider.getLogger(\"foo\", Thread.class)"); loggerDescMap.put(sysLogger1, "provider.getLogger(\"foo\", Thread.class.getModule())");
} finally { } finally {
allowControl.get().set(old); allowControl.get().set(old);
} }
@ -254,8 +254,8 @@ public class BaseLoggerFinderTest {
// callers and non system callers // callers and non system callers
Logger appLogger2 = null; Logger appLogger2 = null;
try { try {
appLogger2 = provider.getLocalizedLogger("foo", loggerBundle, BaseLoggerFinderTest.class); appLogger2 = provider.getLocalizedLogger("foo", loggerBundle, BaseLoggerFinderTest.class.getModule());
loggerDescMap.put(appLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, BaseLoggerFinderTest.class)"); loggerDescMap.put(appLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, BaseLoggerFinderTest.class.getModule())");
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
throw new RuntimeException("Managed to obtain a logger without permission"); throw new RuntimeException("Managed to obtain a logger without permission");
} }
@ -270,8 +270,8 @@ public class BaseLoggerFinderTest {
final boolean old = allowControl.get().get(); final boolean old = allowControl.get().get();
allowControl.get().set(true); allowControl.get().set(true);
try { try {
appLogger2 = provider.getLocalizedLogger("foo", loggerBundle, BaseLoggerFinderTest.class); appLogger2 = provider.getLocalizedLogger("foo", loggerBundle, BaseLoggerFinderTest.class.getModule());
loggerDescMap.put(appLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, BaseLoggerFinderTest.class)"); loggerDescMap.put(appLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, BaseLoggerFinderTest.class.getModule())");
} finally { } finally {
allowControl.get().set(old); allowControl.get().set(old);
} }
@ -279,8 +279,8 @@ public class BaseLoggerFinderTest {
Logger sysLogger2 = null; Logger sysLogger2 = null;
try { try {
sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class); sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class.getModule());
loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class)"); loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class.getModule())");
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
throw new RuntimeException("Managed to obtain a system logger without permission"); throw new RuntimeException("Managed to obtain a system logger without permission");
} }
@ -295,8 +295,8 @@ public class BaseLoggerFinderTest {
final boolean old = allowControl.get().get(); final boolean old = allowControl.get().get();
allowControl.get().set(true); allowControl.get().set(true);
try { try {
sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class); sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class.getModule());
loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class))"); loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class.getModule()))");
} finally { } finally {
allowControl.get().set(old); allowControl.get().set(old);
} }

View File

@ -30,6 +30,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.lang.System.Logger; import java.lang.System.Logger;
import java.lang.reflect.Module;
/** /**
* What our test provider needs to implement. * What our test provider needs to implement.
@ -176,6 +177,6 @@ public interface TestLoggerFinder {
} }
} }
public Logger getLogger(String name, Class<?> caller); public Logger getLogger(String name, Module caller);
public Logger getLocalizedLogger(String name, ResourceBundle bundle, Class<?> caller); public Logger getLocalizedLogger(String name, ResourceBundle bundle, Module caller);
} }

View File

@ -364,8 +364,8 @@ public class DefaultLoggerFinderTest {
Logger appLogger1 = null; Logger appLogger1 = null;
try { try {
appLogger1 = provider.getLogger("foo", DefaultLoggerFinderTest.class); appLogger1 = provider.getLogger("foo", DefaultLoggerFinderTest.class.getModule());
loggerDescMap.put(appLogger1, "provider.getApplicationLogger(\"foo\")"); loggerDescMap.put(appLogger1, "provider.getLogger(\"foo\", DefaultLoggerFinderTest.class.getModule())");
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
throw new RuntimeException("Managed to obtain a logger without permission"); throw new RuntimeException("Managed to obtain a logger without permission");
} }
@ -380,8 +380,8 @@ public class DefaultLoggerFinderTest {
boolean old = allowControl.get().get(); boolean old = allowControl.get().get();
allowControl.get().set(true); allowControl.get().set(true);
try { try {
appLogger1 =provider.getLogger("foo", DefaultLoggerFinderTest.class); appLogger1 =provider.getLogger("foo", DefaultLoggerFinderTest.class.getModule());
loggerDescMap.put(appLogger1, "provider.getApplicationLogger(\"foo\")"); loggerDescMap.put(appLogger1, "provider.getLogger(\"foo\", DefaultLoggerFinderTest.class.getModule())");
} finally { } finally {
allowControl.get().set(old); allowControl.get().set(old);
} }
@ -389,8 +389,8 @@ public class DefaultLoggerFinderTest {
Logger sysLogger1 = null; Logger sysLogger1 = null;
try { try {
sysLogger1 = provider.getLogger("foo", Thread.class); sysLogger1 = provider.getLogger("foo", Thread.class.getModule());
loggerDescMap.put(sysLogger1, "provider.getSystemLogger(\"foo\")"); loggerDescMap.put(sysLogger1, "provider.getLogger(\"foo\", Thread.class.getModule())");
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
throw new RuntimeException("Managed to obtain a system logger without permission"); throw new RuntimeException("Managed to obtain a system logger without permission");
} }
@ -405,8 +405,8 @@ public class DefaultLoggerFinderTest {
boolean old = allowControl.get().get(); boolean old = allowControl.get().get();
allowControl.get().set(true); allowControl.get().set(true);
try { try {
sysLogger1 = provider.getLogger("foo", Thread.class); sysLogger1 = provider.getLogger("foo", Thread.class.getModule());
loggerDescMap.put(sysLogger1, "provider.getSystemLogger(\"foo\")"); loggerDescMap.put(sysLogger1, "provider.getLogger(\"foo\", Thread.class.getModule())");
} finally { } finally {
allowControl.get().set(old); allowControl.get().set(old);
} }
@ -417,8 +417,8 @@ public class DefaultLoggerFinderTest {
Logger appLogger2 = null; Logger appLogger2 = null;
try { try {
appLogger2 = provider.getLocalizedLogger("foo", loggerBundle, DefaultLoggerFinderTest.class); appLogger2 = provider.getLocalizedLogger("foo", loggerBundle, DefaultLoggerFinderTest.class.getModule());
loggerDescMap.put(appLogger2, "provider.getLocalizedApplicationLogger(\"foo\", loggerBundle)"); loggerDescMap.put(appLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, DefaultLoggerFinderTest.class.getModule())");
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
throw new RuntimeException("Managed to obtain a logger without permission"); throw new RuntimeException("Managed to obtain a logger without permission");
} }
@ -433,8 +433,8 @@ public class DefaultLoggerFinderTest {
boolean old = allowControl.get().get(); boolean old = allowControl.get().get();
allowControl.get().set(true); allowControl.get().set(true);
try { try {
appLogger2 = provider.getLocalizedLogger("foo", loggerBundle, DefaultLoggerFinderTest.class); appLogger2 = provider.getLocalizedLogger("foo", loggerBundle, DefaultLoggerFinderTest.class.getModule());
loggerDescMap.put(appLogger2, "provider.getLocalizedApplicationLogger(\"foo\", loggerBundle)"); loggerDescMap.put(appLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, DefaultLoggerFinderTest.class.getModule())");
} finally { } finally {
allowControl.get().set(old); allowControl.get().set(old);
} }
@ -442,8 +442,8 @@ public class DefaultLoggerFinderTest {
Logger sysLogger2 = null; Logger sysLogger2 = null;
try { try {
sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class); sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class.getModule());
loggerDescMap.put(sysLogger2, "provider.getLocalizedSystemLogger(\"foo\", loggerBundle)"); loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class.getModule())");
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
throw new RuntimeException("Managed to obtain a system logger without permission"); throw new RuntimeException("Managed to obtain a system logger without permission");
} }
@ -458,8 +458,8 @@ public class DefaultLoggerFinderTest {
boolean old = allowControl.get().get(); boolean old = allowControl.get().get();
allowControl.get().set(true); allowControl.get().set(true);
try { try {
sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class); sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class.getModule());
loggerDescMap.put(sysLogger2, "provider.getLocalizedSystemLogger(\"foo\", loggerBundle)"); loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class.getModule())");
} finally { } finally {
allowControl.get().set(old); allowControl.get().set(old);
} }

View File

@ -55,6 +55,7 @@ import java.util.function.Function;
import jdk.internal.logger.DefaultLoggerFinder; import jdk.internal.logger.DefaultLoggerFinder;
import jdk.internal.logger.SimpleConsoleLogger; import jdk.internal.logger.SimpleConsoleLogger;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
import java.lang.reflect.Module;
/** /**
* @test * @test
@ -112,10 +113,10 @@ public class BaseDefaultLoggerFinderTest {
public final static AtomicLong sequencer = new AtomicLong(); public final static AtomicLong sequencer = new AtomicLong();
public Logger getLogger(String name, Class<?> caller); public Logger getLogger(String name, Module caller);
public Logger getLocalizedLogger(String name, ResourceBundle bundle, Class<?> caller); public Logger getLocalizedLogger(String name, ResourceBundle bundle, Module caller);
void setLevel(Logger logger, Level level, Class<?> caller); void setLevel(Logger logger, Level level, Module caller);
void setLevel(Logger logger, PlatformLogger.Level level, Class<?> caller); void setLevel(Logger logger, PlatformLogger.Level level, Module caller);
PlatformLogger.Bridge asPlatformLoggerBridge(Logger logger); PlatformLogger.Bridge asPlatformLoggerBridge(Logger logger);
} }
@ -130,7 +131,7 @@ public class BaseDefaultLoggerFinderTest {
} }
@Override @Override
public void setLevel(Logger logger, Level level, Class<?> caller) { public void setLevel(Logger logger, Level level, Module caller) {
PrivilegedAction<Void> pa = () -> { PrivilegedAction<Void> pa = () -> {
setLevel(logger, PlatformLogger.toPlatformLevel(level), caller); setLevel(logger, PlatformLogger.toPlatformLevel(level), caller);
return null; return null;
@ -139,7 +140,7 @@ public class BaseDefaultLoggerFinderTest {
} }
@Override @Override
public void setLevel(Logger logger, PlatformLogger.Level level, Class<?> caller) { public void setLevel(Logger logger, PlatformLogger.Level level, Module caller) {
PrivilegedAction<Logger> pa = () -> demandLoggerFor(logger.getName(), caller); PrivilegedAction<Logger> pa = () -> demandLoggerFor(logger.getName(), caller);
Logger impl = AccessController.doPrivileged(pa); Logger impl = AccessController.doPrivileged(pa);
SimpleConsoleLogger.class.cast(impl) SimpleConsoleLogger.class.cast(impl)
@ -606,11 +607,12 @@ public class BaseDefaultLoggerFinderTest {
String name, String name,
ResourceBundle loggerBundle, ResourceBundle loggerBundle,
Logger logger, Logger logger,
Class<?> caller) { Class<?> callerClass) {
System.out.println("Testing " + loggerDescMap.get(logger) + " [" + logger +"]"); System.out.println("Testing " + loggerDescMap.get(logger) + " [" + logger +"]");
AtomicLong sequencer = TestLoggerFinder.sequencer; AtomicLong sequencer = TestLoggerFinder.sequencer;
Module caller = callerClass.getModule();
Foo foo = new Foo(); Foo foo = new Foo();
String fooMsg = foo.toString(); String fooMsg = foo.toString();
for (Level loggerLevel : Level.values()) { for (Level loggerLevel : Level.values()) {

View File

@ -47,6 +47,7 @@ import java.lang.System.LoggerFinder;
import java.lang.System.Logger; import java.lang.System.Logger;
import java.lang.System.Logger.Level; import java.lang.System.Logger.Level;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.lang.reflect.Module;
/** /**
* @test * @test
@ -209,8 +210,6 @@ public class BaseLoggerBridgeTest {
return Arrays.deepToString(toArray(false)); return Arrays.deepToString(toArray(false));
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return obj instanceof LogEvent return obj instanceof LogEvent
@ -342,15 +341,15 @@ public class BaseLoggerBridgeTest {
} }
public Logger getLogger(String name, Class<?> caller); public Logger getLogger(String name, Module caller);
public Logger getLocalizedLogger(String name, ResourceBundle bundle, Class<?> caller); public Logger getLocalizedLogger(String name, ResourceBundle bundle, Module caller);
} }
public static class BaseLoggerFinder extends LoggerFinder implements TestLoggerFinder { public static class BaseLoggerFinder extends LoggerFinder implements TestLoggerFinder {
static final RuntimePermission LOGGERFINDER_PERMISSION = static final RuntimePermission LOGGERFINDER_PERMISSION =
new RuntimePermission("loggerFinder"); new RuntimePermission("loggerFinder");
@Override @Override
public Logger getLogger(String name, Class<?> caller) { public Logger getLogger(String name, Module caller) {
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) { if (sm != null) {
sm.checkPermission(LOGGERFINDER_PERMISSION); sm.checkPermission(LOGGERFINDER_PERMISSION);
@ -375,7 +374,7 @@ public class BaseLoggerBridgeTest {
} }
} }
static Logger getLogger(String name, Class<?> caller) { static Logger getLogger(String name, Module caller) {
boolean old = allowAll.get().get(); boolean old = allowAll.get().get();
allowAccess.get().set(true); allowAccess.get().set(true);
try { try {
@ -465,7 +464,7 @@ public class BaseLoggerBridgeTest {
TestLoggerFinder.LoggerImpl appSink = null; TestLoggerFinder.LoggerImpl appSink = null;
try { try {
appSink = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", BaseLoggerBridgeTest.class)); appSink = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", BaseLoggerBridgeTest.class.getModule()));
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
throw new RuntimeException("Managed to obtain a system logger without permission"); throw new RuntimeException("Managed to obtain a system logger without permission");
} }
@ -480,7 +479,7 @@ public class BaseLoggerBridgeTest {
boolean old = allowControl.get().get(); boolean old = allowControl.get().get();
allowControl.get().set(true); allowControl.get().set(true);
try { try {
appSink = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", BaseLoggerBridgeTest.class)); appSink = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", BaseLoggerBridgeTest.class.getModule()));
} finally { } finally {
allowControl.get().set(old); allowControl.get().set(old);
} }
@ -489,7 +488,7 @@ public class BaseLoggerBridgeTest {
TestLoggerFinder.LoggerImpl sysSink = null; TestLoggerFinder.LoggerImpl sysSink = null;
try { try {
sysSink = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", Thread.class)); sysSink = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", Thread.class.getModule()));
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
throw new RuntimeException("Managed to obtain a system logger without permission"); throw new RuntimeException("Managed to obtain a system logger without permission");
} }
@ -527,13 +526,13 @@ public class BaseLoggerBridgeTest {
Logger sysLogger1 = null; Logger sysLogger1 = null;
try { try {
sysLogger1 = getLogger("foo", Thread.class); sysLogger1 = getLogger("foo", Thread.class.getModule());
loggerDescMap.put(sysLogger1, loggerDescMap.put(sysLogger1,
"jdk.internal.logger.LazyLoggers.getLogger(\"foo\", Thread.class)"); "jdk.internal.logger.LazyLoggers.getLogger(\"foo\", Thread.class.getModule())");
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
// check that the provider would have thrown an exception // check that the provider would have thrown an exception
provider.getLogger("foo", Thread.class); provider.getLogger("foo", Thread.class.getModule());
throw new RuntimeException("Managed to obtain a system logger without permission"); throw new RuntimeException("Managed to obtain a system logger without permission");
} }
} catch (AccessControlException acx) { } catch (AccessControlException acx) {
@ -572,8 +571,8 @@ public class BaseLoggerBridgeTest {
Logger sysLogger2 = null; Logger sysLogger2 = null;
try { try {
sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class); sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class.getModule());
loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class)"); loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class.getModule())");
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
throw new RuntimeException("Managed to obtain a system logger without permission"); throw new RuntimeException("Managed to obtain a system logger without permission");
} }

View File

@ -47,6 +47,7 @@ import java.lang.System.Logger.Level;
import java.security.AccessControlException; import java.security.AccessControlException;
import java.util.stream.Stream; import java.util.stream.Stream;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
import java.lang.reflect.Module;
/** /**
* @test * @test
@ -327,12 +328,12 @@ public class BasePlatformLoggerTest {
} }
} }
public Logger getLogger(String name, Class<?> caller); public Logger getLogger(String name, Module caller);
} }
public static class BaseLoggerFinder extends LoggerFinder implements TestLoggerFinder { public static class BaseLoggerFinder extends LoggerFinder implements TestLoggerFinder {
@Override @Override
public Logger getLogger(String name, Class<?> caller) { public Logger getLogger(String name, Module caller) {
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) { if (sm != null) {
sm.checkPermission(LOGGERFINDER_PERMISSION); sm.checkPermission(LOGGERFINDER_PERMISSION);
@ -433,7 +434,7 @@ public class BasePlatformLoggerTest {
try { try {
allowControl.get().set(true); allowControl.get().set(true);
appSink = TestLoggerFinder.LoggerImpl.class.cast( appSink = TestLoggerFinder.LoggerImpl.class.cast(
provider.getLogger("foo", BasePlatformLoggerTest.class)); provider.getLogger("foo", BasePlatformLoggerTest.class.getModule()));
} finally { } finally {
allowControl.get().set(before); allowControl.get().set(before);
} }
@ -442,7 +443,8 @@ public class BasePlatformLoggerTest {
before = allowControl.get().get(); before = allowControl.get().get();
try { try {
allowControl.get().set(true); allowControl.get().set(true);
sysSink = TestLoggerFinder.LoggerImpl.class.cast(provider.getLogger("foo", Thread.class)); sysSink = TestLoggerFinder.LoggerImpl.class.cast(
provider.getLogger("foo", Thread.class.getModule()));
} finally { } finally {
allowControl.get().set(before); allowControl.get().set(before);
} }

View File

@ -30,7 +30,7 @@ import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Set; import java.util.Set;
import java.lang.reflect.Module;
import jdk.internal.logger.BootstrapLogger; import jdk.internal.logger.BootstrapLogger;
import jdk.internal.logger.LazyLoggers; import jdk.internal.logger.LazyLoggers;
@ -69,7 +69,7 @@ public class BootstrapLoggerAPIsTest {
} }
final Logger LOGGER = final Logger LOGGER =
LazyLoggers.getLogger("foo.bar", Thread.class); LazyLoggers.getLogger("foo.bar", Thread.class.getModule());
final sun.util.logging.PlatformLogger.Level PLATFORM_LEVEL = final sun.util.logging.PlatformLogger.Level PLATFORM_LEVEL =
sun.util.logging.PlatformLogger.Level.SEVERE; sun.util.logging.PlatformLogger.Level.SEVERE;
final MyResources BUNDLE = new MyResources(); final MyResources BUNDLE = new MyResources();

View File

@ -43,6 +43,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import jdk.internal.logger.BootstrapLogger; import jdk.internal.logger.BootstrapLogger;
import jdk.internal.logger.LazyLoggers; import jdk.internal.logger.LazyLoggers;
import java.lang.reflect.Module;
/* /*
* @test * @test
@ -105,7 +106,7 @@ public class BootstrapLoggerTest {
if (BootstrapLogger.isBooted()) { if (BootstrapLogger.isBooted()) {
throw new RuntimeException("VM should not be booted!"); throw new RuntimeException("VM should not be booted!");
} }
Logger logger = LazyLoggers.getLogger("foo.bar", Thread.class); Logger logger = LazyLoggers.getLogger("foo.bar", Thread.class.getModule());
if (test != TestCase.NO_SECURITY) { if (test != TestCase.NO_SECURITY) {
LogStream.err.println("Setting security manager"); LogStream.err.println("Setting security manager");
@ -261,7 +262,7 @@ public class BootstrapLoggerTest {
SimplePolicy.allowAll.set(Boolean.TRUE); SimplePolicy.allowAll.set(Boolean.TRUE);
try { try {
bazbaz = java.lang.System.LoggerFinder bazbaz = java.lang.System.LoggerFinder
.getLoggerFinder().getLogger("foo.bar.baz.baz", BootstrapLoggerTest.class); .getLoggerFinder().getLogger("foo.bar.baz.baz", BootstrapLoggerTest.class.getModule());
} finally { } finally {
SimplePolicy.allowAll.set(Boolean.FALSE); SimplePolicy.allowAll.set(Boolean.FALSE);
} }

View File

@ -51,6 +51,7 @@ import java.lang.System.Logger;
import java.lang.System.Logger.Level; import java.lang.System.Logger.Level;
import java.util.stream.Stream; import java.util.stream.Stream;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
import java.lang.reflect.Module;
/** /**
* @test * @test
@ -164,6 +165,7 @@ public class LoggerBridgeTest {
null, null, level, bundle, key, null, null, level, bundle, key,
thrown, params); thrown, params);
} }
public static LogEvent of(long sequenceNumber, public static LogEvent of(long sequenceNumber,
boolean isLoggable, String name, boolean isLoggable, String name,
sun.util.logging.PlatformLogger.Level level, ResourceBundle bundle, sun.util.logging.PlatformLogger.Level level, ResourceBundle bundle,
@ -231,7 +233,7 @@ public class LoggerBridgeTest {
try { try {
// Preload classes before the security manager is on. // Preload classes before the security manager is on.
providerClass = ClassLoader.getSystemClassLoader().loadClass("LoggerBridgeTest$LogProducerFinder"); providerClass = ClassLoader.getSystemClassLoader().loadClass("LoggerBridgeTest$LogProducerFinder");
((LoggerFinder)providerClass.newInstance()).getLogger("foo", providerClass); ((LoggerFinder)providerClass.newInstance()).getLogger("foo", providerClass.getModule());
} catch (Exception ex) { } catch (Exception ex) {
throw new ExceptionInInitializerError(ex); throw new ExceptionInInitializerError(ex);
} }
@ -415,7 +417,7 @@ public class LoggerBridgeTest {
} }
@Override @Override
public Logger getLogger(String name, Class<?> caller) { public Logger getLogger(String name, Module caller) {
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) { if (sm != null) {
sm.checkPermission(LOGGERFINDER_PERMISSION); sm.checkPermission(LOGGERFINDER_PERMISSION);
@ -430,6 +432,15 @@ public class LoggerBridgeTest {
} }
} }
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 = { static final sun.util.logging.PlatformLogger.Level[] julLevels = {
sun.util.logging.PlatformLogger.Level.ALL, sun.util.logging.PlatformLogger.Level.ALL,
sun.util.logging.PlatformLogger.Level.FINEST, sun.util.logging.PlatformLogger.Level.FINEST,
@ -497,14 +508,14 @@ public class LoggerBridgeTest {
try { try {
Class<?> bridgeClass = Class.forName("jdk.internal.logger.LazyLoggers"); Class<?> bridgeClass = Class.forName("jdk.internal.logger.LazyLoggers");
lazyGetLogger = bridgeClass.getDeclaredMethod("getLogger", lazyGetLogger = bridgeClass.getDeclaredMethod("getLogger",
String.class, Class.class); String.class, Module.class);
lazyGetLogger.setAccessible(true); lazyGetLogger.setAccessible(true);
} catch (Throwable ex) { } catch (Throwable ex) {
throw new ExceptionInInitializerError(ex); throw new ExceptionInInitializerError(ex);
} }
} }
static Logger getLogger(LoggerFinder provider, String name, Class<?> caller) { static Logger getLogger(LoggerFinder provider, String name, Module caller) {
Logger logger; Logger logger;
try { try {
logger = Logger.class.cast(lazyGetLogger.invoke(null, name, caller)); logger = Logger.class.cast(lazyGetLogger.invoke(null, name, caller));
@ -522,14 +533,14 @@ public class LoggerBridgeTest {
// The method above does not throw exception... // The method above does not throw exception...
// call the provider here to verify that an exception would have // call the provider here to verify that an exception would have
// been thrown by the provider. // been thrown by the provider.
if (logger != null && caller == Thread.class) { if (logger != null && caller == Thread.class.getModule()) {
Logger log = provider.getLogger(name, caller); Logger log = provider.getLogger(name, caller);
} }
return logger; return logger;
} }
static Logger getLogger(LoggerFinder provider, String name, ResourceBundle bundle, Class<?> caller) { static Logger getLogger(LoggerFinder provider, String name, ResourceBundle bundle, Module caller) {
if (caller.getClassLoader() != null) { if (getClassLoader(caller) != null) {
return System.getLogger(name,bundle); return System.getLogger(name,bundle);
} else { } else {
return provider.getLocalizedLogger(name, bundle, caller); return provider.getLocalizedLogger(name, bundle, caller);
@ -614,12 +625,12 @@ public class LoggerBridgeTest {
Logger appLogger1 = System.getLogger("foo"); Logger appLogger1 = System.getLogger("foo");
loggerDescMap.put(appLogger1, "LogProducer.getApplicationLogger(\"foo\")"); loggerDescMap.put(appLogger1, "System.getLogger(\"foo\")");
Logger sysLogger1 = null; Logger sysLogger1 = null;
try { try {
sysLogger1 = getLogger(provider, "foo", Thread.class); sysLogger1 = getLogger(provider, "foo", Thread.class.getModule());
loggerDescMap.put(sysLogger1, "LogProducer.getSystemLogger(\"foo\")"); loggerDescMap.put(sysLogger1, "provider.getLogger(\"foo\", Thread.class.getModule())");
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
throw new RuntimeException("Managed to obtain a system logger without permission"); throw new RuntimeException("Managed to obtain a system logger without permission");
} }
@ -636,12 +647,12 @@ public class LoggerBridgeTest {
Logger appLogger2 = Logger appLogger2 =
System.getLogger("foo", loggerBundle); System.getLogger("foo", loggerBundle);
loggerDescMap.put(appLogger2, "LogProducer.getApplicationLogger(\"foo\", loggerBundle)"); loggerDescMap.put(appLogger2, "System.getLogger(\"foo\", loggerBundle)");
Logger sysLogger2 = null; Logger sysLogger2 = null;
try { try {
sysLogger2 = getLogger(provider, "foo", loggerBundle, Thread.class); sysLogger2 = getLogger(provider, "foo", loggerBundle, Thread.class.getModule());
loggerDescMap.put(sysLogger2, "provider.getSystemLogger(\"foo\", loggerBundle)"); loggerDescMap.put(sysLogger2, "provider.getLogger(\"foo\", loggerBundle, Thread.class.getModule())");
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
throw new RuntimeException("Managed to obtain a system logger without permission"); throw new RuntimeException("Managed to obtain a system logger without permission");
} }
@ -671,9 +682,9 @@ public class LoggerBridgeTest {
allowControl.get().set(true); allowControl.get().set(true);
try { try {
appSink = LogProducerFinder.LoggerImpl.class.cast( appSink = LogProducerFinder.LoggerImpl.class.cast(
provider.getLogger("foo", LoggerBridgeTest.class)); provider.getLogger("foo", LoggerBridgeTest.class.getModule()));
sysSink = LogProducerFinder.LoggerImpl.class.cast( sysSink = LogProducerFinder.LoggerImpl.class.cast(
provider.getLogger("foo", Thread.class)); provider.getLogger("foo", Thread.class.getModule()));
} finally { } finally {
allowControl.get().set(old); allowControl.get().set(old);
} }

View File

@ -53,6 +53,7 @@ import java.util.ServiceConfigurationError;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import jdk.internal.logger.SimpleConsoleLogger; import jdk.internal.logger.SimpleConsoleLogger;
import java.lang.reflect.Module;
/** /**
* @test * @test
@ -166,8 +167,8 @@ public class LoggerFinderLoaderTest {
} }
public Logger getLogger(String name, Class<?> caller); public Logger getLogger(String name, Module caller);
public Logger getLocalizedLogger(String name, ResourceBundle bundle, Class<?> caller); public Logger getLocalizedLogger(String name, ResourceBundle bundle, Module caller);
} }
public static class BaseLoggerFinder extends LoggerFinder implements TestLoggerFinder { public static class BaseLoggerFinder extends LoggerFinder implements TestLoggerFinder {
@ -187,7 +188,7 @@ public class LoggerFinderLoaderTest {
@Override @Override
public Logger getLogger(String name, Class<?> caller) { public Logger getLogger(String name, Module caller) {
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) { if (sm != null) {
sm.checkPermission(LOGGERFINDER_PERMISSION); sm.checkPermission(LOGGERFINDER_PERMISSION);
@ -210,7 +211,7 @@ public class LoggerFinderLoaderTest {
throw new ServiceConfigurationError("Should not come here"); throw new ServiceConfigurationError("Should not come here");
} }
@Override @Override
public Logger getLogger(String name, Class<?> caller) { public Logger getLogger(String name, Module caller) {
throw new ServiceConfigurationError("Should not come here"); throw new ServiceConfigurationError("Should not come here");
} }
} }

View File

@ -49,6 +49,7 @@ import java.lang.System.Logger;
import java.lang.System.Logger.Level; import java.lang.System.Logger.Level;
import java.util.stream.Stream; import java.util.stream.Stream;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
import java.lang.reflect.Module;
/** /**
* @test * @test
@ -94,7 +95,7 @@ public class PlatformLoggerBridgeTest {
try { try {
// Preload classes before the security manager is on. // Preload classes before the security manager is on.
providerClass = ClassLoader.getSystemClassLoader().loadClass("PlatformLoggerBridgeTest$LogProducerFinder"); providerClass = ClassLoader.getSystemClassLoader().loadClass("PlatformLoggerBridgeTest$LogProducerFinder");
((LoggerFinder)providerClass.newInstance()).getLogger("foo", providerClass); ((LoggerFinder)providerClass.newInstance()).getLogger("foo", providerClass.getModule());
} catch (Exception ex) { } catch (Exception ex) {
throw new ExceptionInInitializerError(ex); throw new ExceptionInInitializerError(ex);
} }
@ -415,7 +416,7 @@ public class PlatformLoggerBridgeTest {
} }
@Override @Override
public Logger getLogger(String name, Class<?> caller) { public Logger getLogger(String name, Module caller) {
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) { if (sm != null) {
sm.checkPermission(LOGGERFINDER_PERMISSION); sm.checkPermission(LOGGERFINDER_PERMISSION);
@ -598,7 +599,7 @@ public class PlatformLoggerBridgeTest {
allowControl.get().set(true); allowControl.get().set(true);
try { try {
sysSink = LogProducerFinder.LoggerImpl.class.cast( sysSink = LogProducerFinder.LoggerImpl.class.cast(
provider.getLogger("foo", Thread.class)); provider.getLogger("foo", Thread.class.getModule()));
} finally { } finally {
allowControl.get().set(old); allowControl.get().set(old);
} }

View File

@ -469,12 +469,12 @@ public class LoggerFinderAPITest {
errors.append(test.testGetLoggerOverriddenOnSpi()); errors.append(test.testGetLoggerOverriddenOnSpi());
java.lang.System.Logger julLogger = java.lang.System.Logger julLogger =
java.lang.System.LoggerFinder.getLoggerFinder() java.lang.System.LoggerFinder.getLoggerFinder()
.getLogger("foo", LoggerFinderAPITest.class); .getLogger("foo", LoggerFinderAPITest.class.getModule());
errors.append(test.testDefaultJULLogger(julLogger)); errors.append(test.testDefaultJULLogger(julLogger));
if (errors.length() > 0) throw new RuntimeException(errors.toString()); if (errors.length() > 0) throw new RuntimeException(errors.toString());
java.lang.System.Logger julSystemLogger = java.lang.System.Logger julSystemLogger =
java.lang.System.LoggerFinder.getLoggerFinder() java.lang.System.LoggerFinder.getLoggerFinder()
.getLogger("bar", Thread.class); .getLogger("bar", Thread.class.getModule());
errors.append(test.testDefaultJULLogger(julSystemLogger)); errors.append(test.testDefaultJULLogger(julSystemLogger));
if (errors.length() > 0) throw new RuntimeException(errors.toString()); if (errors.length() > 0) throw new RuntimeException(errors.toString());
java.lang.System.Logger julLocalizedLogger = java.lang.System.Logger julLocalizedLogger =
@ -482,7 +482,7 @@ public class LoggerFinderAPITest {
System.getLogger("baz", bundleLocalized); System.getLogger("baz", bundleLocalized);
java.lang.System.Logger julLocalizedSystemLogger = java.lang.System.Logger julLocalizedSystemLogger =
java.lang.System.LoggerFinder.getLoggerFinder() java.lang.System.LoggerFinder.getLoggerFinder()
.getLocalizedLogger("oof", bundleLocalized, Thread.class); .getLocalizedLogger("oof", bundleLocalized, Thread.class.getModule());
final String error = errors.toString(); final String error = errors.toString();
if (!error.isEmpty()) throw new RuntimeException(error); if (!error.isEmpty()) throw new RuntimeException(error);
for (java.lang.System.Logger logger : new java.lang.System.Logger[] { for (java.lang.System.Logger logger : new java.lang.System.Logger[] {

View File

@ -77,6 +77,7 @@ import java.util.logging.LogManager;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
import java.util.logging.Logger; import java.util.logging.Logger;
import sun.util.logging.internal.LoggingProviderImpl; import sun.util.logging.internal.LoggingProviderImpl;
import java.lang.reflect.Module;
/** /**
* @author danielfuchs * @author danielfuchs
@ -1506,7 +1507,7 @@ public class LoggerFinderBackendTest {
Logger getBackendLogger(String name) { Logger getBackendLogger(String name) {
if (isSystem) { if (isSystem) {
return LoggingProviderImpl.getLogManagerAccess().demandLoggerFor( return LoggingProviderImpl.getLogManagerAccess().demandLoggerFor(
LogManager.getLogManager(), name, Thread.class); LogManager.getLogManager(), name, Thread.class.getModule());
} else { } else {
return Logger.getLogger(name); return Logger.getLogger(name);
} }
@ -1699,7 +1700,7 @@ public class LoggerFinderBackendTest {
Collections.synchronizedMap(new HashMap<>()); Collections.synchronizedMap(new HashMap<>());
@Override @Override
public java.lang.System.Logger getLogger(String name, Class<?> caller) { public java.lang.System.Logger getLogger(String name, Module caller) {
ClassLoader callerLoader = caller.getClassLoader(); ClassLoader callerLoader = caller.getClassLoader();
if (callerLoader == null) { if (callerLoader == null) {
systemLoggers.putIfAbsent(name, new CustomLogger(name)); systemLoggers.putIfAbsent(name, new CustomLogger(name));
@ -1827,8 +1828,8 @@ public class LoggerFinderBackendTest {
public void setLevel(java.lang.System.Logger logger, Level level) { public void setLevel(java.lang.System.Logger logger, Level level) {
final CustomLoggerFinder.CustomLogger l = final CustomLoggerFinder.CustomLogger l =
(CustomLoggerFinder.CustomLogger) (CustomLoggerFinder.CustomLogger)
(isSystem ? provider.getLogger(logger.getName(), Thread.class) : (isSystem ? provider.getLogger(logger.getName(), Thread.class.getModule()) :
provider.getLogger(logger.getName(), LoggerFinderBackendTest.class)); provider.getLogger(logger.getName(), LoggerFinderBackendTest.class.getModule()));
l.setLevel(provider.fromJul(level)); l.setLevel(provider.fromJul(level));
} }
@Override @Override
@ -1840,8 +1841,8 @@ public class LoggerFinderBackendTest {
CustomLoggerFinder.CustomLevel getLevel(java.lang.System.Logger logger) { CustomLoggerFinder.CustomLevel getLevel(java.lang.System.Logger logger) {
final CustomLoggerFinder.CustomLogger l = final CustomLoggerFinder.CustomLogger l =
(CustomLoggerFinder.CustomLogger) (CustomLoggerFinder.CustomLogger)
(isSystem ? provider.getLogger(logger.getName(), Thread.class) : (isSystem ? provider.getLogger(logger.getName(), Thread.class.getModule()) :
provider.getLogger(logger.getName(), LoggerFinderBackendTest.class)); provider.getLogger(logger.getName(), LoggerFinderBackendTest.class.getModule()));
return l.level; return l.level;
} }
@ -1962,7 +1963,7 @@ public class LoggerFinderBackendTest {
try { try {
Class<?> lazyLoggers = jdk.internal.logger.LazyLoggers.class; Class<?> lazyLoggers = jdk.internal.logger.LazyLoggers.class;
getLazyLogger = lazyLoggers.getMethod("getLazyLogger", getLazyLogger = lazyLoggers.getMethod("getLazyLogger",
String.class, Class.class); String.class, Module.class);
getLazyLogger.setAccessible(true); getLazyLogger.setAccessible(true);
Class<?> loggerFinderLoader = Class<?> loggerFinderLoader =
Class.forName("java.lang.System$LoggerFinder"); Class.forName("java.lang.System$LoggerFinder");
@ -1973,7 +1974,7 @@ public class LoggerFinderBackendTest {
} }
} }
static java.lang.System.Logger getSystemLogger(String name, Class<?> caller) throws Exception { static java.lang.System.Logger getSystemLogger(String name, Module caller) throws Exception {
try { try {
return java.lang.System.Logger.class.cast(getLazyLogger.invoke(null, name, caller)); return java.lang.System.Logger.class.cast(getLazyLogger.invoke(null, name, caller));
} catch (InvocationTargetException x) { } catch (InvocationTargetException x) {
@ -1986,7 +1987,7 @@ public class LoggerFinderBackendTest {
} }
} }
static java.lang.System.Logger getSystemLogger(String name, static java.lang.System.Logger getSystemLogger(String name,
ResourceBundle bundle, Class<?> caller) throws Exception { ResourceBundle bundle, Module caller) throws Exception {
try { try {
LoggerFinder provider = LoggerFinder.class.cast(accessLoggerFinder.invoke(null)); LoggerFinder provider = LoggerFinder.class.cast(accessLoggerFinder.invoke(null));
return provider.getLocalizedLogger(name, bundle, caller); return provider.getLocalizedLogger(name, bundle, caller);
@ -2047,14 +2048,14 @@ public class LoggerFinderBackendTest {
final BackendTester tester = factory.createBackendTester(false); final BackendTester tester = factory.createBackendTester(false);
final java.lang.System.Logger logger = final java.lang.System.Logger logger =
java.lang.System.LoggerFinder.getLoggerFinder() java.lang.System.LoggerFinder.getLoggerFinder()
.getLogger("foo", LoggerFinderBackendTest.class); .getLogger("foo", LoggerFinderBackendTest.class.getModule());
testLogger(tester, logger, nb); testLogger(tester, logger, nb);
// Test a simple system logger with JUL backend // Test a simple system logger with JUL backend
final java.lang.System.Logger system = final java.lang.System.Logger system =
java.lang.System.LoggerFinder.getLoggerFinder() java.lang.System.LoggerFinder.getLoggerFinder()
.getLogger("bar", Thread.class); .getLogger("bar", Thread.class.getModule());
final BackendTester systemTester = factory.createBackendTester(true); final BackendTester systemTester = factory.createBackendTester(true);
testLogger(systemTester, system, nb); testLogger(systemTester, system, nb);
@ -2062,7 +2063,7 @@ public class LoggerFinderBackendTest {
// JUL backend // JUL backend
final java.lang.System.Logger noBundleLogger = final java.lang.System.Logger noBundleLogger =
java.lang.System.LoggerFinder.getLoggerFinder() java.lang.System.LoggerFinder.getLoggerFinder()
.getLocalizedLogger("baz", null, LoggerFinderBackendTest.class); .getLocalizedLogger("baz", null, LoggerFinderBackendTest.class.getModule());
final BackendTester noBundleTester = final BackendTester noBundleTester =
factory.createBackendTester(false, spiLoggerClass); factory.createBackendTester(false, spiLoggerClass);
testLogger(noBundleTester, noBundleLogger, nb); testLogger(noBundleTester, noBundleLogger, nb);
@ -2071,7 +2072,7 @@ public class LoggerFinderBackendTest {
// backend // backend
final java.lang.System.Logger noBundleSysLogger = final java.lang.System.Logger noBundleSysLogger =
java.lang.System.LoggerFinder.getLoggerFinder() java.lang.System.LoggerFinder.getLoggerFinder()
.getLocalizedLogger("oof", null, Thread.class); .getLocalizedLogger("oof", null, Thread.class.getModule());
final BackendTester noBundleSysTester = final BackendTester noBundleSysTester =
factory.createBackendTester(true, spiLoggerClass); factory.createBackendTester(true, spiLoggerClass);
testLogger(noBundleSysTester, noBundleSysLogger, nb); testLogger(noBundleSysTester, noBundleSysLogger, nb);
@ -2085,14 +2086,14 @@ public class LoggerFinderBackendTest {
System.out.println("System.Loggers.getLogger(\"baz\", null): got expected " + x); System.out.println("System.Loggers.getLogger(\"baz\", null): got expected " + x);
} }
final java.lang.System.Logger noBundleExtensionLogger = final java.lang.System.Logger noBundleExtensionLogger =
getSystemLogger("baz", null, LoggerFinderBackendTest.class); getSystemLogger("baz", null, LoggerFinderBackendTest.class.getModule());
final BackendTester noBundleExtensionTester = final BackendTester noBundleExtensionTester =
factory.createBackendTester(false, jdkLoggerClass); factory.createBackendTester(false, jdkLoggerClass);
testLogger(noBundleExtensionTester, noBundleExtensionLogger, nb); testLogger(noBundleExtensionTester, noBundleExtensionLogger, nb);
// Test a simple system logger with JUL backend // Test a simple system logger with JUL backend
final java.lang.System.Logger sysExtensionLogger = final java.lang.System.Logger sysExtensionLogger =
getSystemLogger("oof", Thread.class); getSystemLogger("oof", Thread.class.getModule());
final BackendTester sysExtensionTester = final BackendTester sysExtensionTester =
factory.createBackendTester(true, jdkLoggerClass); factory.createBackendTester(true, jdkLoggerClass);
testLogger(sysExtensionTester, sysExtensionLogger, nb); testLogger(sysExtensionTester, sysExtensionLogger, nb);
@ -2100,7 +2101,7 @@ public class LoggerFinderBackendTest {
// Test a localized system logger with null resource bundle and JUL // Test a localized system logger with null resource bundle and JUL
// backend // backend
final java.lang.System.Logger noBundleSysExtensionLogger = final java.lang.System.Logger noBundleSysExtensionLogger =
getSystemLogger("oof", null, Thread.class); getSystemLogger("oof", null, Thread.class.getModule());
final BackendTester noBundleSysExtensionTester = final BackendTester noBundleSysExtensionTester =
factory.createBackendTester(true, jdkLoggerClass); factory.createBackendTester(true, jdkLoggerClass);
testLogger(noBundleSysExtensionTester, noBundleSysExtensionLogger, nb); testLogger(noBundleSysExtensionTester, noBundleSysExtensionLogger, nb);
@ -2127,7 +2128,7 @@ public class LoggerFinderBackendTest {
ResourceBundle.getBundle(ResourceBundeLocalized.class.getName()); ResourceBundle.getBundle(ResourceBundeLocalized.class.getName());
final java.lang.System.Logger bundleLogger = final java.lang.System.Logger bundleLogger =
java.lang.System.LoggerFinder.getLoggerFinder() java.lang.System.LoggerFinder.getLoggerFinder()
.getLocalizedLogger("toto", bundle, LoggerFinderBackendTest.class); .getLocalizedLogger("toto", bundle, LoggerFinderBackendTest.class.getModule());
final BackendTester bundleTester = final BackendTester bundleTester =
factory.createBackendTester(false, spiLoggerClass, bundle); factory.createBackendTester(false, spiLoggerClass, bundle);
testLogger(bundleTester, bundleLogger, nb); testLogger(bundleTester, bundleLogger, nb);
@ -2135,7 +2136,7 @@ public class LoggerFinderBackendTest {
// Test a localized system logger with resource bundle and JUL backend // Test a localized system logger with resource bundle and JUL backend
final java.lang.System.Logger bundleSysLogger = final java.lang.System.Logger bundleSysLogger =
java.lang.System.LoggerFinder.getLoggerFinder() java.lang.System.LoggerFinder.getLoggerFinder()
.getLocalizedLogger("titi", bundle, Thread.class); .getLocalizedLogger("titi", bundle, Thread.class.getModule());
final BackendTester bundleSysTester = final BackendTester bundleSysTester =
factory.createBackendTester(true, spiLoggerClass, bundle); factory.createBackendTester(true, spiLoggerClass, bundle);
testLogger(bundleSysTester, bundleSysLogger, nb); testLogger(bundleSysTester, bundleSysLogger, nb);
@ -2151,7 +2152,7 @@ public class LoggerFinderBackendTest {
// Test a localized Jdk system logger with resource bundle and JUL // Test a localized Jdk system logger with resource bundle and JUL
// backend // backend
final java.lang.System.Logger bundleExtensionSysLogger = final java.lang.System.Logger bundleExtensionSysLogger =
getSystemLogger("titu", bundle, Thread.class); getSystemLogger("titu", bundle, Thread.class.getModule());
final BackendTester bundleExtensionSysTester = final BackendTester bundleExtensionSysTester =
factory.createBackendTester(true, jdkLoggerClass, bundle); factory.createBackendTester(true, jdkLoggerClass, bundle);
testLogger(bundleExtensionSysTester, bundleExtensionSysLogger, nb); testLogger(bundleExtensionSysTester, bundleExtensionSysLogger, nb);

View File

@ -48,6 +48,7 @@ import java.lang.System.LoggerFinder;
import java.lang.System.Logger; import java.lang.System.Logger;
import java.util.stream.Stream; import java.util.stream.Stream;
import sun.util.logging.internal.LoggingProviderImpl; import sun.util.logging.internal.LoggingProviderImpl;
import java.lang.reflect.Module;
/** /**
* @test * @test
@ -246,7 +247,7 @@ public class DefaultLoggerBridgeTest {
} }
} }
static Logger getLogger(String name, Class<?> caller) { static Logger getLogger(String name, Module caller) {
boolean old = allowAccess.get().get(); boolean old = allowAccess.get().get();
allowAccess.get().set(true); allowAccess.get().set(true);
try { try {
@ -311,8 +312,8 @@ public class DefaultLoggerBridgeTest {
ResourceBundle.getBundle(MyLoggerBundle.class.getName()); ResourceBundle.getBundle(MyLoggerBundle.class.getName());
final Map<Object, String> loggerDescMap = new HashMap<>(); final Map<Object, String> loggerDescMap = new HashMap<>();
Logger sysLogger1a = getLogger("foo", Thread.class); Logger sysLogger1a = getLogger("foo", Thread.class.getModule());
loggerDescMap.put(sysLogger1a, "jdk.internal.logger.LazyLoggers.getLogger(\"foo\", Thread.class)"); loggerDescMap.put(sysLogger1a, "jdk.internal.logger.LazyLoggers.getLogger(\"foo\", Thread.class.getModule())");
Logger appLogger1 = System.getLogger("foo"); Logger appLogger1 = System.getLogger("foo");
loggerDescMap.put(appLogger1, "System.getLogger(\"foo\")"); loggerDescMap.put(appLogger1, "System.getLogger(\"foo\")");
@ -341,9 +342,9 @@ public class DefaultLoggerBridgeTest {
Logger sysLogger1b = null; Logger sysLogger1b = null;
try { try {
sysLogger1b = provider.getLogger("foo", Thread.class); sysLogger1b = provider.getLogger("foo", Thread.class.getModule());
if (sysLogger1b != sysLogger1a) { if (sysLogger1b != sysLogger1a) {
loggerDescMap.put(sysLogger1b, "provider.getLogger(\"foo\", Thread.class)"); loggerDescMap.put(sysLogger1b, "provider.getLogger(\"foo\", Thread.class.getModule())");
} }
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
throw new RuntimeException("Managed to obtain a system logger without permission"); throw new RuntimeException("Managed to obtain a system logger without permission");
@ -367,8 +368,8 @@ public class DefaultLoggerBridgeTest {
Logger sysLogger2 = null; Logger sysLogger2 = null;
try { try {
sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class); sysLogger2 = provider.getLocalizedLogger("foo", loggerBundle, Thread.class.getModule());
loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class)"); loggerDescMap.put(sysLogger2, "provider.getLocalizedLogger(\"foo\", loggerBundle, Thread.class.getModule())");
if (!hasRequiredPermissions) { if (!hasRequiredPermissions) {
throw new RuntimeException("Managed to obtain a system logger without permission"); throw new RuntimeException("Managed to obtain a system logger without permission");
} }
@ -396,9 +397,9 @@ public class DefaultLoggerBridgeTest {
allowAll.get().set(true); allowAll.get().set(true);
try { try {
sysSink = LoggingProviderImpl.getLogManagerAccess().demandLoggerFor( sysSink = LoggingProviderImpl.getLogManagerAccess().demandLoggerFor(
LogManager.getLogManager(), "foo", Thread.class); LogManager.getLogManager(), "foo", Thread.class.getModule());
appSink = LoggingProviderImpl.getLogManagerAccess().demandLoggerFor( appSink = LoggingProviderImpl.getLogManagerAccess().demandLoggerFor(
LogManager.getLogManager(), "foo", DefaultLoggerBridgeTest.class); LogManager.getLogManager(), "foo", DefaultLoggerBridgeTest.class.getModule());
if (appSink == sysSink) { if (appSink == sysSink) {
throw new RuntimeException("identical backend loggers"); throw new RuntimeException("identical backend loggers");
} }

View File

@ -44,6 +44,7 @@ import java.util.logging.LogRecord;
import java.lang.System.LoggerFinder; import java.lang.System.LoggerFinder;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
import sun.util.logging.internal.LoggingProviderImpl; import sun.util.logging.internal.LoggingProviderImpl;
import java.lang.reflect.Module;
/** /**
* @test * @test
@ -244,9 +245,9 @@ public class DefaultPlatformLoggerTest {
LoggerFinder provider = LoggerFinder.getLoggerFinder(); LoggerFinder provider = LoggerFinder.getLoggerFinder();
java.util.logging.Logger appSink = LoggingProviderImpl.getLogManagerAccess() java.util.logging.Logger appSink = LoggingProviderImpl.getLogManagerAccess()
.demandLoggerFor(LogManager.getLogManager(), "foo", .demandLoggerFor(LogManager.getLogManager(), "foo",
DefaultPlatformLoggerTest.class); DefaultPlatformLoggerTest.class.getModule());
java.util.logging.Logger sysSink = LoggingProviderImpl.getLogManagerAccess() java.util.logging.Logger sysSink = LoggingProviderImpl.getLogManagerAccess()
.demandLoggerFor(LogManager.getLogManager(),"foo", Thread.class); .demandLoggerFor(LogManager.getLogManager(),"foo", Thread.class.getModule());
appSink.addHandler(new MyHandler()); appSink.addHandler(new MyHandler());
sysSink.addHandler(new MyHandler()); sysSink.addHandler(new MyHandler());
appSink.setUseParentHandlers(VERBOSE); appSink.setUseParentHandlers(VERBOSE);

View File

@ -197,7 +197,7 @@ public class PlatformLoggerTest {
// create a brand new java logger // create a brand new java logger
Logger javaLogger = sun.util.logging.internal.LoggingProviderImpl.getLogManagerAccess() Logger javaLogger = sun.util.logging.internal.LoggingProviderImpl.getLogManagerAccess()
.demandLoggerFor(LogManager.getLogManager(), .demandLoggerFor(LogManager.getLogManager(),
logger.getName()+"."+level.getName(), Thread.class); logger.getName()+"."+level.getName(), Thread.class.getModule());
// Set a non standard java.util.logging.Level on the java logger // Set a non standard java.util.logging.Level on the java logger
// (except for OFF & ALL - which will remain unchanged) // (except for OFF & ALL - which will remain unchanged)