[
https://issues.apache.org/jira/browse/OAK-6164?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15996316#comment-15996316
]
Michael Dürig commented on OAK-6164:
------------------------------------
[~mattvryan], thanks for sending a patch. Looks good!
I wonder though whether we could/should change the return type of
{{nextPowerOf2}} from {{int}} to {{long}}. This would allow us to handle the
values in the range \[0x40000000, 0x7FFFFFFF] uniformly. This is the approach
I've taken with {{PriorityCache.nextPowerOfTwo()}} (where I probably wasn't
aware of {{IOUtils}}).
WDYT?
> 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)