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

CharsetEncoder.encode of Cp970 fails to throw CharacterCodingException

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Linux honolulu.ilog.fr 2.4.21-0.13mdk #1 Fri Mar 14 15:08:06 EST 2003 i686 unknown
      Windows XP


      A DESCRIPTION OF THE PROBLEM :
      The encoder for Cp970 returns empty byte buffers instead of throwing
      UnmappableCharacterException when the input is a lone surrogate code point.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      javac niobug7.java
      java niobug7


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No output.

      ACTUAL -
      Charset Cp970: 1024 errors


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;
      import java.nio.*;
      import java.nio.charset.*;

      public class niobug7 {
        public static void main (String[] args) throws CharacterCodingException {
          String charset = "Cp970";
          CharsetEncoder converter = Charset.forName(charset).newEncoder();
          converter = converter.onMalformedInput(CodingErrorAction.REPORT);
          converter = converter.onUnmappableCharacter(CodingErrorAction.REPORT);
          int errors = 0;
          for (int i = 0xd800; i < 0xe000; i++) {
            char[] in = new char[] { (char)i };
            try {
              ByteBuffer out = converter.encode(CharBuffer.wrap(in));
              if (out.remaining() == 0)
                errors++;
            } catch (CharacterCodingException e) {
            }
          }
          if (errors > 0)
            System.err.println("Charset "+charset+": "+errors+" errors");
        }
      }

      ---------- END SOURCE ----------

            sherman Xueming Shen
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: