Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6710755

DOMSerializerImpl.prepareForSerialization throws NPE

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.3.0
    • 5.0
    • xml
    • 1.3
    • x86
    • linux
    • Verified

        Run the following on JDK 5:

        ---%<---
        import javax.xml.parsers.DocumentBuilderFactory;
        import org.w3c.dom.Document;
        import org.w3c.dom.Element;
        import org.w3c.dom.ls.DOMImplementationLS;
        public class TestDOMSerializerImpl {
            public static void main(String[] args) throws Exception {
                Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
                Element el = doc.createElement("x");
                DOMImplementationLS ls = (DOMImplementationLS) doc.getImplementation().getFeature("LS", "3.0");
                System.out.println(ls.createLSSerializer().writeToString(el));
            }
        }
        ---%<---

        I get:

        ---%<---
        java version "1.5.0_15"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_15-b04)
        Java HotSpot(TM) Server VM (build 1.5.0_15-b04, mixed mode)

        Exception in thread "main" org.w3c.dom.ls.LSException: java.lang.NullPointerException
                at com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl.writeToString(DOMSerializerImpl.java:546)
                at TestDOMSerializerImpl.main(TestDOMSerializerImpl.java:10)
        ---%<---

        The lack of a proper stack trace is recorded in bug #6710741, but using a source debugger shows that the culprit is prepareForSerialization:

          next = node.getNextSibling();

        The bug appears to be fixed in JDK 6; perhaps the fix can be backported?

              joehw Joe Wang
              jglick Jesse Glick (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: