--- old/src/java.logging/share/classes/java/util/logging/Logger.java 2017-03-20 11:58:09.000000000 +0000 +++ new/src/java.logging/share/classes/java/util/logging/Logger.java 2017-03-20 11:58:09.000000000 +0000 @@ -645,11 +645,19 @@ return Boolean.valueOf(s); } } + + private static Class checkCaller(Class caller) { + if (caller == null) { + throw new IllegalCallerException("no caller frame"); + } + return caller; + } - private static Logger demandLogger(String name, String resourceBundleName, Class caller) { + private static Logger demandLogger(String name, String resourceBundleName, + Class caller) { LogManager manager = LogManager.getLogManager(); if (!SystemLoggerHelper.disableCallerCheck) { - if (isSystem(caller.getModule())) { + if (isSystem(checkCaller(caller).getModule())) { return manager.demandSystemLogger(name, resourceBundleName, caller); } } @@ -684,6 +692,9 @@ * or javax.swing * @return a suitable Logger * @throws NullPointerException if the name is null. + * @throws IllegalCallerException if there is no caller frame, i.e. + * when this {@code getLogger} method is called from JNI + * and there is no Java frame on the stack. */ // Synchronization is not required here. All synchronization for @@ -700,7 +711,7 @@ // would throw an IllegalArgumentException in the second call // because the wrapper would result in an attempt to replace // the existing "resourceBundleForFoo" with null. - return Logger.getLogger(name, Reflection.getCallerClass()); + return Logger.getLogger(name, checkCaller(Reflection.getCallerClass())); } /** @@ -761,13 +772,17 @@ * {@code resourceBundleName} is {@code null} but the named * logger has a resource bundle set. * @throws NullPointerException if the name is null. + * @throws IllegalCallerException if there is no caller frame, i.e. + * when this {@code getLogger} method is called from JNI + * and there is no Java frame on the stack. */ // Synchronization is not required here. All synchronization for // adding a new Logger object is handled by LogManager.addLogger(). @CallerSensitive public static Logger getLogger(String name, String resourceBundleName) { - return Logger.getLogger(name, resourceBundleName, Reflection.getCallerClass()); + return Logger.getLogger(name, resourceBundleName, + checkCaller(Reflection.getCallerClass())); } /** @@ -869,6 +884,9 @@ * @return a newly created private Logger * @throws MissingResourceException if the resourceBundleName is non-null and * no corresponding resource can be found. + * @throws IllegalCallerException if there is no caller frame, i.e. + * when this {@code getLogger} method is called from JNI + * and there is no Java frame on the stack. */ // Synchronization is not required here. All synchronization for @@ -878,7 +896,7 @@ LogManager manager = LogManager.getLogManager(); // cleanup some Loggers that have been GC'ed manager.drainLoggerRefQueueBounded(); - final Class callerClass = Reflection.getCallerClass(); + final Class callerClass = checkCaller(Reflection.getCallerClass()); final Module module = callerClass.getModule(); Logger result = new Logger(null, resourceBundleName, module, manager, false);