User account creation filtered due to spam.

Bug 26220 - InputStreamReader(,CharSet) creates broken reader
Summary: InputStreamReader(,CharSet) creates broken reader
Status: RESOLVED FIXED
Alias: None
Product: classpath
Classification: Unclassified
Component: classpath (show other bugs)
Version: 0.20
: P3 normal
Target Milestone: 0.90
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-11 10:35 UTC by Andy Seaborne
Modified: 2006-02-12 09:36 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-02-12 09:18:03


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Seaborne 2006-02-11 10:35:33 UTC
Setup: ikvm 0.24.0.1 (as JVM), Java 1.4.2_10

Of the three constructors for InputStreamReader that allow the app to set
the Charset, the one where the Charset is passed directly does not give a Reader that can read the data.

Charset cs = Charset.forName("utf-8");
new InputStreamReader(ins, cs.newDecoder()); // Works
new InputStreamReader(ins, "utf-8");         // Works
new InputStreamReader(ins, cs);              // Does not work

The test program should print 104 each time but does not do so in the third case.  Workaround: use the constructor with cs.newDecoder().

Couldn't find a bug like this in bugzilla - apologies if it is a duplicate.

    Andy

Test program:
public static void main(String[] argv)
    {
        System.out.println("<<<<<<<<<<<<<<<");
        try {
            Charset cs = Charset.forName("utf-8");
            {
                ByteArrayInputStream ins = new ByteArrayInputStream("hello world".getBytes()) ;
                Reader r = new InputStreamReader(ins, cs.newDecoder());
                System.out.println("With decoder: .read()         => "+r.read()) ;
            }
            System.out.println("---------------");
            // ----
            {
                ByteArrayInputStream ins = new ByteArrayInputStream("hello world".getBytes()) ;
                Reader r = new InputStreamReader(ins, "utf-8");
                System.out.println("With charset name: .read()    => "+r.read()) ;
            }
            System.out.println("---------------");
            // ----
            {
                ByteArrayInputStream ins = new ByteArrayInputStream("hello world".getBytes()) ;
                Reader r = new InputStreamReader(ins, cs);
                System.out.println("With charset object: .read()  => "+r.read()) ;
            }
        } catch (Exception ex)
        {
            System.err.println("IO exception: "+ex.getMessage()) ;
        }
        System.out.println(">>>>>>>>>>>>>>>");
    }
Comment 1 Andy Seaborne 2006-02-11 12:03:46 UTC
Forgot to be clear about the effect:

The reader created by 
new InputStreamReader(ins, cs); 
returns -1 on the .read() when it should be 104 (the "h")
Comment 2 Jeroen Frijters 2006-02-12 09:18:03 UTC
Thanks for the bug report.

maxBytesPerChar is not initialized in InputStreamReader(InputStream, CharSet) constructor.
Comment 3 Jeroen Frijters 2006-02-12 09:36:53 UTC
Fixed.
Comment 4 cvs-commit@developer.classpath.org 2006-02-12 09:44:35 UTC
Subject: Bug 26220

CVSROOT:	/cvsroot/classpath
Module name:	classpath
Branch: 	
Changes by:	Jeroen Frijters <jfrijters@savannah.gnu.org>	06/02/12 09:36:21

Modified files:
	.              : ChangeLog 
	java/io        : InputStreamReader.java 

Log message:
	2006-02-12  Jeroen Frijters  <jeroen@frijters.net>
	
	Fixes PR 26220
	* java/io/InputStreamReader.java
	(InputStreamReader(InputStream)): Use SystemProperties.
	(InputStreamReader(InputStream,Charset)): Corrected @since tag.
	Throw NullPointerException if in is null.
	Added maxBytesPerChar initialisation.
	(InputStreamReader(InputStream,CharsetDecoder)): Corrected @since tag.
	Throw NullPointerException if in is null.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/classpath/classpath/ChangeLog.diff?tr1=1.6340&tr2=1.6341&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/classpath/classpath/java/io/InputStreamReader.java.diff?tr1=1.28&tr2=1.29&r1=text&r2=text