RFR: JDK-8312453: GrowableArray should assert for length overflow on append

David Holmes dholmes at openjdk.org
Fri Jul 21 05:31:45 UTC 2023


On Thu, 20 Jul 2023 15:41:56 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> Trivial change to assert that we don't overflow on append.
>
> src/hotspot/share/utilities/growableArray.hpp line 390:
> 
>> 388: public:
>> 389:   int append(const E& elem) {
>> 390:     assert(this->_len != INT_MAX, "Overflow");
> 
> This isn't needed.  `grow` (via `next_power_of_2`) already does the appropriate overflow checking.

I'm inclined to agree with @kimbarrett . We check length against capacity and grow if needed. The responsibility for checking overflow lies in grow, not append.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14951#discussion_r1270239346


More information about the hotspot-dev mailing list