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)
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)
- relates to
-
JDK-8247373 ArraysSupport.newLength doc, test, and exception message
- Resolved
-
JDK-8246725 Provide MAX_ARRAY_SIZE publicly
- Open