You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Michael Dürig (JIRA)" <ji...@apache.org> on 2017/05/04 07:54:05 UTC

[jira] [Assigned] (OAK-6164) IOUtils.nextPowerOf2() returns lower power of 2 for very high int values

     [ https://issues.apache.org/jira/browse/OAK-6164?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Dürig reassigned OAK-6164:
----------------------------------

    Assignee: Michael Dürig

> IOUtils.nextPowerOf2() returns lower power of 2 for very high int values
> ------------------------------------------------------------------------
>
>                 Key: OAK-6164
>                 URL: https://issues.apache.org/jira/browse/OAK-6164
>             Project: Jackrabbit Oak
>          Issue Type: Bug
>          Components: commons
>            Reporter: Matt Ryan
>            Assignee: Michael Dürig
>            Priority: Minor
>             Fix For: 1.7.0, 1.8
>
>         Attachments: OAK-6164.patch.1, OAK-6164.patch.2
>
>
> In the IOUtils.nextPowerOf2() method, all int values are accepted as input.  However, there are valid signed integer values that this method accepts as input, but for which a lower power of 2 value is returned.
> This occurs for values that are valid signed integer values that are greater than the highest possible power of two value in the signed integer range.  Signed integer values have the maximum value of 0x7FFFFFFF, but the maximum possible power of two in the signed integer range is 0x40000000.  (The current implementation incorrectly identifies the maximum possible power of two as 0x3FFFFFFF, due to how it is computed by doing integer division of 0x7FFFFFFF / 2.)
> In the current implementation any input in the range of [0x40000000, 0x7FFFFFFF] is a valid signed integer input, but the method will return 0x3FFFFFFF as the next valid max power of 2.
> Two minor things need to be fixed:
> * If the input is 0x40000000, the return value needs to be 0x40000000, instead of 0x3FFFFFFF which is not a valid power of 2.
> * If the input is in the range [0x40000001, 0x7FFFFFFF] I propose the method should instead throw an IllegalArgumentException and indicate that it is not possible to compute a next power of 2 for a number in that range.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)