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

Base64.Encoder.encode and Base64.Decoder.decode should specify OOME if the output bytes array/buffer of the needed size can not be allocated

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 13
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      low
    • Compatibility Risk Description:
      The compatibility risk is low, as the encode/decode throwing exceptions (For example, NegativeArraySizeException) for large input array size, will now throw an OutOfMemoryError
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Base64.Encoder.encode and Base64.Decoder.decode should throw OutOfMemoryError if the output bytes array/buffer of the needed size can not be allocated.

      Problem

      The existing Base64.Encoder.encode and Base64.Decoder.decode methods do not specify the error to be thrown when the encoded/decoded byte array of needed size can not be allocated. The current implementation throws an unspecified exception, for example, NegativeArraySizeException.

      Solution

      Add an OutOfMemoryError statement to Base64.Encoder and Base64.Decoder, if encode and decode methods fail to allocate the output array/buffer or memory.

      Specification

      Update Base64.Encoder spec

      from:

      * <p> Unless otherwise noted, passing a {@code null} argument to
      * a method of this class will cause a
      * {@link java.lang.NullPointerException NullPointerException} to
      * be thrown.

      to:

      * <p> Unless otherwise noted, passing a {@code null} argument to
      * a method of this class will cause a
      * {@link java.lang.NullPointerException NullPointerException} to
      * be thrown.
      * <p> If the encoded byte output of the needed size can not
      *     be allocated, the encode methods of this class will
      *     cause an {@link java.lang.OutOfMemoryError OutOfMemoryError}
      *     to be thrown.

      Update Base64.Decoder spec

      from:

      * <p> Unless otherwise noted, passing a {@code null} argument to
      * a method of this class will cause a
      * {@link java.lang.NullPointerException NullPointerException} to
      * be thrown.

      to:

      * <p> Unless otherwise noted, passing a {@code null} argument to
      * a method of this class will cause a
      * {@link java.lang.NullPointerException NullPointerException} to
      * be thrown.
      * <p> If the decoded byte output of the needed size can not
      *     be allocated, the decode methods of this class will
      *     cause an {@link java.lang.OutOfMemoryError OutOfMemoryError}
      *     to be thrown.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                nishjain Nishit Jain
                Reporter:
                webbuggrp Webbug Group
                Reviewed By:
                Naoto Sato, Roger Riggs
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: