Mantis - Resin
Viewing Issue Advanced Details
2286 major always 01-03-08 13:36 01-03-08 13:40
atifmk  
ferg  
normal  
closed 3.1.3  
fixed  
none    
none 3.1.5  
0002286: NullPointerException in DomBuilder class
There is bug in com.caucho.xml.DomBuilder class that result in NPE at runtime while parsing the XML/XSL documents with namespaces. The bug is in the startPrefixMapping(String prefix, String url) method at line 178. If does a check for the empty prefix without considering that the prefix can be null. An example of this from the com.caucho.xsl.XslWriter class at line 1168:

_xmlWriter.startPrefixMapping(null, topUrl);

It's calling the startPrefixMapping(...) method with null prefix and results in NPE.

The bug in DomBuilder class can very easily be fixed by following implemention of the method:

  public void startPrefixMapping(String prefix, String url)
  {
    if (_node == null || _node == _top)
      _doc.addNamespace(prefix, url);

    if (prefix == null || prefix.equals("")) {
      _prefixNames.add(new QName(null, "xmlns", XmlParser.XMLNS));
      _prefixValues.add(url);
    }
    else {
      _prefixNames.add(new QName("xmlns", prefix, XmlParser.XMLNS));
      _prefixValues.add(url);
    }
  }

It does a check for null before doing a check for empty string. I am also attaching the DomBuilder.java with above changes in it.
 DOMBuilder.java [^] (14,414 bytes) 01-03-08 13:36

There are no notes attached to this issue.