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

CharsetDecoder decode in JDK8 results in different behavior compared to JDK7

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_11"
      Java(TM) SE Runtime Environment (build 1.8.0_11-b12)

      ADDITIONAL OS VERSION INFORMATION :
      MacOS 13.4.0 Darwin Kernel Version 13.4.0

      A DESCRIPTION OF THE PROBLEM :
      Running the below code results in different behavior in JDK8 from JDK7

      @Test
        public void testTest() {
          CharsetDecoder decoder = Charsets.UTF_8.newDecoder();

          decoder.onMalformedInput(CodingErrorAction.REPLACE);
          decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);

          ByteBuffer buf = ByteBuffer.allocate(20);
          buf.put(new byte[] { (byte)0xf8, (byte)0xa1, (byte)0xa1, (byte)0xa1,
                  (byte)0xa1 });
          buf.flip();

          CharBuffer cbuf = CharBuffer.allocate(1);
          CoderResult res = decoder.decode(buf, cbuf, false);
          System.out.println(decoder.getClass().getName());
          System.out.println("Pos --- "+buf.position()+ " cbuf pos --"+cbuf.position());
      }

      Jdk 7 output -->Pos --- 5 cbuf pos --1
      Jdk 8 output -->Pos --- 1 cbuf pos --1

      REGRESSION. Last worked in version 7u67


      REPRODUCIBILITY :
      This bug can be reproduced always.

            sherman Xueming Shen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: