On Tue, 8 Dec 2020 00:48:55 GMT, Stuart Marks <sma...@openjdk.org> wrote:
>> The algorithm can be well defined for minGrowth and prefGrowth == 0 without >> extra checks or exceptions with a careful look at the inequality checks. >> For example, as currently coded, if both are zero, it returns >> SOFT_MAX_ARRAY_LENGTH. >> Changing the `0 < prefLength` to `0 <= prefLength` would return minGrowth >> and avoid a very large but unintentional allocation. > > That's only true if oldLength is zero. The behavior is different if oldLength > is positive. In any case, this method is called when the array needs to > **grow**, which means the caller needs to reallocate and copy. If the caller > passes zero for both minGrowth and prefGrowth, the caller doesn't need to > reallocate and copy, and there's no point in it calling this method in the > first place. Not calling for a zero value is usually an optimization, not a necessity to work around an inconsistency or unpredictability in the API or the range of arguments it accepts. ------------- PR: https://git.openjdk.java.net/jdk/pull/1617