title: NullPointerException in weblogic's DOMFactoryProperties when parsing an XML document under Tomcat
body: <p>I'm trying to parse an XML and getting a weirdest <code>NullPointerException</code> I've ever seen. Here's the stack trace:</p>
  
  <pre><code>java.lang.NullPointerException
      at java.util.Hashtable.put(Hashtable.java:399)
      at weblogic.xml.jaxp.DOMFactoryProperties.&lt;init&gt;(DOMFactoryProperties.java:44)
      at weblogic.xml.jaxp.DOMFactoryProperties.clone(DOMFactoryProperties.java:114)
      at weblogic.xml.jaxp.RegistryDocumentBuilderFactory.newDocumentBuilder(RegistryDocumentBuilderFactory.java:140)
      at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2DOM.createDocument(SAX2DOM.java:324)
      at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2DOM.&lt;init&gt;(SAX2DOM.java:84)
      at com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputHandlerFactory.getSerializationHandler(TransletOutputHandlerFactory.java:187)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(TransformerImpl.java:392)
      at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerHandlerImpl.setResult(TransformerHandlerImpl.java:137)
      at com.sun.xml.bind.v2.runtime.unmarshaller.DomLoader$State.&lt;init&gt;(DomLoader.java:74)
      at com.sun.xml.bind.v2.runtime.unmarshaller.DomLoader.startElement(DomLoader.java:113)
      at com.sun.xml.bind.v2.runtime.unmarshaller.ProxyLoader.startElement(ProxyLoader.java:55)
      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:455)
      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:433)
      at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
      at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
      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.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
      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 weblogic.xml.jaxp.WebLogicXMLReader.parse(WebLogicXMLReader.java:133)
      at weblogic.xml.jaxp.RegistryXMLReader.parse(RegistryXMLReader.java:173)
      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:211)
      at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184)
      at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
      at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:105)
      at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:584)
      at org.springframework.oxm.jaxb.Jaxb2Marshaller.unmarshal(Jaxb2Marshaller.java:571)
  </code></pre>
  
  <p>Firstly, it only happens when my app is deployed under Tomcat (I'm using weblogic client JAR to connect to external weblogic JMS queues). I could not reproduce it in my tests outside of Tomcat. So I suspect some class loader weirdness or something.</p>
  
  <p>Secondly, I tried to decompile <code>DOMFactoryProperties</code> class and here's a constructor that's causing that NPE:</p>
  
  <pre><code>public class DOMFactoryProperties
  {
    public static String COALESCING = "Coalescing";
    public static String EXPANDENTITYREFERENCES = "ExpandEntityReferences";
    public static String IGNORINGCOMMENTS = "IgnoringComments";
    public static String IGNORINGELEMENTCONTENTWHITESPACE = "IgnoringElementContentWhitespace";
    public static String NAMESPACEAWARE = "Namespaceaware";
    public static String VALIDATING = "Validating";
  
    public static String SCHEMA = "Schema";
  
    public static String XINCL = "XIncludeAware";
    private Hashtable factoryProperties;
    private Set facPropertySettingMarks;
    private LinkedHashMap attributes;
  
    public DOMFactoryProperties()
    {
      this.factoryProperties = new Hashtable();
      this.factoryProperties.put(COALESCING, Boolean.FALSE);
      this.factoryProperties.put(EXPANDENTITYREFERENCES, Boolean.TRUE);
      this.factoryProperties.put(IGNORINGCOMMENTS, Boolean.FALSE);
      this.factoryProperties.put(IGNORINGELEMENTCONTENTWHITESPACE, Boolean.FALSE);
      this.factoryProperties.put(NAMESPACEAWARE, Boolean.FALSE);
      this.factoryProperties.put(VALIDATING, Boolean.FALSE);
      this.factoryProperties.put(XINCL, Boolean.FALSE);
  
      this.facPropertySettingMarks = new HashSet();
  
      this.attributes = new LinkedHashMap();
    }
  
  //...
  }
  </code></pre>
  
  <p>It's failing on the line <code>this.factoryProperties.put(COALESCING, Boolean.FALSE);</code>. The only cause for that could be <code>null</code> value in <code>COALESCING</code>, but unless some other class is setting that to <code>null</code> (as it is <code>public static</code> for some reason) from outside I don't see why it can be <code>null</code>.</p>
  
  <p>Any idea?</p>
  
  <p><strike>Is there any way to tell Spring's <code>Jaxb2Marshaller</code> to not use XML reader from weblogic?</strike></p>
  
  <p><strong>UPDATE</strong>: To make things worse this is not even always reproducible under Tomcat for the same XML. Sometimes it works, sometimes it doesn't.</p>
  
  <p><strong>UPDATE2</strong>: Debug shows that <code>weblogic.xml.jaxp.DOMFactoryProperties.COALESCING</code> is indeed <code>null</code>. But why?</p>
  
  <p><strong>UPDATE3</strong>: It looks like I can tell which implementation of <code>SAXParserFactory</code> to use by setting <code>javax.xml.parsers.SAXParserFactory</code> system property to <code>com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl</code> (platform default). The other question still remains.</p>