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

adjust OutOfMemoryError specification to mention implementation limits being exceeded

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      OutOfMemoryError currently specifies "Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector." [1]

      However, as was pointed out by Chris Hegarty [2], it's kind of a de facto standard to throw an OutOfMemoryError when inherent size limits (typically of arrays) are hit. So I believe that the Javadoc of OutOfMemoryError should be updated to specify this usage and give concrete examples such as:
      - allocation of arrays, e.g. new byte[Integer.MAX_VALUE] gives an OOME with message "Requested array size exceeds VM limit"
      - methods that return an array/Buffer, e.g. InputStream::readAllBytes [3], Files::readAllBytes [4] and ModuleReader::read [5]
      - classes that use arrays internally (ArrayList, StringBuilder, ...) and are unable to complete a requested operation, e.g. new StringBuffer().ensureCapacity(Integer.MAX_VALUE)

      [1] https://download.java.net/java/early_access/jdk12/docs/api/java.base/java/lang/OutOfMemoryError.html
      [2] http://mail.openjdk.java.net/pipermail/core-libs-dev/2017-March/046671.html
      [3] https://download.java.net/java/early_access/jdk12/docs/api/java.base/java/io/InputStream.html#readAllBytes()
      [4] https://download.java.net/java/early_access/jdk12/docs/api/java.base/java/nio/file/Files.html#readAllBytes(java.nio.file.Path)
      [5] https://download.java.net/java/early_access/jdk12/docs/api/java.base/java/lang/module/ModuleReader.html#read(java.lang.String)



            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: