Fix for Tomcat 8 Examples WebApp NullPointerException


tl;dr:

In webapps/examples/META-INF/context.xml, change:

<Context allowLinking="true"/>

to

<Context>
  <Resources allowLinking="true" />
</Context>

I had just finished a fresh install of Tomcat 8 (yum install tomcat8) on my EC2 instance. I looked at my catalina.out log and saw this:

14-Sep-2016 18:48:54.625 WARNING [localhost-startStop-1] org.apache.catalina.startup.SetContextPropertiesRule.begin [SetContextPropertiesRule]{Context} Setting property 'allowLinking' to 'true' did not find a matching property.

14-Sep-2016 18:48:54.641 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
 org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/examples]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
        ...
Caused by: java.lang.NullPointerException
        at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:321)
        at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:182)
        ...

14-Sep-2016 18:48:54.642 SEVERE [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Error deploying web application directory /var/lib/tomcat8/webapps/examples
 java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/examples]]
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:729)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
        ...

The Examples WebApp from Tomcat was failing to deploy. I hadn't touched any of the config files.

It all starts with that first warning message: Setting property 'allowLinking' to 'true' did not find a matching property.. I did some digging and found that according to this migration guide, between Tomcat versions 7 and 8 some properties that used to be defined on the Context level now must defined on the Resources level. This includes allowLinking. Sure enough it we look at webapps/examples/META-INF/context.xml we see:

<Context allowLinking="true"/>

I guess Tomcat forgot to update their Examples WebApp for Tomcat 8. Easy enough to fix. Simply replace with:

<Context>
  <Resources allowLinking="true" />
</Context>

Restart Tomcat and check your logs. Everything should be working now.

How does this fix the NullPointerException? Well, I'm not sure exactly. If you look at the source around that line it is trying to load jars. I was pretty sure the two were connected when I read a comment on a bug about the same issue. When he mentioned the problem had something to do with loading jars and symlinks, I remembered that warning that was printed right before the stack trace.

Mike Moore

Read more posts by this author.

Austin, TX yo1.dog
comments powered by Disqus