You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Imran Ghory (JIRA)" <ji...@apache.org> on 2007/11/08 00:33:50 UTC

[jira] Created: (HARMONY-5088) [classlib][math] BigInteger(int numBits, Random rnd) constructor contains overflow

[classlib][math] BigInteger(int numBits, Random rnd)  constructor contains overflow
-----------------------------------------------------------------------------------

                 Key: HARMONY-5088
                 URL: https://issues.apache.org/jira/browse/HARMONY-5088
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
            Reporter: Imran Ghory


If numBits = Integer.MAX_VALUE then you have an integer overflow situation on the following lines:

numberLength = (numBits + 31) >> 5;
digits = new int[numberLength];



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-5088) [classlib][math] BigInteger(int numBits, Random rnd) constructor contains overflow

Posted by "Paulex Yang (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-5088?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paulex Yang updated HARMONY-5088:
---------------------------------

    Attachment:     (was: HARMONY-5088.diff)

> [classlib][math] BigInteger(int numBits, Random rnd)  constructor contains overflow
> -----------------------------------------------------------------------------------
>
>                 Key: HARMONY-5088
>                 URL: https://issues.apache.org/jira/browse/HARMONY-5088
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Imran Ghory
>            Assignee: Paulex Yang
>         Attachments: HARMONY-5088.diff
>
>
> If numBits = Integer.MAX_VALUE then you have an integer overflow situation on the following lines:
> numberLength = (numBits + 31) >> 5;
> digits = new int[numberLength];

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-5088) [classlib][math] BigInteger(int numBits, Random rnd) constructor contains overflow

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-5088?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12544743 ] 

Tim Ellison commented on HARMONY-5088:
--------------------------------------

Why would you do that Paulex?  Seems that the correct behaviour would be as described in Imran's last comment (i.e. no Neg array exception, and a NPE if rnd is null).

I suggest it is fixed in both 5.0 and 6.0 streams.


> [classlib][math] BigInteger(int numBits, Random rnd)  constructor contains overflow
> -----------------------------------------------------------------------------------
>
>                 Key: HARMONY-5088
>                 URL: https://issues.apache.org/jira/browse/HARMONY-5088
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Imran Ghory
>            Assignee: Paulex Yang
>
> If numBits = Integer.MAX_VALUE then you have an integer overflow situation on the following lines:
> numberLength = (numBits + 31) >> 5;
> digits = new int[numberLength];

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-5088) [classlib][math] BigInteger(int numBits, Random rnd) constructor contains overflow

Posted by "Imran Ghory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-5088?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12544575 ] 

Imran Ghory commented on HARMONY-5088:
--------------------------------------

I verifed that calling the constructor with Integer.MAX_VALUE works with 1.6.0_03 of the RI. Further more the test case we're using: "new BigInteger(Integer.MAX_VALUE, (Random)null) "  causes the RI to throw a null pointer exception.

> [classlib][math] BigInteger(int numBits, Random rnd)  constructor contains overflow
> -----------------------------------------------------------------------------------
>
>                 Key: HARMONY-5088
>                 URL: https://issues.apache.org/jira/browse/HARMONY-5088
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Imran Ghory
>            Assignee: Paulex Yang
>
> If numBits = Integer.MAX_VALUE then you have an integer overflow situation on the following lines:
> numberLength = (numBits + 31) >> 5;
> digits = new int[numberLength];

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Reopened: (HARMONY-5088) [classlib][math] BigInteger(int numBits, Random rnd) constructor contains overflow

Posted by "Imran Ghory (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-5088?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Imran Ghory reopened HARMONY-5088:
----------------------------------


> [classlib][math] BigInteger(int numBits, Random rnd)  constructor contains overflow
> -----------------------------------------------------------------------------------
>
>                 Key: HARMONY-5088
>                 URL: https://issues.apache.org/jira/browse/HARMONY-5088
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Imran Ghory
>            Assignee: Paulex Yang
>
> If numBits = Integer.MAX_VALUE then you have an integer overflow situation on the following lines:
> numberLength = (numBits + 31) >> 5;
> digits = new int[numberLength];

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-5088) [classlib][math] BigInteger(int numBits, Random rnd) constructor contains overflow

Posted by "Paulex Yang (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-5088?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paulex Yang updated HARMONY-5088:
---------------------------------

    Attachment: HARMONY-5088.diff

I preferred to leave the difference alone and make both NPE and OOME are accepttable(refer to attached patch for details). How do you think?

> [classlib][math] BigInteger(int numBits, Random rnd)  constructor contains overflow
> -----------------------------------------------------------------------------------
>
>                 Key: HARMONY-5088
>                 URL: https://issues.apache.org/jira/browse/HARMONY-5088
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Imran Ghory
>            Assignee: Paulex Yang
>         Attachments: HARMONY-5088.diff
>
>
> If numBits = Integer.MAX_VALUE then you have an integer overflow situation on the following lines:
> numberLength = (numBits + 31) >> 5;
> digits = new int[numberLength];

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-5088) [classlib][math] BigInteger(int numBits, Random rnd) constructor contains overflow

Posted by "Paulex Yang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-5088?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12544718 ] 

Paulex Yang commented on HARMONY-5088:
--------------------------------------

I tried it against RI 1.5.0_09 on winxp.x86 before, and just tried on RI 6, you are right that seems this is fixed at that build. How about I fixed it on Harmony java6 branch and leave the trunk (java 5  level) intact? 

> [classlib][math] BigInteger(int numBits, Random rnd)  constructor contains overflow
> -----------------------------------------------------------------------------------
>
>                 Key: HARMONY-5088
>                 URL: https://issues.apache.org/jira/browse/HARMONY-5088
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Imran Ghory
>            Assignee: Paulex Yang
>
> If numBits = Integer.MAX_VALUE then you have an integer overflow situation on the following lines:
> numberLength = (numBits + 31) >> 5;
> digits = new int[numberLength];

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (HARMONY-5088) [classlib][math] BigInteger(int numBits, Random rnd) constructor contains overflow

Posted by "Paulex Yang (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-5088?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paulex Yang updated HARMONY-5088:
---------------------------------

    Attachment: HARMONY-5088.diff

ASF license.

> [classlib][math] BigInteger(int numBits, Random rnd)  constructor contains overflow
> -----------------------------------------------------------------------------------
>
>                 Key: HARMONY-5088
>                 URL: https://issues.apache.org/jira/browse/HARMONY-5088
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Imran Ghory
>            Assignee: Paulex Yang
>         Attachments: HARMONY-5088.diff
>
>
> If numBits = Integer.MAX_VALUE then you have an integer overflow situation on the following lines:
> numberLength = (numBits + 31) >> 5;
> digits = new int[numberLength];

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-5088) [classlib][math] BigInteger(int numBits, Random rnd) constructor contains overflow

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-5088?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12544462 ] 

Tim Ellison commented on HARMONY-5088:
--------------------------------------

Maybe worth adding a comment to BigInteger.java to explain that to code readers?


> [classlib][math] BigInteger(int numBits, Random rnd)  constructor contains overflow
> -----------------------------------------------------------------------------------
>
>                 Key: HARMONY-5088
>                 URL: https://issues.apache.org/jira/browse/HARMONY-5088
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Imran Ghory
>            Assignee: Paulex Yang
>
> If numBits = Integer.MAX_VALUE then you have an integer overflow situation on the following lines:
> numberLength = (numBits + 31) >> 5;
> digits = new int[numberLength];

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[classlib][math] BigInteger(int numBits, Random rnd) constructor contains overflow

Posted by Tim Ellison <t....@gmail.com>.
I don't think that trying to throw an OutOfMemoryError is going to be
useful here.

Imran:  What is the scenario?  Is this behavior expected by some
application or is this just something you came across?

I suggest we leave it as NPE.

Regards,
Tim


Paulex Yang (JIRA) wrote:
>     [ https://issues.apache.org/jira/browse/HARMONY-5088?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12546162 ] 
> 
> Paulex Yang commented on HARMONY-5088:
> --------------------------------------
> 
> I got problem to comply with RI 1.6_03 here,  new BigInteger(Integer.MAX_VALUE, (Random)null) throws OutOfMemoryError on both windows/linux, while my modification like below throws NPE.
> 
> - numberLength = (numBits + 31) >> 5;
> + numberLength = (numBits + 31) >>> 5;
> 
> I have no idea how to make a OOME except explicitly new one, which is too ugly to me. Any ideas?
> 
> 
>> [classlib][math] BigInteger(int numBits, Random rnd)  constructor contains overflow
>> -----------------------------------------------------------------------------------
>>
>>                 Key: HARMONY-5088
>>                 URL: https://issues.apache.org/jira/browse/HARMONY-5088
>>             Project: Harmony
>>          Issue Type: Bug
>>          Components: Classlib
>>            Reporter: Imran Ghory
>>            Assignee: Paulex Yang
>>
>> If numBits = Integer.MAX_VALUE then you have an integer overflow situation on the following lines:
>> numberLength = (numBits + 31) >> 5;
>> digits = new int[numberLength];
> 

[jira] Commented: (HARMONY-5088) [classlib][math] BigInteger(int numBits, Random rnd) constructor contains overflow

Posted by "Paulex Yang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-5088?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12546162 ] 

Paulex Yang commented on HARMONY-5088:
--------------------------------------

I got problem to comply with RI 1.6_03 here,  new BigInteger(Integer.MAX_VALUE, (Random)null) throws OutOfMemoryError on both windows/linux, while my modification like below throws NPE.

- numberLength = (numBits + 31) >> 5;
+ numberLength = (numBits + 31) >>> 5;

I have no idea how to make a OOME except explicitly new one, which is too ugly to me. Any ideas?


> [classlib][math] BigInteger(int numBits, Random rnd)  constructor contains overflow
> -----------------------------------------------------------------------------------
>
>                 Key: HARMONY-5088
>                 URL: https://issues.apache.org/jira/browse/HARMONY-5088
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Imran Ghory
>            Assignee: Paulex Yang
>
> If numBits = Integer.MAX_VALUE then you have an integer overflow situation on the following lines:
> numberLength = (numBits + 31) >> 5;
> digits = new int[numberLength];

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-5088) [classlib][math] BigInteger(int numBits, Random rnd) constructor contains overflow

Posted by "Paulex Yang (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-5088?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12545780 ] 

Paulex Yang commented on HARMONY-5088:
--------------------------------------

hmm...I just had a little concern about the compatibility with RI 5. But I'm fine to fix it in trunk, too, I cannot imagine an application will be break if our BigInteger are more defensive here, will commit a fix soon.

> [classlib][math] BigInteger(int numBits, Random rnd)  constructor contains overflow
> -----------------------------------------------------------------------------------
>
>                 Key: HARMONY-5088
>                 URL: https://issues.apache.org/jira/browse/HARMONY-5088
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Imran Ghory
>            Assignee: Paulex Yang
>
> If numBits = Integer.MAX_VALUE then you have an integer overflow situation on the following lines:
> numberLength = (numBits + 31) >> 5;
> digits = new int[numberLength];

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (HARMONY-5088) [classlib][math] BigInteger(int numBits, Random rnd) constructor contains overflow

Posted by "Imran Ghory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-5088?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12544544 ] 

Imran Ghory commented on HARMONY-5088:
--------------------------------------

I just googled for confirmation of  that being the correct behaviour and turned up the following:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050278

If the RI has the same behaviour it looks like it's a regression on their part, it looks like that constructor worked for Interger.MAX_VALUE in  RI in version 1.4.2 (I haven't verified this).


> [classlib][math] BigInteger(int numBits, Random rnd)  constructor contains overflow
> -----------------------------------------------------------------------------------
>
>                 Key: HARMONY-5088
>                 URL: https://issues.apache.org/jira/browse/HARMONY-5088
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Imran Ghory
>            Assignee: Paulex Yang
>
> If numBits = Integer.MAX_VALUE then you have an integer overflow situation on the following lines:
> numberLength = (numBits + 31) >> 5;
> digits = new int[numberLength];

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (HARMONY-5088) [classlib][math] BigInteger(int numBits, Random rnd) constructor contains overflow

Posted by "Paulex Yang (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-5088?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paulex Yang resolved HARMONY-5088.
----------------------------------

    Resolution: Won't Fix
      Assignee: Paulex Yang

Imran, the overflow causes NegativeArraySizeException thrown, which complies with RI's behavior. Please refer to tests.api.java.math.BigIntegerTest.test_ConstructorILjava_util_Random() for details. Let me know if the resolution is not satisfied, thanks.


> [classlib][math] BigInteger(int numBits, Random rnd)  constructor contains overflow
> -----------------------------------------------------------------------------------
>
>                 Key: HARMONY-5088
>                 URL: https://issues.apache.org/jira/browse/HARMONY-5088
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Imran Ghory
>            Assignee: Paulex Yang
>
> If numBits = Integer.MAX_VALUE then you have an integer overflow situation on the following lines:
> numberLength = (numBits + 31) >> 5;
> digits = new int[numberLength];

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.