Re: Reply: what to do next to fix JDK-8230557. thanks

Peter Levart peter.levart at gmail.com
Thu Sep 5 13:40:17 UTC 2019


Hi 未来阳光,

On 9/5/19 10: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.

Unfortunately, when such bug is out in the wild for so long, it becomes 
a feature. It would be unreasonable to fix it the way you propose now, 
because all programs that use BitSet.size() method would break by such 
fix. It is not only source incompatible fix, but binary incompatible too.

>
> User can't understand why the size method return a negative number.

Perhaps, if the javadoc of the method described this corner case, he/she 
would understand?

Regards, Peter

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



More information about the core-libs-dev mailing list