8032909: XSLT string-length returns incorrect length when string includes complementary chars
Reviewed-by: joehw, dfuchs
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/StringLengthCall.java Thu Feb 20 19:59:46 2014 -0800
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/StringLengthCall.java Fri Feb 21 16:57:21 2014 +0400
@@ -26,7 +26,7 @@
import java.util.Vector;
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
-import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
+import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
import com.sun.org.apache.bcel.internal.generic.InstructionList;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
@@ -51,7 +51,8 @@
il.append(methodGen.loadContextNode());
Type.Node.translateTo(classGen, methodGen, Type.String);
}
- il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_CLASS,
- "length", "()I")));
+ il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS,
+ "getStringLength",
+ "(Ljava/lang/String;)I")));
}
}
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java Thu Feb 20 19:59:46 2014 -0800
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java Fri Feb 21 16:57:21 2014 +0400
@@ -1660,5 +1660,14 @@
}
+ /**
+ * Utility method to calculate string-length as a number of code points,
+ * to avoid possible errors with string that contains
+ * complementary characters
+ */
+ public static int getStringLength(String str) {
+ return str.codePointCount(0,str.length());
+ }
+
//-- End utility functions
}