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

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 9
    • 9
    • xml
    • 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.

        Attachments

          Issue Links

            Activity

              People

                fyuan Frank Yuan (Inactive)
                fyuan Frank Yuan (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: