FIX: java.io.OutputStreamWriter Class Incorrectly Throws Exception (280062)



The information in this article applies to:

  • Microsoft virtual machine

This article was previously published under Q280062

SYMPTOMS

When the java.io.OutputStreamWriter class uses multiple-byte character encoding systems, it may incorrectly throw a CharConversionException exception with an "OutputBuffer too small" detail string.

CAUSE

This problem occurs if previous operations nearly fill up the byte array conversion buffer (with only 1, 2, or 3 bytes left in the buffer) and the first character of a new incoming conversion operation is too large to fit in the buffer's remaining space.

RESOLUTION

To resolve this problem on computers that are running Microsoft Windows 95, Microsoft Windows 98, Microsoft Windows Millennium Edition (Me), Microsoft Windows NT, and Microsoft Windows 2000, download and install the latest build of the Microsoft VM.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new file named Test.java, and paste the following code:
    import java.util.*;
    import java.io.*;
    
    public class Test
    {
    	public static void main(String[] args) throws IOException
    	{
    		ByteArrayOutputStream bos;
    		OutputStreamWriter osw;
    		byte[] array;
    		
    		
    		bos = new ByteArrayOutputStream();
    		osw = new OutputStreamWriter(bos, "UTF8");
    
    		try
    		{
    			for(int count = 1; count < 3000; ++count)
    				osw.write('\u3042'); // Hiragana
    
    			osw.close();
    			array = bos.toByteArray();
    
    			System.out.println( "Number of UTF8 bytes written "+ array.length );
    		}
    		catch( CharConversionException ex)
    		{
    			System.out.println(ex.getMessage());
    		}
    	}
    }
    					
  2. At a command prompt, type the following command to compile the source file:

    jvc Test.java

  3. At a command prompt, type the following command to run the class file:

    jview Test.class

  4. Because the CharConversionException exception is incorrectly thrown, you receive the following message:
    Output buffer too small

REFERENCES

The latest build of the Microsoft VM is available from the following Microsoft Web site: For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:

Modification Type:MajorLast Reviewed:6/14/2006
Keywords:kbbug kbfix KB280062