A DESCRIPTION OF THE PROBLEM :
ArrayList should have a description about the maximum ArrayList capacity allowed.
Size method returns integer that implies that size can not be more than Integer.MAX_VALUE.
but if we go on adding element in ArrayList, then we will get OutOfMemoryError.
that should not be the case as developer can expect to throw exception which is handle-able.
So, A Developer with no information about internal implementation will assume that Integer.MAX_VALUE is the maximum allowed capacity of ArrayList.
But that is not the case with openjdk 8. Maximum allowed capacity is below value:
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
But ArrayList docs does not give information about the maximum allowed capacity.
Developer can go through blogs and implementation of openjdk to understand more.
But Why there is no any guide on maximum capacity allowed in ArrayList docs itself ?
Programmer can read that guide while creating huge ArrayList.
There can be a static public field of max allowed.
ArrayList should have a description about the maximum ArrayList capacity allowed.
Size method returns integer that implies that size can not be more than Integer.MAX_VALUE.
but if we go on adding element in ArrayList, then we will get OutOfMemoryError.
that should not be the case as developer can expect to throw exception which is handle-able.
So, A Developer with no information about internal implementation will assume that Integer.MAX_VALUE is the maximum allowed capacity of ArrayList.
But that is not the case with openjdk 8. Maximum allowed capacity is below value:
private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
But ArrayList docs does not give information about the maximum allowed capacity.
Developer can go through blogs and implementation of openjdk to understand more.
But Why there is no any guide on maximum capacity allowed in ArrayList docs itself ?
Programmer can read that guide while creating huge ArrayList.
There can be a static public field of max allowed.