Bug 50027 - NullPointerException if context.xml is present with <Resource>
NullPointerException if context.xml is present with <Resource>
Status: RESOLVED FIXED
Product: Tomcat 7
Classification: Unclassified
Component: Catalina
7.0.2
PC Windows Vista
: P3 regression (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2010-09-29 13:02 UTC by Flávio Henrique
Modified: 2010-10-08 17:46 UTC (History)
0 users



Attachments
server.xml that crashes tomcat 7.0.2 (2.89 KB, application/x-zip-compressed)
2010-10-08 11:27 UTC, Flávio Henrique
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Flávio Henrique 2010-09-29 13:02:53 UTC
If you deploy a WAR with contex.xml in META-INF and the context.xml has <Resource> tag, Tomcat don´t boot and gives this error:

java.lang.NullPointerException
	at org.apache.catalina.core.StandardContext.getObjectKeyPropertiesNameOnly(StandardContext.java:5570)
	at org.apache.catalina.core.StandardContext.setNamingResources(StandardContext.java:1757)
	at org.apache.catalina.core.StandardContext.getNamingResources(StandardContext.java:1735)
	at org.apache.catalina.startup.SetNextNamingRule.end(SetNextNamingRule.java:99)
	at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1058)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:180)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1343)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
	at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1544)
	at org.apache.catalina.startup.Catalina.load(Catalina.java:524)
	at org.apache.catalina.startup.Catalina.load(Catalina.java:560)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:260)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
29/09/2010 13:50:37 org.apache.catalina.startup.Catalina load
AVISO: Catalina.start using conf/server.xml: 
java.lang.NullPointerException
	at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2688)
	at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2714)
	at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1061)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:180)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1343)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
	at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1544)
	at org.apache.catalina.startup.Catalina.load(Catalina.java:524)
	at org.apache.catalina.startup.Catalina.load(Catalina.java:560)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:260)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.NullPointerException
	at org.apache.catalina.core.StandardContext.getObjectKeyPropertiesNameOnly(StandardContext.java:5570)
	at org.apache.catalina.core.StandardContext.setNamingResources(StandardContext.java:1757)
	at org.apache.catalina.core.StandardContext.getNamingResources(StandardContext.java:1735)
	at org.apache.catalina.startup.SetNextNamingRule.end(SetNextNamingRule.java:99)
	at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1058)
	... 20 more
29/09/2010 13:50:37 org.apache.tomcat.util.digester.SetPropertiesRule begin
AVISO: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:bestforkprime' did not find a matching property.
29/09/2010 13:50:37 org.apache.tomcat.util.digester.Digester endElement
GRAVE: End event threw exception
java.lang.NullPointerException
	at org.apache.catalina.core.StandardContext.getObjectKeyPropertiesNameOnly(StandardContext.java:5570)
	at org.apache.catalina.core.StandardContext.setNamingResources(StandardContext.java:1757)
	at org.apache.catalina.core.StandardContext.getNamingResources(StandardContext.java:1735)
	at org.apache.catalina.startup.SetNextNamingRule.end(SetNextNamingRule.java:99)
	at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1058)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:180)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1343)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
	at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1544)
	at org.apache.catalina.startup.Catalina.load(Catalina.java:524)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:573)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:415)
29/09/2010 13:50:37 org.apache.catalina.startup.Catalina load
AVISO: Catalina.start using conf/server.xml: 
java.lang.NullPointerException
	at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2688)
	at org.apache.tomcat.util.digester.Digester.createSAXException(Digester.java:2714)
	at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1061)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601)
	at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:180)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1343)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
	at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1544)
	at org.apache.catalina.startup.Catalina.load(Catalina.java:524)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:573)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:415)
Caused by: java.lang.NullPointerException
	at org.apache.catalina.core.StandardContext.getObjectKeyPropertiesNameOnly(StandardContext.java:5570)
	at org.apache.catalina.core.StandardContext.setNamingResources(StandardContext.java:1757)
	at org.apache.catalina.core.StandardContext.getNamingResources(StandardContext.java:1735)
	at org.apache.catalina.startup.SetNextNamingRule.end(SetNextNamingRule.java:99)
	at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1058)
	... 20 more
29/09/2010 13:50:37 org.apache.catalina.startup.Catalina start
GRAVE: Cannot start server. Server instance is not configured.

Here is my contex.xml OBS: some values were replaced with XXXX 


<?xml version="1.0" encoding="UTF-8"?>
<Context privileged="true" reloadable="true">

	<WatchedResource>WEB-INF/web.xml</WatchedResource>
	<WatchedResource>META-INF/context.xml</WatchedResource>
	
	<Resource name="jdbc/bestfork" auth="Container"
		type="com.mchange.v2.c3p0.ComboPooledDataSource" factory="org.apache.naming.factory.BeanFactory"
		user="xxx" password="xxxx" driverClass="org.postgresql.Driver"
		jdbcUrl="jdbc:postgresql://localhost:5432/xxxxx" minPoolSize="5"
		maxPoolSize="30" acquireIncrement="5" idleConnectionTestPeriod="100"
		maxIdleTime="30"/>

	<Resource name="mail/Session" auth="Container" type="javax.mail.Session"
		mail.smtp.host="xxxx" mail.smtp.auth="true"
		username="xxx" password="xxx"
		mail.user="xxxx" mail.password="xxxx"
		mail.smtp.port="587" mail.transport.protocol="smtp" mail.debug="true" />

	<Realm className="org.apache.catalina.realm.JDBCRealm"
		driverName="org.postgresql.Driver" connectionURL="jdbc:postgresql://localhost:5432/xxxx"
		connectionName="xxxx" connectionPassword="xxxx" userTable="usuario"
		userNameCol="usuario_cpf" userCredCol="usuario_senha" userRoleTable="usuario_papel"
		roleNameCol="papel_nome" digest="MD5" />
				

</Context>
Comment 1 Flávio Henrique 2010-10-03 08:42:40 UTC
I Solved the problem (but I still thing that this is a bug in tomcat), let me explain with more detail, because I was to anxious do report the bug.

The problem happens when you have context <Resource> tag in SERVER.XML. The problem doesn´t happens with you have a new <Realm> inside SERVER.XML.

How I solved the problem:

1 - instead of inserting context information in SERVER.XML, I created myApplication.xml in conf\Catalina\localhost\myApplication.xml.

The first approach work on tomcat 6, but not in tomcat 7.
By the way, I solved the problem, I am afraid that the presence of additional context information in SERVER.XML crashes tomcat 7.

Can anyone confirm if it´s a bug?
Comment 2 Tim Whittington 2010-10-08 04:22:48 UTC
Can you attach a server.xml that actually breaks - it's not clear from your report what you're actually having problems with.
Comment 3 Flávio Henrique 2010-10-08 11:27:39 UTC
Created attachment 26143 [details]
server.xml that crashes tomcat 7.0.2

Server.xml that crash tomcat 7.02. Only added <Context> information inside <Host>.
Comment 4 Flávio Henrique 2010-10-08 11:29:28 UTC
Here is the server.xml (zipped).
I only added to the default server.xml <Context> inside <Host>

Thanks
Comment 5 Mark Thomas 2010-10-08 17:46:33 UTC
Thanks for the example. That made it much clearer.

This has been fixed in trunk and will be included in 7.0.4 onwards.