Bug 65684 - NullPointerException in Tomcat's ClassLoaderLogManager when logging.properties is empty
Summary: NullPointerException in Tomcat's ClassLoaderLogManager when logging.propertie...
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: JULI (show other bugs)
Version: 8.5.71
Hardware: Other Linux
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-16 11:13 UTC by roscoe
Modified: 2021-11-24 18:09 UTC (History)
0 users



Attachments
Servlet to test the issue. (1.36 KB, text/plain)
2021-11-16 11:13 UTC, roscoe
Details

Note You need to log in before you can comment on or make changes to this bug.
Description roscoe 2021-11-16 11:13:21 UTC
Created attachment 38092 [details]
Servlet to test the issue.

I am using Tomcat 8.5.71 in a docker container.

I followed the instructions from https://logging.apache.org/log4j/2.x/log4j-appserver/index.html in order to setup log4j2 logging configuration.

Additionally, I removed every entry from file conf/loggging.properties and added a comment "# see: log4j2/conf/log4j2-tomcat.xml" to guide other maintainer to the log4j2 xml.

In one webapp some business logic is done in a separate thread by using the join-fork-threadpool. At some point, jdbc comes into play and the mssql.jdbc:8.4.1 driver asks for a logging property.


    static boolean isActivityTraceOn() {
        LogManager lm = LogManager.getLogManager();
        String activityTrace = lm.getProperty("com.microsoft.sqlserver.jdbc.traceactivity");
        return "on".equalsIgnoreCase(activityTrace);
    }

But a NPE is thrown in ClassLoaderLogManager.

2021-11-04T11:08:27,233 ERROR [ForkJoinPool.commonPool-worker-0] 
java.lang.NullPointerException: null
	at org.apache.juli.ClassLoaderLogManager.findProperty(ClassLoaderLogManager.java:311) ~[tomcat-juli.jar:8.5.71]
	at org.apache.juli.ClassLoaderLogManager.getProperty(ClassLoaderLogManager.java:291) ~[tomcat-juli.jar:8.5.71]
	at com.microsoft.sqlserver.jdbc.Util.isActivityTraceOn(Util.java:778) ~[mssql-jdbc-8.4.1.jre8.jar:?]


I debugged into the method org.apache.juli.ClassLoaderLogManager#findProperty.
In my case, the ContextClassLoader is null and info.props.isEmpty() yields true. 

I would suggest to check if classLoader is null in the if condition in line 310 to avoid the NPE.

My workaround at the moment is to remove the conf/loggging.properties entirely. Then everything works as expected.

I attached a servlet to test the issue.
Comment 1 Mark Thomas 2021-11-24 18:09:12 UTC
Thanks for the report.

This has been fixed and the fix will be included in:
- 10.1.x for 10.1.0-M8 onwards
- 10.0.x for 10.0.14 onwards
- 9.0.x for 9.0.56 onwards
- 8.5.x for 8.5.74 onwards