JDK-8177136 : Caller sensitive method System::getLogger should specify what happens if there is no caller on the stack.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.logging
  • Affected Version: 9
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2017-03-20
  • Updated: 2019-03-28
  • Resolved: 2017-03-29
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10 JDK 9
10Fixed 9 b164Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
Caller sensitive methods System.getLogger(name) and System.getLogger(name, resourceBundle) currently throw an undocumented NullPointerException if they are called from JNI and there is no Java frame on the stack. These methods are specified to call LoggerFinder to obtain a logger, which requires the module of the caller class.
When there is no java frame on the stack, then the caller information cannot be obtained and there is not enough context to know which module would be appropriate in this case. 
The NullPointerException should be documented - or another more specific exception should be thrown (and documented) in this case.

Note: should a JNI attached thread need to obtain a System::Logger it can do so by two other means:

    a) use an auxiliary class that will implicitly be identified as the caller. The module given to the LoggerFinder will then be the auxillary class module.
    or b) access the system LoggerFinder instance (LoggerFinder.getLoggerFinder()) and obtain a logger from it.

Note however that b) may force the eager initialization of the underlying logging system.
Comments
I've added jdk9-fix-yes to this issue, only because it involves a small spec change to a new API. If this were an implementation only change then it would be hard to justify as a P2. Also there are many @CS methods in the JDK that throw NPE when invoked from a native thread that doesn't have any java frames on the stack - this is something we should sort out early in JDK 10.
23-03-2017

Fix Request System.getLogger(String) and System.getLogger(String,ResourceBundle) are specified to obtain a logger from System.LoggerFinder, passing the module of the class that called System.getLogger. However, the specification doesn't say what happens if there is no caller frame on the stack, as can be the case if these methods are called directly from a JNI attached thread. Currently these methods will throw an undocumented NullPointerException when that happens. The proposal is to throw IllegalCallerException instead, and make it clear in the specification that calling System.getLogger in such a context is not a supported use case. Because these methods are new in JDK 9 then it is important to tighten the specification and make this change in JDK 9. Proposed fix: http://cr.openjdk.java.net/~dfuchs/webrev_8177136/webrev.04/ Review Thread: http://mail.openjdk.java.net/pipermail/core-libs-dev/2017-March/046900.html Alan Bateman, Mandy Chung, Brent Christian, and David Holmes have provided feedback. Risk of the fix: low (trivial) Testing: existing tests will cover the regular usage. new tests may be added as part of JDK-8177155.
23-03-2017

JDK-8177325 is logged to track the use of @CallerSensitive in java.util.logging
21-03-2017

Throwing NullPointerException is confusing and makes it look like there is a bug in the implementation. In truth, these method are @CallerSensitive, and therefore should not be called in a context where the caller cannot be determined. Therefore, I believe the right thing to do is to throw IllegalCallerException and document this.
21-03-2017

Review started: http://mail.openjdk.java.net/pipermail/core-libs-dev/2017-March/046868.html
20-03-2017