https://bz.apache.org/bugzilla/show_bug.cgi?id=65684

            Bug ID: 65684
           Summary: NullPointerException in Tomcat's ClassLoaderLogManager
                    when logging.properties is empty
           Product: Tomcat 8
           Version: 8.5.71
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: JULI
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ----

Created attachment 38092
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=38092&action=edit
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.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to