Hello.
I came across unexpected behaviour of Arrays.deepToString method.
It throws OOM even on non-huge arrays.
For example this code:

    int size = Integer.MAX_VALUE / 19;
    Integer[] integers = new Integer[size];
    Arrays.fill(integers, 0);
   System.out.println(Arrays.deepToString(integers));

Fails with following stack trace:

Exception in thread "main" java.lang.OutOfMemoryError: Requested array
size exceeds VM limit
    at 
java.base/java.lang.AbstractStringBuilder.<init>(AbstractStringBuilder.java:86)
    at java.base/java.lang.StringBuilder.<init>(StringBuilder.java:112)
    at java.base/java.util.Arrays.deepToString(Arrays.java:5160)


I believe it should be able to handle such arrays and not throw OOM


Andrey Turbanov

Reply via email to