aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVlad Dumitrescu <[email protected]>2011-10-20 14:29:59 +0200
committerHenrik Nord <[email protected]>2011-11-24 10:22:57 +0100
commita30445c2a40ebc0e449c7b7605fdc202c48e00d8 (patch)
treefcdd07f4aaa4d9d6931f5fc65ffd70244a97f757
parentf545894e96d5898285eee8dce812c885cf208fb7 (diff)
downloadotp-a30445c2a40ebc0e449c7b7605fdc202c48e00d8.tar.gz
otp-a30445c2a40ebc0e449c7b7605fdc202c48e00d8.tar.bz2
otp-a30445c2a40ebc0e449c7b7605fdc202c48e00d8.zip
workaround for Java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6242664
Java 1.5 has a bug where detecting codepoint offsets in strings that are created by String.substring() gives wrong results. The new implementation uses a different method, avoinding the issue. The following code will crash without the fix: final String s = "abcdefg"; final String ss = s.substring(3, 6); final int[] cps = OtpErlangString.stringToCodePoints(ss);
-rw-r--r--lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangString.java17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangString.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangString.java
index 23734bf83b..2d3a5a5d1c 100644
--- a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangString.java
+++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangString.java
@@ -154,13 +154,16 @@ public class OtpErlangString extends OtpErlangObject implements Serializable,
* Unicode code points
*/
- public static int[] stringToCodePoints(final String s) {
- final int m = s.codePointCount(0, s.length());
- final int [] codePoints = new int[m];
- for (int i = 0, j = 0; j < m; i = s.offsetByCodePoints(i, 1), j++) {
- codePoints[j] = s.codePointAt(i);
- }
- return codePoints;
+ public static int[] stringToCodePoints(final String s) {
+ final int m = s.codePointCount(0, s.length());
+ final int[] codePoints = new int[m];
+ int j = 0;
+ for (int offset = 0; offset < s.length();) {
+ final int codepoint = s.codePointAt(offset);
+ codePoints[j++] = codepoint;
+ offset += Character.charCount(codepoint);
+ }
+ return codePoints;
}
/**