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

ArrayDeque created with default constructor can only hold 15 elements

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P5
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 12
    • Component/s: core-libs
    • Labels:
      None

      Description

      The spec states that a deque created with the default constructor should be able to hold 16 elements.

      https://docs.oracle.com/javase/10/docs/api/java/util/ArrayDeque.html#%3Cinit%3E()
      """
      Constructs an empty array deque with an initial capacity sufficient to hold 16 elements.
      """

      In the constructor an array of size 16 is created:
              elements = new Object[16];

      However, one element is always null:
          /**
           * The array in which the elements of the deque are stored.
           * All array cells not holding deque elements are always null.
           * The array always has at least one null slot (at tail).
           */
          transient Object[] elements;

      which leaves us space for only 15 elements, contrarily to what the spec promises.

        Attachments

          Activity

            People

            Assignee:
            martin Martin Buchholz
            Reporter:
            igerasim Ivan Gerasimov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: