You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Julius Davies (JIRA)" <ji...@apache.org> on 2010/06/03 01:59:54 UTC

[jira] Updated: (CODEC-101) Base64InputStream#read(byte[]) incorrectly returns 0 at end of any stream which is multiple of 3 bytes long

     [ https://issues.apache.org/jira/browse/CODEC-101?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julius Davies updated CODEC-101:
--------------------------------

    Attachment: codec-101-fix.patch

Wow, I can't imagine how you tracked this one down to Base64InputStream!  Java6's stacktrace is so un-helpful:

{code}
public class R {
    public static void main(String[] args) throws Exception {
        Base64InputStream in = new Base64InputStream(System.in);
        InputStreamReader isr = new InputStreamReader(in, "UTF-8");
        BufferedReader br = new BufferedReader(isr);
        String line = br.readLine();
        while (line != null) {
            System.out.println("Line:" + line);
            line = br.readLine();
        }
    }
}

$ java -cp build/playground.jar:/opt/dev/codec/target/classes  R   < all-whitespace.txt 
Exception in thread "main" java.io.IOException: Underlying input stream returned zero bytes
	at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:268)
	at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
	at java.io.InputStreamReader.read(InputStreamReader.java:167)
	at java.io.BufferedReader.fill(BufferedReader.java:136)
	at java.io.BufferedReader.readLine(BufferedReader.java:299)
	at java.io.BufferedReader.readLine(BufferedReader.java:362)
	at R.main(R.java:17)
{code}


I've attached a patch that appears to fix it.   Are you able to try this out?  You can try the following commands to build a patched binary:

{code}
svn export http://svn.apache.org/repos/asf/commons/proper/codec/trunk/ codec-trunk
cd codec-trunk
patch -p0 < codec-101-fix.patch
ant dist
{code}


In the meantime I'm working on some unit tests to better exercise this patch.  I'll try and get those uploaded here to CODEC-101 within 48 hours.




> Base64InputStream#read(byte[]) incorrectly returns 0 at end of any stream which is multiple of 3 bytes long
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: CODEC-101
>                 URL: https://issues.apache.org/jira/browse/CODEC-101
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>         Environment: WinXP, JDK 1.6.0_14
>            Reporter: Bauke Scholtz
>         Attachments: codec-101-fix.patch
>
>
> Using new InputStreamReader(new Base64InputStream(in, true)) sometimes fails with "java.io.IOException: Underlying input stream returned zero bytes".
> This is been tracked down that Base64InputStream#read(byte[]) incorrectly returns 0 at end of any stream which is multiple of 3 bytes long.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.