Workaround for Tomcat 9.0.46 (bug 65308) - NPE in JNDIRealm

Since you already did the heavy-lifting of finding a patch, the easiest "workaround" is to patch the class affected by the bug.

You just need to:

  1. Download the patched JNDIRealm.java file,
  2. Compile it against your Tomcat's jars:
javac -cp '/path/to/tomcat/lib/*:/path/to/tomcat/bin/*' JNDIRealm.java
  1. Put the generated class files in $CATALINA_BASE/lib/org/apache/catalina/realm. Due to the way the common loader is configured, the class files will override the corresponding classes in the catalina.jar.