JDK-8231319 : API Doc for CharsetEncoder.maxBytesPerChar() should be clearer about BOMs
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.nio.charsets
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 14
  • Submitted: 2019-09-20
  • Updated: 2019-09-24
  • Resolved: 2019-09-24
Related Reports
CSR :  
Description
Summary
-------

Clarify the method description of `java.nio.charset.CharsetEncoder#maxBytesPerChar()` method with regard to content-independent prefix/suffix output bytes.

Problem
-------

An implementation of `CharsetEncoder.maxBytesPerChar()`, which does not account for content-independent prefix/suffix bytes, could end up insufficient output buffer size calculation, which leads to `BufferOverflowException`.

Solution
--------

Modify the method description by explicitly mentioning the accountancy of content-independent prefix/suffix.

Specification
-------------

Change the paragraph in the method description of `java.nio.charset.Charset$Coder$` from:

     * Returns the maximum number of $otype$s that will be produced for each
     * $itype$ of input.  This value may be used to compute the worst-case size
     * of the output buffer required for a given input sequence.

to:

      * Returns the maximum number of $otype$s that will be produced for each
      * $itype$ of input.  This value may be used to compute the worst-case size
      * of the output buffer required for a given input sequence. This value
      * accounts for any necessary content-independent prefix or suffix
    #if[encoder]
      * $otype$s, such as byte-order marks.
    #end[encoder]
    #if[decoder]
      * $otype$s.
    #end[decoder] 


Comments
Moving to Approved.
24-09-2019