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

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 13
    • core-libs
    • None
    • behavioral
    • low
    • The compatibility risk is low, as the encode/decode throwing exceptions (For example, NegativeArraySizeException) for large input array size, will now throw an OutOfMemoryError
    • Java API
    • SE

      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.

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

              Created:
              Updated:
              Resolved: