8080248: Coding regression in HKSCS charsets
authorsherman
Thu, 21 May 2015 15:42:30 -0700
changeset 30691 8b8579faebd4
parent 30690 f6d8413a278c
child 30692 1286226d1236
child 30806 6e9d62b1dbc3
8080248: Coding regression in HKSCS charsets Summary: to update the sp correctly when encoding supplementary characters Reviewed-by: martin
jdk/src/java.base/share/classes/sun/nio/cs/HKSCS.java
jdk/test/sun/nio/cs/TestStringCoding.java
--- a/jdk/src/java.base/share/classes/sun/nio/cs/HKSCS.java	Thu May 21 14:18:33 2015 -0700
+++ b/jdk/src/java.base/share/classes/sun/nio/cs/HKSCS.java	Thu May 21 15:42:30 2015 -0700
@@ -378,7 +378,6 @@
                             dst[dp++] = repl[1];
                         continue;
                     }
-                    sp++;
                 }
                 if (bb > MAX_SINGLEBYTE) {        // DoubleByte
                     dst[dp++] = (byte)(bb >> 8);
--- a/jdk/test/sun/nio/cs/TestStringCoding.java	Thu May 21 14:18:33 2015 -0700
+++ b/jdk/test/sun/nio/cs/TestStringCoding.java	Thu May 21 15:42:30 2015 -0700
@@ -22,7 +22,7 @@
  */
 
 /* @test
-   @bug 6636323 6636319 7040220 7096080 7183053
+   @bug 6636323 6636319 7040220 7096080 7183053 8080248
    @summary Test if StringCoding and NIO result have the same de/encoding result
  * @run main/othervm/timeout=2000 TestStringCoding
  * @key randomness
@@ -200,6 +200,17 @@
             */
         }
 
+        //encode mappable surrogates for hkscs
+        if (cs.name().equals("Big5-HKSCS") || cs.name().equals("x-MS950-HKSCS")) {
+            String str = "ab\uD840\uDD0Ccd";
+            byte[] expected = new byte[] {(byte)'a', (byte)'b',
+                (byte)0x88, (byte)0x45, (byte)'c', (byte)'d' };
+            if (!Arrays.equals(str.getBytes(cs.name()), expected) ||
+                !Arrays.equals(str.getBytes(cs), expected)) {
+                throw new RuntimeException("encode(surrogates) failed  -> "
+                                           + cs.name());
+            }
+        }
     }
 
     static class PermissiveSecurityManger extends SecurityManager {