[ https://issues.apache.org/jira/browse/XALANJ-2782?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Mukul Gandhi reassigned XALANJ-2782: ------------------------------------ Assignee: Mukul Gandhi > NullPointerException in XSLT 3 code > ----------------------------------- > > Key: XALANJ-2782 > URL: https://issues.apache.org/jira/browse/XALANJ-2782 > Project: XalanJ2 > Issue Type: Bug > Security Level: No security risk; visible to anyone(Ordinary problems in > Xalan projects. Anybody can view the issue.) > Components: transformation, Xalan, Xalan-CmdLine > Affects Versions: The Latest Development Code > Environment: Windows 11, Adoptium Java 8.422 > Reporter: Martin Honnen > Assignee: Mukul Gandhi > Priority: Major > Attachments: nullpointer-exception-input-sample1.xml, > nullpointer-exception-sample1.xsl > > > This is a bug report on the XSLT 3 development branch of Apache Xalan. > > When I run the following XSLT code > > > {code:java} > <?xml version="1.0" encoding="utf-8"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="3.0" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > exclude-result-prefixes="xs"> > > <xsl:template match="data"> > <xsl:copy> > <xsl:value-of select="if (normalize-space()) then . else 'default'"/> > </xsl:copy> > </xsl:template> > <xsl:output method="xml" indent="no"/> > <xsl:template match="@* | node()"> > <xsl:copy> > <xsl:apply-templates select="@* | node()"/> > </xsl:copy> > </xsl:template> > <xsl:template match="/"> > <xsl:copy> > <xsl:apply-templates/> > <xsl:comment>Run with <xsl:value-of > select="system-property('xsl:vendor')"/> at <xsl:value-of > select="current-dateTime()"/></xsl:comment> > </xsl:copy> > </xsl:template> > </xsl:stylesheet> > {code} > > against the XML input > > {code:java} > <root> > <item> > <data>foo</data> > </item> > <item> > <data></data> > </item> > </root>{code} > > (from the command line with e.g. > {noformat} > & 'C:\Program Files\Eclipse Adoptium\jdk-8.0.422.5-hotspot\bin\java.exe' -cp > 'build\xalan.jar;build\serializer.jar;lib\bcel-6.7.0.jar;lib\brazil-2.1.jar;lib\bsf.jar;lib\commons-logging-1.2.jar;lib\javaee-api-5.0-2.jar;lib\javaee-api-5.0-2.jar;lib\regexp.jar;lib\rhino-1.7.14.jar;lib\runtime.jar;lib\servlet-api-2.5.jar;lib\xpath31_types.jar;lib\endorsed\xercesImpl.jar;lib\endorsed\xml-apis.jar' > org.apache.xalan.xslt.Process -in > ..\..\OneDrive\Documents\xslt\blog-xslt-3-by-example\xalan-xslt3-tests\nullpointer-exception-input-sample1.xml > -xsl > ..\..\OneDrive\Documents\xslt\blog-xslt-3-by-example\xalan-xslt3-tests\nullpointer-exception-sample1.xsl > {noformat} > > ) > I get an error (NullPointerException) > > {noformat} > file:///C:/Users/marti/IdeaProjects/xalan-java/../../OneDrive/Documents/xslt/blog-xslt-3-by-example/xalan-xslt3-tests/nullpointer-exception-sample1.xsl; > Zeilennummer22; Spaltennummer15; java.lang.NullPointerException{noformat} > > The code runs fine with Saxon HE 12 as shown above or even with Xalan with no > change to that line 22 but a rewrite and avoidance of the `if` expression by > using a match pattern e.g. > > > {code:java} > <?xml version="1.0" encoding="utf-8"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > version="3.0" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > exclude-result-prefixes="xs"> > > <xsl:template match="data[not(normalize-space())]"> > <xsl:copy>default</xsl:copy> > </xsl:template> > <xsl:output method="xml" indent="no"/> > <xsl:template match="@* | node()"> > <xsl:copy> > <xsl:apply-templates select="@* | node()"/> > </xsl:copy> > </xsl:template> > <xsl:template match="/"> > <xsl:copy> > <xsl:apply-templates/> > <xsl:comment>Run with <xsl:value-of > select="system-property('xsl:vendor')"/> at <xsl:value-of > select="current-dateTime()"/></xsl:comment> > </xsl:copy> > </xsl:template> > </xsl:stylesheet> > {code} > > > -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@xalan.apache.org For additional commands, e-mail: dev-h...@xalan.apache.org