JDK-4131647 : UTF* internal conversion bug: Output buffer too small
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.1.5,1.2.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 1998-04-22
  • Updated: 1998-06-19
  • Resolved: 1998-06-19
Related Reports
Duplicate :  
Relates :  
Description
java.io.CharConversionException: Output buffer too small
        at java.io.OutputStreamWriter.write(OutputStreamWriter.java)
        at java.io.Writer.write(Writer.java)
        at gen.main(gen.java:29)

See the enclosed "gen.java" file ... run it a few times (it generates
data randomly -- collect the seeds to find one that generates the error,
then reuse that if you like):

	java gen filename.xml UTF8

Before very long you'll get an exception like the one reported above.  This
is clearly a bug in the implementation, since it has no business failing to
allocate sufficient space for a character in its internal buffer!  (Also,
note that at some point I started getting error reports with the surrogate
generation code, and don't know what changed to make them happen.  The bug
shows up either way, although more often when surrogates are used I think.)

You'll note that java.io.OutputStreamWriter only reports this when it gets
a ConversionBufferFull exception.  I think that it may be interpreting
the exception incorrectly ... the fact that it's full doesn't mean that
no characters were written.

Comments
WORK AROUND Implement your own UTF-8 writer, and use that instead. You can even arrange to have it use the "UTF-8" encoding name, per the Internet and ISO standards ... :-)
11-06-2004

PUBLIC COMMENTS Sometimes writing UTF-8 data exposes an internal error in the OutputStreamWriter class, reported as an "Output buffer too small" exception message.
10-06-2004

EVALUATION This looks more like a bug in OutputStreamWriter.write(char[], int, int) than in the UTF-8 converters. mark.son-bell@eng 1998-04-24
24-04-1998