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

DOMSerializerImpl.prepareForSerialization throws NPE

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 1.3.0
    • Component/s: xml
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      1.3
    • CPU:
      x86
    • OS:
      linux
    • Verification:
      Verified

      Backports

        Description

        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?

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: