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

NPE may be thrown when xsltc select a non-existing node after JDK-8062518

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: xml
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b80

      Backports

        Description

        After JDK-8062518, the following test code will throw NPE.

        TestTrans.java
        import java.io.File;
        import javax.xml.transform.Transformer;
        import javax.xml.transform.TransformerFactory;
        import javax.xml.transform.stream.StreamResult;
        import javax.xml.transform.stream.StreamSource;

        public class TestTrans {
            public static void main(String[] args) throws Exception {
                Transformer transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(new File("librarySet01.xsl")));

                transformer.transform(new StreamSource(new File("librarySet01.xml")), new StreamResult("test1.out"));
            }
        }


        librarySet01.xsl :
        <?xml version="1.0"?>
        <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
            xmlns:set="http://exslt.org/sets"
            exclude-result-prefixes="set">
        <xsl:output method="xml" encoding="UTF-8" indent="yes" />

        <xsl:template match="/">
          <out>
            <test desc="the second should be empty, but not null">
              <xsl:copy-of select="set:leading(/doc/*, /doc/non-existing)"/>
            </test>
          </out>
        </xsl:template>

        </xsl:stylesheet>


        librarySet01.xml:
        <?xml version="1.0" encoding="UTF-8"?>
        <doc>
          <num>1</num>
          <str>a</str>
          <num>2</num>
        </doc>


        Program output:
        java TestTrans
        ERROR: ''
        Exception in thread "main" javax.xml.transform.TransformerException: java.lang.NullPointerException
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:754)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:359)
        at TestTrans.main(TestTrans.java:16)
        Caused by: java.lang.NullPointerException
        at com.sun.org.apache.xalan.internal.lib.ExsltSets.leading(ExsltSets.java:63)
        at librarySet01.template$dot$0()
        at librarySet01.applyTemplates()
        at librarySet01.transform()
        at com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet.transform(AbstractTranslet.java:619)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:747)
        ... 2 more
        ---------
        java.lang.NullPointerException
        at com.sun.org.apache.xalan.internal.lib.ExsltSets.leading(ExsltSets.java:63)
        at librarySet01.template$dot$0()
        at librarySet01.applyTemplates()
        at librarySet01.transform()
        at com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet.transform(AbstractTranslet.java:619)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:747)
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:359)
        at TestTrans.main(TestTrans.java:16)


        In XSL, select /doc/non-existing shoud returns an empty nodelist instance, but returns null actually, that causes NPE.

          Issue Links

            Activity

            Hide
            fyuan Frank Yuan added a comment -
            I believe the attached test.diff can fix this issue. However, interface com.sun.org.apache.xalan.internal.xsltc.DOM doesn't state the particular definition of makeNodeList, e.g. may this method return null or not. In com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl, makeNodeList(int index) may return null, but makeNodeList(DTMAxisIterator iter) will never return null, this represent the inconsistence of the design.
            Show
            fyuan Frank Yuan added a comment - I believe the attached test.diff can fix this issue. However, interface com.sun.org.apache.xalan.internal.xsltc.DOM doesn't state the particular definition of makeNodeList, e.g. may this method return null or not. In com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl, makeNodeList(int index) may return null, but makeNodeList(DTMAxisIterator iter) will never return null, this represent the inconsistence of the design.
            Hide
            joehw Joe Wang added a comment -
            I see. In that case, you may also simply call return new DTMAxisIterNodeList(null, null); to create an empty NodeList, right?

            Could you put together a fix?

            Thanks.
            Show
            joehw Joe Wang added a comment - I see. In that case, you may also simply call return new DTMAxisIterNodeList(null, null); to create an empty NodeList, right? Could you put together a fix? Thanks.
            Show
            fyuan Frank Yuan added a comment - http://cr.openjdk.java.net/~fyuan/8133924/webrev.00/
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/dev/jaxp/rev/7c045de70a66
            User: joehw
            Date: 2015-08-26 17:16:28 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jaxp/rev/7c045de70a66 User: joehw Date: 2015-08-26 17:16:28 +0000
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk9/jdk9/jaxp/rev/7c045de70a66
            User: lana
            Date: 2015-09-01 20:26:48 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jaxp/rev/7c045de70a66 User: lana Date: 2015-09-01 20:26:48 +0000

              People

              • Assignee:
                fyuan Frank Yuan
                Reporter:
                fyuan Frank Yuan
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: