Hi, can we make `size()` and `length()` as deprecated, then write new methods ?
Best. ------------------ 原始邮件 ------------------ 发件人: "Peter Levart"<peter.lev...@gmail.com>; 发送时间: 2019年9月5日(星期四) 晚上10:24 收件人: "Ivan Gerasimov"<ivan.gerasi...@oracle.com>;"未来阳光"<2217232...@qq.com>;"core-libs-dev"<core-libs-dev@openjdk.java.net>; 主题: Re: Reply: what to do next to fix JDK-8230557. thanks Hi Ivan, On 9/5/19 11:22 AM, Ivan Gerasimov wrote: > Hello! > > BitSet is known to be flawed in many ways: its size(), length(), > cardinality() and nextClearBit() can return meaningless negative values. > > I was thinking about disallowing setting any index greater than > (Integer.MAX_VALUE - 63), for example by throwing OutOfMemoryError. An index of Integer.MAX_VALUE - 64 would be the greatest index then, an index of Integer.MAX_VALUE - 63 already needs an array of longs of length 2^25 which results in BitSet size() of 2^31 ... > > We could do it without changing the specification. The calls to: new BitSet(Integer.MAX_VALUE - 63) ... new BitSet(Integer.MAX_VALUE) would also have to throw then. BitSet.valueOf(...) methods don't even check the passed in arguments lengths, so size() can really return a meaningless negative or positive number. They all would have to throw if the passed-in length of array/buffer is too large. So would you not specify when those methods throw? Regards, Peter > > With kind regards, > > Ivan > > > On 9/5/19 1:16 AM, 未来阳光 wrote: >> Hi, Peter. >> >> >> I understand your point, but I think it's unreasonable for the reason >> that source code compatibility problem, it's really a bug. >> >> >> User can't understand why the size method return a negative number. >> >> >> >> &nbsp; >> >> >> Best, lamber-ken >> >> >> >> >> ------------------&nbsp;原始邮件&nbsp;------------------ >> 发件人:&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;&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;&nbsp; public int size() { >> &gt; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return words.length >> * BITS_PER_WORD; >> &gt; +&nbsp;&nbsp;&nbsp; public long size() { >> &gt; +&nbsp;&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; ------------------&nbsp;原始邮件&nbsp;------------------ >> &gt;&gt; *发件人:*&nbsp;"David Holmes"<david.hol...@oracle.com&gt;; >> &gt;&gt; *发送时间:*&nbsp;2019年9月5日(星期四) 下午2:00 >> &gt;&gt; >> *收件人:*&nbsp;"未来阳光"<2217232...@qq.com&gt;;"core-libs-dev"<core-libs- >> &gt;&gt; d...@openjdk.java.net&gt;; >> &gt;&gt; *主题:*&nbsp;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; >> ------------------&nbsp;原始邮件&nbsp;------------------ >> &gt;&gt; &nbsp;&gt; *发件人:*&nbsp;"David >> Holmes"<david.hol...@oracle.com&gt;; >> &gt;&gt; &nbsp;&gt; *发送时间:*&nbsp;2019年9月5日(星期四) 中午1:44 >> &gt;&gt; &nbsp;&gt; >> *收件人:*&nbsp;"未来阳光"<2217232...@qq.com&gt;;"core-libs-dev"<core-libs- >> &gt;&gt; &nbsp;&gt; d...@openjdk.java.net&gt;; >> &gt;&gt; &nbsp;&gt; *主题:*&nbsp;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;&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;&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;&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;&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;&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;&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;&nbsp; >> Java SE Downloads >> &gt;&gt; &nbsp;&gt;&nbsp; >> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; >> Java Developer Forums >> &gt;&gt; &nbsp;&gt;&nbsp; >> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; >> Oracle Java SE Advanced >> &gt;&gt; &nbsp;&gt;&nbsp; >> &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; >> Bug Database >> &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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; >> Copyright © Oracle >> &gt;&gt; and/or >> &gt;&gt; &nbsp;&gt; its affiliates. All rights reserved. >> &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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; >> Terms of Use >> |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; >> &gt;&gt; Privacy >> &gt;&gt; &nbsp;&gt;&nbsp; &gt; >