Bug 66184 - Null root logger level on Java 8
Summary: Null root logger level on Java 8
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: JULI (show other bugs)
Version: 8.5.x-trunk
Hardware: PC All
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-07-28 15:31 UTC by Piotr P. Karwasz
Modified: 2022-08-16 01:08 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Piotr P. Karwasz 2022-07-28 15:31:35 UTC
The constructor `java.util.logging.LogManager$RootLogger` in OpenJDK 8 no longer sets the log level. This causes the following test to fail:

    Logger current = ...;
    while (current.getLevel() == null && current.getParent() != null) {
        current = current.getParent();
    }
    assertNotNull(current.getLevel());

As far as I understand the `java.util.logging.Logger` contract forbids both `getLevel()` and `getParent()` to return a null value.

Steps to reproduce:

 * create an application with a `logging.properties` file without a `.level` property.
Comment 1 Christopher Schultz 2022-07-28 21:17:16 UTC
Sounds like a bug in Java, not Tomcat.

Do you have a stack trace from where Tomcat triggers this?
Comment 2 Piotr P. Karwasz 2022-07-29 05:41:47 UTC
Hi Christopher,

(In reply to Christopher Schultz from comment #1)
> Sounds like a bug in Java, not Tomcat.
> 
> Do you have a stack trace from where Tomcat triggers this?

The `LogManager` in JDK8 initializes the level of the root logger in `LogManager#ensureLogManagerInitialized()`, so it is not a Java bug:

https://github.com/openjdk/jdk8u/blob/3dca446d440e55cbb7dc3555392f4520ec9ff3bc/jdk/src/share/classes/java/util/logging/LogManager.java#L350

Tomcat's `ClassLoaderLogManager` creates additional "root" loggers (one per classloader) and:

 * if the classloader does not contain a `logging.properties` resource, its root logger becomes a child of its parent classloader root logger,
 * otherwise the root classloader remains without a parent and without a level.

I have submitted a PR with a test case:

https://github.com/apache/tomcat/pull/533

The lack of a `Level` object does not prevent JUL from working, since the (inaccessible) effective int level is computed correctly. However this causes problems in code that need to access the effective level like this one:

https://issues.apache.org/jira/browse/LOG4J2-3564
Comment 3 Mark Thomas 2022-08-16 01:08:44 UTC
Thanks for the bug report and the PR.

This has been fixed in:
- 10.1.x for 10.1.0-M18 onwards
- 10.0.x for 10.0.24 onwards
-  9.0.x for 9.0.66 onwards
-  8.5.x for 8.5.83 onwards