Hi, Peter.

the length method return a negative number too



 


Best, lamber-ken




------------------ ???????? ------------------
??????:&nbsp;"Peter Levart"<peter.lev...@gmail.com&gt;;
????????:&nbsp;2019??9??5??(??????) ????3:51
??????:&nbsp;"????????"<2217232...@qq.com&gt;;"core-libs-dev"<core-libs-dev@openjdk.java.net&gt;;
????:&nbsp;"David Holmes"<david.hol...@oracle.com&gt;;
????:&nbsp;Re: ?????? ?????? what to do next to fix JDK-8230557. thanks



Hi ????????,

As David has pointed out, your proposed fix would break binary and 
source compatibility of BitSet.size() method, so it is not acceptable.

BitSet API allows addressing individual bits using non-negative 'int' 
typed indexes (analogous to indexes of Java arrays). The range of 
indexes is: 0 ... 2^31 - 1 (0 ... Integer.MAX_VALUE). The maximum "size" 
of BitSet is therefore 2^31. Unfortunately, this value can't be 
"corectly" represented with signed 32 bit integer (int). Only in this 
corner case, - 2^31 (Integer.MIN_VALUE) is the interpreted value 
returned from size(). If one would interpret it as unsigned 32 bit 
integer value, it is entirely correct. For example, this holds:

Integer.toUnsignedLong(new BitSet(Integer.MAX_VALUE).size()) == 1L << 31

It is also always true what javadoc says about size(): "The maximum 
element in the set is the size - 1st element"

The following holds also for this corner case:

new BitSet(Integer.MAX_VALUE).size() - 1 == Integer.MAX_VALUE;

So perhaps, the fix could be just to describe this corner case in the 
spec. And perhaps, to support the following use case in the corner case:

BitSet set1 = ...
...

BitSet set2 = new BitSet(set1.size());

... by modifying the BitSet constructor to accept the Integer.MIN_VALUE 
in addition to all the non-negative values as the 'nbits' parameter.

What do you think?

Regards, Peter

On 9/5/19 8:31 AM, David Holmes wrote:
&gt; Hi,
&gt;
&gt; On 5/09/2019 4:11 pm, ???????? wrote:
&gt;&gt;
&gt;&gt; Thanks very much.
&gt;&gt;
&gt;&gt; *BUG-LINK:* https://bugs.openjdk.java.net/browse/JDK-8230557
&gt;&gt;
&gt;&gt; *Describe: *
&gt;&gt; the return type of the method BitSet#size is int, so the method may 
&gt;&gt; return a negative value in some case, for example, will return 
&gt;&gt; -2147483648.
&gt;&gt; ```
&gt;&gt; BitSet bitSet = new BitSet(Integer.MAX_VALUE);
&gt;&gt; for (int i = 0; i < Integer.MAX_VALUE - 1000; i++) {
&gt;&gt; &nbsp;&nbsp;&nbsp;&nbsp; bitSet.set(i);
&gt;&gt; }
&gt;&gt; System.out.println(bitSet.size());
&gt;&gt; ```
&gt;&gt; EXPECTED: 2147483648, but ACTUAL: -2147483648.
&gt;&gt;
&gt;&gt; *FIX*
&gt;&gt; I have put the patch in the attachment of the mail.
&gt;
&gt; In case the attachment got stripped form the mailing list the proposed 
&gt; fix is:
&gt;
&gt; -&nbsp; &nbsp; public int size() {
&gt; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return words.length * BITS_PER_WORD;
&gt; +&nbsp; &nbsp; public long size() {
&gt; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; return (long) words.length * 
BITS_PER_WORD;
&gt;
&gt; Unfortunately this simple fix it not possible. You can't just change 
&gt; the return type of the method to long as that is a source-incompatible 
&gt; change and would not be approved [1]. Instead the return value should 
&gt; be capped at Integer.MAX_VALUE - but I'll leave that for someone from 
&gt; core-libs team to pick up. Also look at the evaluation in:
&gt;
&gt; https://bugs.openjdk.java.net/browse/JDK-4213570
&gt;
&gt; Cheers,
&gt; David
&gt;
&gt; [1] https://wiki.openjdk.java.net/display/csr/CSR+FAQs
&gt;
&gt;
&gt;
&gt;&gt;
&gt;&gt; ------------------ ???????? ------------------
&gt;&gt; *??????:* "David Holmes"<david.hol...@oracle.com&gt;;
&gt;&gt; *????????:* 2019??9??5??(??????) ????2:00
&gt;&gt; *??????:* "????????"<2217232...@qq.com&gt;;"core-libs-dev"<core-libs- 
&gt;&gt; d...@openjdk.java.net&gt;;
&gt;&gt; *????:* Re: ?????? what to do next to fix JDK-8230557. thanks
&gt;&gt;
&gt;&gt; On 5/09/2019 3:46 pm, ???????? wrote:
&gt;&gt; &nbsp;&gt;
&gt;&gt; &nbsp;&gt; hi, developers.
&gt;&gt; &nbsp;&gt;
&gt;&gt; &nbsp;&gt; Can someone help me? thanks very much !!
&gt;&gt;
&gt;&gt; Help you how exactly. As I stated your are up to step 2 of the how to
&gt;&gt; contribute process. If you have a suggested fix for the bug then put
&gt;&gt; that in an email as described.
&gt;&gt;
&gt;&gt; Thanks,
&gt;&gt; David
&gt;&gt;
&gt;&gt; &nbsp;&gt;
&gt;&gt; &nbsp;&gt; ------------------ ???????? ------------------
&gt;&gt; &nbsp;&gt; *??????:* "David Holmes"<david.hol...@oracle.com&gt;;
&gt;&gt; &nbsp;&gt; *????????:* 2019??9??5??(??????) ????1:44
&gt;&gt; &nbsp;&gt; *??????:* 
"????????"<2217232...@qq.com&gt;;"core-libs-dev"<core-libs-
&gt;&gt; &nbsp;&gt; d...@openjdk.java.net&gt;;
&gt;&gt; &nbsp;&gt; *????:* Re: what to do next to fix JDK-8230557. thanks
&gt;&gt; &nbsp;&gt;
&gt;&gt; &nbsp;&gt; On 5/09/2019 3:35 pm, ???????? wrote:
&gt;&gt; &nbsp;&gt;&nbsp; &gt; Hi, leaders.
&gt;&gt; &nbsp;&gt;
&gt;&gt; &nbsp;&gt; Hi,
&gt;&gt; &nbsp;&gt;
&gt;&gt; &nbsp;&gt; No "leaders" here only developers :)
&gt;&gt; &nbsp;&gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt; A few days ago, I report a bug in core lib[1]. 
According to the
&gt;&gt; &nbsp;&gt; contribute document[2], I had send oca to oracle 
and&amp;nbsp;my name has
&gt;&gt; &nbsp;&gt; been listed on&amp;nbsp;oca[3].
&gt;&gt; &nbsp;&gt;
&gt;&gt; &nbsp;&gt; Welcome aboard!
&gt;&gt; &nbsp;&gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt; But I still can't push my changes to jdk, can 
someone tell me 
&gt;&gt; how to
&gt;&gt; &nbsp;&gt; do next? thanks very match!!
&gt;&gt; &nbsp;&gt;
&gt;&gt; &nbsp;&gt; You can't push anything until you become a Committer and 
before 
&gt;&gt; that you
&gt;&gt; &nbsp;&gt; have to become an Author. The steps for contributing are 
outlined 
&gt;&gt; here:
&gt;&gt; &nbsp;&gt;
&gt;&gt; &nbsp;&gt; http://openjdk.java.net/contribute/
&gt;&gt; &nbsp;&gt;
&gt;&gt; &nbsp;&gt; and you would seem to be up to step 2. :)
&gt;&gt; &nbsp;&gt;
&gt;&gt; &nbsp;&gt; Cheers,
&gt;&gt; &nbsp;&gt; David
&gt;&gt; &nbsp;&gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt; 
[1]https://bugs.openjdk.java.net/browse/JDK-8230557
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt; [2]http://openjdk.java.net/contribute/
&gt;&gt; &nbsp;&gt;&nbsp; &gt; 
[3]https://www.oracle.com/technetwork/community/oca-486395.html
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt; 
------------------&amp;nbsp;????????&amp;nbsp;------------------
&gt;&gt; &nbsp;&gt;&nbsp; &gt; ??????:&amp;nbsp;"Bug Report
&gt;&gt; &nbsp;&gt; Notification"<bug-report-daemon...@oracle.com&amp;gt;;
&gt;&gt; &nbsp;&gt;&nbsp; &gt; ????????:&amp;nbsp;2019??9??5??(??????) ????3:33
&gt;&gt; &nbsp;&gt;&nbsp; &gt; 
??????:&amp;nbsp;"????????"<2217232...@qq.com&amp;gt;;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt; ????:&amp;nbsp;Update Notification: Bug 
Report&nbsp; - JDK-8230557
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; [This is an automated response. Please 
&gt;&gt; do not
&gt;&gt; &nbsp;&gt; reply.]
&gt;&gt; &nbsp;&gt;&nbsp; &gt; Dear Java Developer,
&gt;&gt; &nbsp;&gt;&nbsp; &gt; We have finished evaluating your report and have 
assigned it a Bug
&gt;&gt; &nbsp;&gt; ID: JDK-8230557. The issue is visible on bugs.java.com at 
the 
&gt;&gt; following
&gt;&gt; &nbsp;&gt; url JDK-8230557.
&gt;&gt; &nbsp;&gt;&nbsp; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; To provide more information about this issue,
&gt;&gt; &nbsp;&gt; click&nbsp; here.
&gt;&gt; &nbsp;&gt;&nbsp; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; We work to resolve the issues that are 
&gt;&gt; submitted to
&gt;&gt; &nbsp;&gt; us according to their impact to the community as a whole, 
and make no
&gt;&gt; &nbsp;&gt; promises as to the time or release in which a bug might be 
fixed. If
&gt;&gt; &nbsp;&gt; this issue has a significant impact on your project you may 
want to
&gt;&gt; &nbsp;&gt; consider using one of the technical support offerings 
available at
&gt;&gt; &nbsp;&gt; Oracle Support.
&gt;&gt; &nbsp;&gt;&nbsp; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; Regards,
&gt;&gt; &nbsp;&gt;&nbsp; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; Java Developer Support
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt;
&gt;&gt; &nbsp;&gt;&nbsp; &gt; Java SE
&gt;&gt; &nbsp;&gt;&nbsp; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; Java SE Documentation
&gt;&gt; &nbsp;&gt;&nbsp; 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; Java SE Downloads
&gt;&gt; &nb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