Sometimes constraints are questionable

Stuart Marks stuart.marks at oracle.com
Fri Jun 5 20:36:25 UTC 2020



On 6/3/20 10:36 AM, Stuart Marks wrote:
> 3) Integer wraparound/overflow during size computation. AS.newLength generates 
> this:
> 
>      OutOfMemoryError: Required array length too large
> 
> (3) is the only case generated by the library. In fact, AS.hugeLength() has 
> oldLength and minGrowth parameters, which seems like enough detail already. 
> These could reasonably be formatted into the error message, something like:
> 
>      private static int hugeLength(int oldLength, int minGrowth) {
>          int minLength = oldLength + minGrowth;
>          if (minLength < 0) { // overflow
>              throw new OutOfMemoryError(
>                  String.format("Required array length %d + %d too large", 
> oldLength, minGrowth));
>          }
> 
> Would this help? If this were added, would it be sufficient to allow various use 
> sites to convert to use AS.newLength? (Except possibly StringJoiner.)

Anything further on this? Should I file a bug/rfe for this? Also, I could update 
the docs to explain ArraysSupport.newLength better, per my earlier exchange with 
David Holmes.

s'marks



More information about the core-libs-dev mailing list