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

CharsetDecoder.implOnMalformedInput() has wrong default implementation

XMLWordPrintable

    • sparc
    • solaris_8



      Name: auR10023 Date: 04/24/2003



      java.nio.charset.CharsetDecoder.implOnMalformedInput(CodingErrorAction)
      has wrong default implementation.
      Javadoc for this method says:
      ...
      The default implementation of this method does nothing.
      ...

      But invocation of the onMalformedInput() method (which according to the
      javadoc should invoke implOnMalformedInput()) change the state of the
      object.

      Here is the example:

      -------test.java---------

      import java.util.*;
      import java.nio.*;
      import java.nio.charset.*;

      public class test extends CharsetDecoder {
          public test(CharsetDecoder d) {
              super(d.charset(), d.averageCharsPerByte(), d.maxCharsPerByte());
          }

          protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
              return null;
          }

          public static void main(String [] args) {
          
              CharsetDecoder d = null;
          
              try {
                  d = Charset.forName("US-ASCII").newDecoder();
              } catch(Exception e) {
                  e.printStackTrace(System.out);
                  return;
              }

              CharsetDecoder dec = new test(d);
          
              System.out.println(dec.malformedInputAction());
              dec.onMalformedInput(CodingErrorAction.IGNORE);
              System.out.println(dec.malformedInputAction());
              dec.onMalformedInput(CodingErrorAction.REPLACE);
              System.out.println(dec.malformedInputAction());
          }
      }

      Here is the result
      #java -version

      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b04)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b04, mixed mode)

      #java test

      REPORT
      IGNORE
      REPLACE

      The same wrong behavior one can see with following methods of the
      CharsetDecoder:

      implOnUnmappableCharacter(), implReplaceWith()

      ======================================================================

            mr Mark Reinhold
            avusunw Avu Avu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: