Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4477225

Unicode Encoding works incorrectly under 2 threads

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.1
    • hotspot
    • x86
    • windows_2000

      Encoding does not work well under a couple of threads are runnning.

      1. Reproduce
       
       (1) Compile the attached program
       (2) Invoke "java test"

           You can see the following message.

      Thread start enc=UnicodeLittle
      Thread start enc=UnicodeBig

           If the program work correctly, no message will not appear.
           However, you will see some error messages like,

      !!!!!!!!!!! Styletemplete new String ERROR
      Stopped index : 29904
      Encoding identifier : UnicodeBig
      strStyleTemplate len.: 150
      strDebug len.:150
      -------strStyleTemplate------
      12345678901234567890123456789012345678901234567890123456789012345678901234567890
      1234567890123456789012345678901234567890123456789012345678901234567890
      ---------strDebug------------
      12345678901234567890123456789012345678901234567890123456789012345678901234567890
      123456789012345678901234567890123456
      -----------------------------

           This is output by the program when conversion error happened.

           strStyleTemplate is original String, and strDebug is the result string
           by converting.
       
           The strDebug looks shorter than strStyleTemplate, but these two are
           the same length, which is, strDebug looks to have invisible char.
           from the position at which char. looks truncated.


      2. Configration

        (1) PCs
           OS : WindowsNT(SP5, Japanese) and Windows98(SE, Japanese)
           MPU: Pentium II 450[MHz]
           Mem: 256[MHz]

           OS : Windows2000(SP2, Japanese)
           MPU: Celeron 300[MHz]
           Mem: 128[MHz]

        (2) JDK
           JDK1.3.0_03, JDK1.3.1


      3. Note

        (1) With Merlin
           This conversion error does not happen with <erlin beta refresh b68.

        (2) Exception
           The ArrayIndexOutOfBoundsException sometimes happens.

      java.lang.ArrayIndexOutOfBoundsException
              at sun.io.ByteToCharUnicode.convert(ByteToCharUnicode.java:154)
              at java.lang.String.<init>(String.java:372)
              at java.lang.String.<init>(String.java:411)
              at java.lang.String.<init>(String.java:432)
              at test.run(test.java:32)


      4. Sample program

         The attached program is to convert given String to byte array,
         and then re-convert the byte array to String with UnicodeBig or
         UnicodeLittle.

         If the converted string is not equal to the given(original) String,
         program outputs each string information.
       
         This program creates two threads and each encoding is achieved
         in each thread.

      =======
      public final class test extends Thread {
        boolean flg;
        String strStyleTemplate = "123456789012345678901234567890123456789012345678901
      23456789012345678901234567890123456789012345678901234567890123456789012345678901
      2345678901234567890";

        public static void main(String[] args)
        {
          test a;
          test b;

          a = new test();
          b = new test();
          a.flg = false;
          b.flg = true;

          a.start();
          b.start();
        }

        public void run(){
          String strEnc = "UnicodeLittle";
          if(flg){
            strEnc = "UnicodeBig";
          }
            System.out.println("Thread start enc="+strEnc);

            for(int iDebug=0;iDebug<1000000;iDebug++) {
            //for(int iDebug=0;iDebug<10000000;iDebug++) {

              byte barrayDebug[];
              try {
                barrayDebug = strStyleTemplate.getBytes(strEnc);
                String strDebug = new String(barrayDebug,strEnc);

                if(strStyleTemplate.compareTo(strDebug) != 0) {
                  System.out.println("!!!!!!!!!!! Styletemplete new String ERROR");
                  System.out.println("Stopped index : " + iDebug );
                  System.out.println("Encoding identifier : " + strEnc);
                  System.out.println("strStyleTemplate len.: " + strStyleTemplate.leng
      th());
                  System.out.println("strDebug len.:" + strDebug.length() );
                  System.out.println("-------strStyleTemplate------");
                  System.out.println(strStyleTemplate);
                  System.out.println("---------strDebug------------");
                  System.out.println(strDebug);
                  System.out.println("-----------------------------");
                }
              }
              catch(Throwable th) {
                th.printStackTrace();
                System.out.println(" index at exception : " + iDebug );
              }
            }
        }
      }

      =======

            duke J. Duke
            tbaba Tadayuki Baba (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: