Matt Ryan created OAK-6164:
------------------------------
Summary: 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
Reporter: Matt Ryan
Priority: Minor
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)