You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by tiberiu <ti...@hotmail.de> on 2008/04/25 18:20:50 UTC
java.lang.StringBuffer works nomore (Java 6)
java.lang.IllegalArgumentException
Hi All,
I got a strange error. A Code such:
<xsl:variable name="dummy" select="StringBuffer:append($str1,'Test')"/>
Crashes with
java.lang.IllegalArgumentException: argument type mismatch
java.lang.NullPointerException
It is quite surprising as I don't remember to change something (meaning java
version).
The error I obtained firstly in xalan2-4-1 and I could simulate it in xalan
2.7.0 and xalan 2.7.1
In the following are code samples from xalan 2.7.1
So, the start is jdk 1.6.0_03 (or 02 same results), I just downloaded a
xalan-2.7.1-bin.zip and added the *.jar found there to a Java Project.
A xsl Code such
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:StringBuffer="xalan://java.lang.StringBuffer"
exclude-result-prefixes="StringBuffer">
<xsl:output method="xml" encoding="ISO-8859-1"/>
<xsl:variable name="str1" select="StringBuffer:new()"/>
<xsl:template match="/">
<xsl:variable name="dummy" select="StringBuffer:append($str1,'Test')"/>
</xsl:template>
</xsl:stylesheet>
executed with a Xml Input (Code very similar with that from fop 0.20.5
ExampleXML2FO.convertXML2FO(File,File,File)) crashes on the line of
StringBuffer:append() with
java.lang.IllegalArgumentException: argument type mismatch and
java.lang.NullPointerException
Debugging the Problem, the Reason is the "bestMethod" chosen by
org.apache.xalan.extensions.MethodResolver
No idea why, the StringBuffer.append Method selected is one that has as
bestParamTypes
the following value: "interface java.lang.CharSequence"
Then in convertParams(argsIn, argsOut, bestParamTypes, exprContext) and
further in static Object convert(Object xsltObj, Class javaClass) there is
the following Code:
case XObject.CLASS_STRING:
{
if((javaClass == java.lang.String.class) ||
(javaClass == java.lang.Object.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);
}
}
// break; Unreachable
Well, in my case javaClass=="interface java.lang.CharSequence" so that the
Code executes convertDoubleToNumber()....
Finally one try to run StringBuffer.append() with a Double having NaN
value... yeap... that lead to throwing Exceptions.
Ok, a solution would be to add in first if a || javaClass ==
java.lang.CharSequence.class but my question is why exactly this problem
occurred...
Regards :)
--
View this message in context: http://www.nabble.com/java.lang.StringBuffer-works-nomore-%28Java-6%29-java.lang.IllegalArgumentException-tp16897184p16897184.html
Sent from the Xalan - J - Users mailing list archive at Nabble.com.