RFR: 8305734: BitSet.get(int, int) always returns the empty BitSet when the Integer.MAX VALUE is set
Andy-Tatman
duke at openjdk.org
Mon Apr 24 09:39:46 UTC 2023
On Fri, 7 Apr 2023 12:22:03 GMT, Andy-Tatman <duke at openjdk.org> wrote:
> See https://bugs.java.com/bugdatabase/view_bug?bug_id=8305734
I realise this is a bit off-topic for this specific bug, but perhaps relevant for the specification: The size() function can already start to overflow with much smaller indices being set, due to how ensureCapacity(int) currently works.
`BitSet bitSet = new BitSet(0);`
`bitSet.set(Integer.MAX_VALUE/2);`
`System.out.println("size = " + bitSet.size());`
`bitSet.set(Integer.MAX_VALUE/2 + 64);`
`System.out.println("size = " + bitSet.size());`
The second size() call has already overflown, due to the fact that ensureCapacity always grows the words array to at least twice the original size.
Furthermore, my impression is that any bit over Integer.MAX_VALUE-64 being set will always cause size() to overflow.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/13388#issuecomment-1519733075
More information about the core-libs-dev
mailing list