RFR: JDK-8312395: Improve assertions in growableArray

Matthias Baesken mbaesken at openjdk.org
Thu Jul 20 08:06:40 UTC 2023


On Thu, 20 Jul 2023 07:56:55 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> There are a number of assertions in growableArray , for example to check for a valid index to access/remove elements.
>> Those assertions can be improved, e.g. by showing the bad index value used in case of failure.
>> 
>> Example for an assertion in the 'at(index i)' access method 
>> old assertion looks like
>> assert(0 <= i && i < _len) failed: illegal index
>> 
>> new assertion looks like
>> assert(0 <= i && i < _len) failed: illegal index -559030609, 1 accessible elements
>
> src/hotspot/share/utilities/growableArray.hpp line 145:
> 
>> 143: 
>> 144:   E& at(int i) {
>> 145:     assert(0 <= i && i < _len, "illegal index %d, %d accessible elements", i, _len);
> 
> How about:
> 
> "Illegal index %d for length %d"
> 
> ?

That sounds like a good suggestions !

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

PR Review Comment: https://git.openjdk.org/jdk/pull/14946#discussion_r1269093770


More information about the hotspot-dev mailing list