RFR: 6187113: DefaultListSelectionModel.removeIndexInterval(0, Integer.MAX_VALUE) fails [v9]
Alexey Ivanov
aivanov at openjdk.org
Sun Oct 30 14:05:32 UTC 2022
On Fri, 28 Oct 2022 03:32:18 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:
>> DefaultListSelectionModel.removeIndexInterva accepts `int` value which allows it to take in Integer.MAX_VALUE theoratically but it does calculation with that value which can results in IOOBE.
>> Fix is to make sure the calculation stays within bounds.
>
> Prasanta Sadhukhan has updated the pull request incrementally with two additional commits since the last revision:
>
> - Review fix
> - Review fix
This looks good now. All the tests pass successfully.
Could you optimise the imports, please? To eliminate the wildcard import.
Could you also update the copyright year?
Would you mind adding the `final` modifier to parameters and local variables in `insertIndexInterval` and `removeIndexInterval` to _explicitly_ declare that they're not modified in the method? That is to `index`, `length`, `before` and `insMinIndex`, `insMaxIndex`; and `index0`, `index1` and `rmMinIndex`, `rmMaxIndex`, `gapLength` correspondingly.
src/java.desktop/share/classes/javax/swing/DefaultListSelectionModel.java line 452:
> 450: clear(i);
> 451: }
> 452: // Integer overflow
Would _“Prevent integer overflow”_ sound even better?
src/java.desktop/share/classes/javax/swing/DefaultListSelectionModel.java line 654:
> 652: {
> 653: if (length < 0 || index < 0) {
> 654: throw new IndexOutOfBoundsException("index or length is negative");
In fact, I also thought about modifying `length` but I didn't figure it out — you did.
-------------
Marked as reviewed by aivanov (Reviewer).
PR: https://git.openjdk.org/jdk/pull/10409
More information about the client-libs-dev
mailing list