Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8231319

API Doc for CharsetEncoder.maxBytesPerChar() should be clearer about BOMs

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 14
    • core-libs
    • None
    • minimal
    • Since this is only a spec clarification, the risk is minimal.
    • Java API
    • SE

      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] 

            naoto Naoto Sato
            webbuggrp Webbug Group
            Alan Bateman, Mark Reinhold, Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: