Uploaded image for project: 'JGroups'
  1. JGroups
  2. JGRP-2062

TYPE_STRING does not handle unicode

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Minor
    • 3.6.11, 4.0
    • None
    • None
    • Hide
      channel.send(new org.jgroups.Message(null, "\u1F601"));
      

      Expected: Ironically, Jira fails on expected output. See http://apps.timwhitlock.info/emoji/tables/unicode

      Actual: garbage data

      Show
      channel.send( new org.jgroups.Message( null , "\u1F601" )); Expected: Ironically, Jira fails on expected output. See http://apps.timwhitlock.info/emoji/tables/unicode Actual: garbage data

    Description

      In several places throughout the org.jgroups.util.Util class, it is assumed that Strings are one byte per character.

      For example, see objectToByteBuffer lines 561-567:

      https://github.com/belaban/JGroups/blob/master/src/org/jgroups/util/Util.java#L561-L567

      case TYPE_STRING:
          String str=(String)obj;
          int len=str.length();
          ByteBuffer retval=ByteBuffer.allocate(Global.BYTE_SIZE + len).put(TYPE_STRING);
          for(int i=0; i < len; i++)
              retval.put((byte)str.charAt(i));
          return retval.array();
      

      This code will incorrectly encode any String with non ASCII encoding.

      There are several options to fix. You could use str.getBytes(StandardCharsets.UTF_8) to get a proper byte encoding, or you could use the existing TYPE_SERIALIZABLE code path.

      Attachments

        Issue Links

          Activity

            People

              rhn-engineering-bban Bela Ban
              codyebberson Cody Ebberson (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: