8015604: JDP packets containing ideographic characters are broken
authordsamersoff
Wed, 05 Jun 2013 18:20:34 +0400
changeset 17951 2734e5252a38
parent 17950 b2d5b298ec6e
child 17952 a5f2fb0e7457
8015604: JDP packets containing ideographic characters are broken Summary: Code uses string length rather than byte array length and non ascii entry brakes packet. Reviewed-by: dholmes, jbachorik, sla
jdk/src/share/classes/sun/management/jdp/JdpPacketWriter.java
jdk/test/sun/management/jdp/JdpUnitTest.java
--- a/jdk/src/share/classes/sun/management/jdp/JdpPacketWriter.java	Wed Jun 05 13:57:16 2013 +0100
+++ b/jdk/src/share/classes/sun/management/jdp/JdpPacketWriter.java	Wed Jun 05 18:20:34 2013 +0400
@@ -60,9 +60,12 @@
      */
     public void addEntry(String entry)
             throws IOException {
-        pkt.writeShort(entry.length());
-        byte[] b = entry.getBytes("UTF-8");
-        pkt.write(b);
+        /* DataOutputStream.writeUTF() do essentially
+         *  the same as:
+         *    pkt.writeShort(entry.getBytes("UTF-8").length);
+         *    pkt.write(entry.getBytes("UTF-8"));
+         */
+        pkt.writeUTF(entry);
     }
 
     /**
--- a/jdk/test/sun/management/jdp/JdpUnitTest.java	Wed Jun 05 13:57:16 2013 +0100
+++ b/jdk/test/sun/management/jdp/JdpUnitTest.java	Wed Jun 05 18:20:34 2013 +0400
@@ -32,6 +32,12 @@
 
 public class JdpUnitTest {
 
+
+    static byte[] russian_name = {(byte)0xd0,(byte)0xbf,(byte)0xd1,(byte)0x80,(byte)0xd0,(byte)0xbe,(byte)0xd0,(byte)0xb2,
+                                  (byte)0xd0,(byte)0xb5,(byte)0xd1,(byte)0x80,(byte)0xd0,(byte)0xba,(byte)0xd0,(byte)0xb0,
+                                  (byte)0x20,(byte)0xd1,(byte)0x81,(byte)0xd0,(byte)0xb2,(byte)0xd1,(byte)0x8f,(byte)0xd0,
+                                  (byte)0xb7,(byte)0xd0,(byte)0xb8,(byte)0x0a};
+
     /**
      * This test tests that complete packet is build correctly
      */
@@ -42,7 +48,7 @@
         {
             JdpJmxPacket p1 = new JdpJmxPacket(UUID.randomUUID(), "fake://unit-test");
             p1.setMainClass("FakeUnitTest");
-            p1.setInstanceName("Fake");
+            p1.setInstanceName( new String(russian_name,"UTF-8"));
             byte[] b = p1.getPacketData();
 
             JdpJmxPacket p2 = new JdpJmxPacket(b);