You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Andrew Zhang <zh...@gmail.com> on 2006/05/24 03:34:23 UTC

Re: [jira] Updated: (HARMONY-491) [classlib] Constructors of java.nio.charset.CharsetEncoder should not throw NPE if charset==null

Hi, Svetlana

I took a quick view on your patch, I found your quick fix didn't resolve the
problem thoroughly.

Try to comment following code in your test case, RI fails on the test case
but Harmony with your patch passes.

    public boolean isLegalReplacement(byte[] arg0) {
         return true;
    }

Here's my suggestion,

1. remove cs.newDecoder() in CharsetEnconder  constructor.
2. add following code in isLegalReplacement method:
  if(null == decoder){
   decoder = cs.newDecoder();
  }
The following code shows the change in patch format.
Would you please have a review?

Thanks!

Index: nio_char/src/main/java/java/nio/charset/CharsetEncoder.java
===================================================================
--- nio_char/src/main/java/java/nio/charset/CharsetEncoder.java (revision
408852)
+++ nio_char/src/main/java/java/nio/charset/CharsetEncoder.java (working
copy)
@@ -133,7 +133,7 @@

  // decoder instance for this encoder's charset, used for replacement value
  // checking
- private CharsetDecoder decoder;
+ private CharsetDecoder decoder = null;

  /*
   * --------------------------------------- Constructors
@@ -202,7 +202,6 @@
   status = INIT;
   malformAction = CodingErrorAction.REPORT;
   unmapAction = CodingErrorAction.REPORT;
-  decoder = cs.newDecoder();
   replaceWith(replacement);
  }

@@ -722,6 +721,9 @@
   *         replacement byte array.
   */
  public boolean isLegalReplacement(byte[] repl) {
+  if(null == decoder){
+   decoder = cs.newDecoder();
+  }
   CodingErrorAction malform = decoder.malformedInputAction();
   CodingErrorAction unmap = decoder.unmappableCharacterAction();
   decoder.onMalformedInput(CodingErrorAction.REPORT);

On 5/23/06, Svetlana Samoilenko (JIRA) <ji...@apache.org> wrote:
>
>     [ http://issues.apache.org/jira/browse/HARMONY-491?page=all ]
>
> Svetlana Samoilenko updated HARMONY-491:
> ----------------------------------------
>
>    Attachment: CharsetEncoder.txt
>
> patch and unit test
>
> > [classlib] Constructors of java.nio.charset.CharsetEncoder should not
> throw NPE if charset==null
> >
> ------------------------------------------------------------------------------------------------
> >
> >          Key: HARMONY-491
> >          URL: http://issues.apache.org/jira/browse/HARMONY-491
> >      Project: Harmony
> >         Type: Bug
>
> >   Components: Classlib
> >     Reporter: Svetlana Samoilenko
> >     Priority: Minor
> >  Attachments: CharsetEncoder.txt
> >
> > The test listed below will pass on RI but fail on Harmony.
> > import java.nio.*;
> > import java.nio.charset.*;
> > public class test {
> >     public static void main(String [] args) {
> >         CharsetEncoder cen=new CharsetEncoderImpl(null, 1, 1);
> >         if (cen.charset() == null) {
> >             System.out.println("PASSED");
> >         } else
> >             System.out.println("FAILED");
> >     }
> > }
> > class CharsetEncoderImpl extends CharsetEncoder {
> >     public CharsetEncoderImpl(Charset arg0, float arg1, float arg2,
> byte[] arg3) {
> >         super(arg0, arg1, arg2, arg3);
> >     }
> >     public boolean isLegalReplacement(byte[] arg0) {
> >         return true;
> >     }
> >     public CharsetEncoderImpl(Charset arg0, float arg1, float arg2) {
> >         super(arg0, arg1, arg2);
> >     }
> >     protected CoderResult encodeLoop(CharBuffer arg0, ByteBuffer arg1) {
> >         return null;
> >     }
> > }
>
> --
> This message is automatically generated by JIRA.
> -
> If you think it was sent incorrectly contact one of the administrators:
>   http://issues.apache.org/jira/secure/Administrators.jspa
> -
> For more information on JIRA, see:
>   http://www.atlassian.com/software/jira
>
>


-- 
Andrew Zhang
China Software Development Lab, IBM