Uploaded image for project: 'MINA'
  1. MINA
  2. DIRMINA-983

Problems with TextLineDecoder and special characters

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0.8
    • Component/s: None
    • Labels:
      None
    • Environment:
      Apache Mina 2.0.7

      Description

      Hey guys,

      we have special characters in our messages like "ΓΌ" or "$" and it seems there is a problem in the TextLineDecoder.

      I debugged the "decodeAuto" method and my question is: Why do you use "buffer.array()" instead of "buffer.toString()"?

      Problem is the array is 1 element too long so "buffer.array()" gives out a blank char at the end. "buffer.toString()" pays attention to "buffer.limit" so the string has perfect size.

      We made a workaround to trim it afterwards but maybe you wanted to know this?

      Greetings,
      Natascha

        Activity

        Hide
        elecharny Emmanuel Lecharny added a comment -

        Moved to MINA

        Show
        elecharny Emmanuel Lecharny added a comment - Moved to MINA
        Hide
        elecharny Emmanuel Lecharny added a comment -

        The exact line is :

        CharBuffer buffer = decoder.decode(ByteBuffer.wrap(data));
        String str = new String(buffer.array());
        

        The fact that we use array() here has no consequence on the length of the resulting string, as the limit will always be teh size of the string (we just created the CharBuffer the line before).

        The problem you have is different. Are you on windows ?

        Show
        elecharny Emmanuel Lecharny added a comment - The exact line is : CharBuffer buffer = decoder.decode(ByteBuffer.wrap(data)); String str = new String (buffer.array()); The fact that we use array() here has no consequence on the length of the resulting string, as the limit will always be teh size of the string (we just created the CharBuffer the line before). The problem you have is different. Are you on windows ?
        Hide
        steve_ulrich Steve Ulrich added a comment -

        It has: The CharsetDecoder gueses the length of the charbuffer depending on the charset. So the backing arrays you are accessing with array() may be larger than the actual string, if you are using a dynamic-length-coding, like UTF-8 with umlauts.

        Show
        steve_ulrich Steve Ulrich added a comment - It has: The CharsetDecoder gueses the length of the charbuffer depending on the charset. So the backing arrays you are accessing with array() may be larger than the actual string, if you are using a dynamic-length-coding, like UTF-8 with umlauts.
        Hide
        nbrell Natascha added a comment -

        Yes we do use UTF-8. This occured at our customer with a Linux Server and on my development environment wich is Windows.

        Show
        nbrell Natascha added a comment - Yes we do use UTF-8. This occured at our customer with a Linux Server and on my development environment wich is Windows.
        Hide
        elecharny Emmanuel Lecharny added a comment -

        Ok, I see. Will find a fix for that.

        Thanks for the report and comments.

        Show
        elecharny Emmanuel Lecharny added a comment - Ok, I see. Will find a fix for that. Thanks for the report and comments.
        Hide
        elecharny Emmanuel Lecharny added a comment -

        I applied the suggested change (ie, using buffer.toString() instead of buffer.array()).

        Show
        elecharny Emmanuel Lecharny added a comment - I applied the suggested change (ie, using buffer.toString() instead of buffer.array()).
        Hide
        elecharny Emmanuel Lecharny added a comment -

        Fixed with Commit: 2030bf02a96f109fd1454c835fcf69e83a16d466

        Show
        elecharny Emmanuel Lecharny added a comment - Fixed with Commit: 2030bf02a96f109fd1454c835fcf69e83a16d466

          People

          • Assignee:
            Unassigned
            Reporter:
            nbrell Natascha
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development