You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Svetlana Samoilenko (JIRA)" <ji...@apache.org> on 2006/05/23 09:33:29 UTC

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

[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


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


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

Posted by Andrew Zhang <zh...@gmail.com>.
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

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

Posted by "Svetlana Samoilenko (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-491?page=all ]

Svetlana Samoilenko updated HARMONY-491:
----------------------------------------

    Attachment: updateCharsetEncoder.txt

Mikhail, try please new patch and test.
A lot of thanks to Andrew Zhang for pointing fix incompletness out. 

> [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
>     Assignee: Mikhail Loenko
>     Priority: Minor
>  Attachments: CharsetEncoder.txt, updateCharsetEncoder.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


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

Posted by "Mikhail Loenko (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-491?page=all ]
     
Mikhail Loenko closed HARMONY-491:
----------------------------------


verified by Svetlana

> [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
>     Assignee: Mikhail Loenko
>     Priority: Minor
>  Attachments: CharsetEncoder.txt, updateCharsetEncoder.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


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

Posted by "Mikhail Loenko (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-491?page=all ]

Mikhail Loenko reassigned HARMONY-491:
--------------------------------------

    Assign To: Mikhail Loenko

> [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
>     Assignee: Mikhail Loenko
>     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


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

Posted by "Mikhail Loenko (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-491?page=all ]
     
Mikhail Loenko resolved HARMONY-491:
------------------------------------

    Resolution: Fixed

fixed in revision 409162
Svetlana, please verify it resolves the issue

> [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
>     Assignee: Mikhail Loenko
>     Priority: Minor
>  Attachments: CharsetEncoder.txt, updateCharsetEncoder.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


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

Posted by "Svetlana Samoilenko (JIRA)" <ji...@apache.org>.
     [ 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


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

Posted by "Svetlana Samoilenko (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-491?page=comments#action_12413216 ] 

Svetlana Samoilenko commented on HARMONY-491:
---------------------------------------------

Thanks a lot, Mikhail,
all works fine.

> [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
>     Assignee: Mikhail Loenko
>     Priority: Minor
>  Attachments: CharsetEncoder.txt, updateCharsetEncoder.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