Jeff Thomas created XALANJ-2783:
-----------------------------------

             Summary: TransformerFactory newTransformer with XSLT Source throws 
exception when expecting java object parameter
                 Key: XALANJ-2783
                 URL: https://issues.apache.org/jira/browse/XALANJ-2783
             Project: XalanJ2
          Issue Type: Bug
      Security Level: No security risk; visible to anyone (Ordinary problems in 
Xalan projects.  Anybody can view the issue.)
          Components: Xalan, XSLTC
    Affects Versions: 2.7.3
         Environment: Java JRE 17 (Temurin) embedded Xalan
            Reporter: Jeff Thomas


We have recently moved from the external Xalan JAR to the Xalan packaged with 
JRE 17.  I understand this is implicitly a move from the XSLTJ to the XSLTC.

Now we are having problems with previously working XSLT that called non-static 
java methods.

In our scenario, we are instantiating the Transformer with a call to the 
{{TransformerFactory#newTransformer(StreamSource)}}

Starting with the example in the comments of XALANJ-180 that example works 
fine.  The 'dateObject' variable is created *within* the XSLT and causes no 
problems.
{code:java}
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:xalan="http://xml.apache.org/xalan";
                xmlns:java="http://xml.apache.org/xalan/java";
                exclude-result-prefixes="xalan java"
                version="1.0">
  
  <xsl:template match="/">
    <xsl:variable name="date" select="java:java.util.Date.new()"/>
    <p>Date <xsl:value-of select="$date"/></p>
    <xsl:variable name="result" select="java:getTime($date)" />
    <p>date getTime() = <xsl:value-of select="$result"/></p>
  </xsl:template>
  
</xsl:stylesheet> {code}
 

If however, the java object is being passed as a parameter, an exception is 
thrown that the parameter is not a valid object reference.
{code:java}
javax.xml.transform.TransformerException: The first argument to the non-static 
Java function 'getTime' is not a valid object reference.
    at 
java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.passErrorsToListener(TransformerFactoryImpl.java:877)
 ~[?:?]
    at 
java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:1084)
 ~[?:?]
    at 
java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:834)
 ~[?:?] {code}
Sample XSLT:
{code:java}
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:xalan="http://xml.apache.org/xalan";
                xmlns:java="http://xml.apache.org/xalan/java";
                exclude-result-prefixes="xalan java"
                version="1.0">

  <xsl:param name="date" select="java:java.util.Date.new()"/>

  <xsl:template match="/">
    <p>Date <xsl:value-of select="$date"/></p>
    <xsl:variable name="result" select="java:getTime($date)" />
    <p>date getTime() = <xsl:value-of select="$result"/></p>
  </xsl:template>

</xsl:stylesheet>{code}
It is not possible to pass a parameter "date" to the transformer until *after* 
it has been instantiated.
 
But here during instantiation the error is occurring *before* any 
transformation is being applied.
 
How can I instantiate the transformer as above without running into this 
exception?

Is this a bug? 
 
NOTE: I am not a XSLT / Xalan expert - just tasked with fixing this problem 
with very old code - so sorry if anything about my question is "off" :P.



--
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

Reply via email to