8032909: XSLT string-length returns incorrect length when string includes complementary chars
authoraefimov
Fri, 21 Feb 2014 16:57:21 +0400
changeset 23092 64904fcdd0ee
parent 23091 bbbe8f840a26
child 23093 d27bb191657e
child 23094 681fdd03de81
8032909: XSLT string-length returns incorrect length when string includes complementary chars Reviewed-by: joehw, dfuchs
jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/StringLengthCall.java
jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java
--- 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
 }