xml-xalan-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex (JIRA)" <xalan-...@xml.apache.org>
Subject [jira] Created: (XALANJ-2374) MethodResolver not handling CharSequence class conversion
Date Tue, 20 Mar 2007 18:58:32 GMT
MethodResolver not handling CharSequence class conversion
---------------------------------------------------------

                 Key: XALANJ-2374
                 URL: https://issues.apache.org/jira/browse/XALANJ-2374
             Project: XalanJ2
          Issue Type: Bug
         Environment: Windows Sun JRE 1.5.0.6 or higher
HPUnix JRE 1.5.0 or higher
            Reporter: Alex


When using Java extensions with StringBuffer class, the MethodResolver picks a method whose
argument types are not converted properly.   This was noticed in the new versions of JVM due
to the order at which they return all methods available for a given class.  Since the MethodResolver
scores the methods, the one with the lowest score wins.  However, the method chosen is different
depending on the order in which JVM returns the available methods.  In the later versions,
the StringBuffer.append(String) operation will actually find the StringBuffer.append(CharSequence)
instead.  This is ok but the "convert" method in the MethodResolver does not handle this type
and therefore generates a "Double" type.  This causes an "Argument Type Mismatch" exception
when the "append" method is called.  I have fixed the code by adding another "elseif" statement
in the "convert" function (see the CharSequence section):

    case XObject.CLASS_STRING:
        {
          if((javaClass == java.lang.String.class) ||
             (javaClass == java.lang.Object.class))
            return xobj.str();
          else if(javaClass == java.lang.CharSequence.class)
        	  return xobj.str();
          else if(javaClass == Character.TYPE)
          {
            String str = xobj.str();
            if(str.length() > 0)
              return new Character(str.charAt(0));
            else
              return null; // ??
          }
          else if(javaClass == Boolean.TYPE)
            return new Boolean(xobj.bool());
          else 
          {
            return convertDoubleToNumber(xobj.num(), javaClass);
          }
        }

The XSLT stylesheet that uses this code is the following:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xalan="http://xml.apache.org/xalan"
xmlns:lxslt="http://xml.apache.org/xslt" xmlns:my-ext="ext2" xmlns:java="http://xml.apache.org/xslt/java"
exclude-result-prefixes="java" extension-element-prefixes="my-ext">

	<xsl:template match="/">
		<xsl:variable name="Destination" select="java:java.lang.StringBuffer.new('ABC')"/>
		<xsl:variable name="Str" select="java:java.lang.String.new('DB')"/>

		<xsl:variable name="b3" select="java:append($Destination,$Str)"/>
		<output>
			<xsl:value-of select="java:toString($Destination)"/>
		</output>
	</xsl:template>
</xsl:stylesheet>



If the code change is not made, the following exception results (again, this is only in the
newer JVM versions as the older ones return the StringBuffer.append(String) before the StringBuffer.append(CharSequence)
and thus the correct method is found:



javax.xml.transform.TransformerException: java.lang.IllegalArgumentException: argument type
mismatch

	at org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction(ExtensionHandlerJavaPackage.java:403)

	at org.apache.xalan.extensions.ExtensionsTable.extFunction(ExtensionsTable.java:227)

	at org.apache.xalan.transformer.TransformerImpl.extFunction(TransformerImpl.java:460)

	at org.apache.xpath.functions.FuncExtFunction.execute(FuncExtFunction.java:196)

	at org.apache.xpath.XPath.execute(XPath.java:308)

	at org.apache.xalan.templates.ElemVariable.getValue(ElemVariable.java:323)

	at org.apache.xalan.templates.ElemVariable.execute(ElemVariable.java:291)

	at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2324)

	at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2147)

	at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1203)

	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:665)

	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1119)

	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1097)

	at com.exln.stylus.CXalanDriver.doProcessing(CXalanDriver.java:108)

	at com.exln.stylus.CProcessorDriver.process(CProcessorDriver.java:55)

Caused by: java.lang.IllegalArgumentException: argument type mismatch

	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.lang.reflect.Method.invoke(Unknown Source)

	at org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction(ExtensionHandlerJavaPackage.java:389)

	... 14 more

---------

java.lang.IllegalArgumentException: argument type mismatch

	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

	at java.lang.reflect.Method.invoke(Unknown Source)

	at org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction(ExtensionHandlerJavaPackage.java:389)

	at org.apache.xalan.extensions.ExtensionsTable.extFunction(ExtensionsTable.java:227)

	at org.apache.xalan.transformer.TransformerImpl.extFunction(TransformerImpl.java:460)

	at org.apache.xpath.functions.FuncExtFunction.execute(FuncExtFunction.java:196)

	at org.apache.xpath.XPath.execute(XPath.java:308)

	at org.apache.xalan.templates.ElemVariable.getValue(ElemVariable.java:323)

	at org.apache.xalan.templates.ElemVariable.execute(ElemVariable.java:291)

	at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2324)

	at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2147)

	at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1203)

	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:665)

	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1119)

	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1097)

	at com.exln.stylus.CXalanDriver.doProcessing(CXalanDriver.java:108)

	at com.exln.stylus.CProcessorDriver.process(CProcessorDriver.java:55)




-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org


Mime
View raw message