JDK-8264976 : Minor numeric bug in AbstractSplittableWithBrineGenerator.makeSplitsSpliterator
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 17
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-04-09
  • Updated: 2021-04-22
  • Resolved: 2021-04-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17
17 b19Fixed
Related Reports
Relates :  
Description
SonarCloud reports:
  Cast one of the operands of this subtraction operation to a "long".

Here:
        Spliterator<SplittableGenerator> makeSplitsSpliterator(long index, long fence, SplittableGenerator source) {
            ...
            long multiplier = (1 << SALT_SHIFT) - 1; // <---- here

The shift is integer, and the cast to long is too late. SALT_SHIFT is currently 4, so this is not the problem. But it would become a problem if SALT_SHIFT ever becomes 32 or larger. The shift operand should be 1L for safety. Observe:

jshell> Long.toHexString((1 << 31) - 1)
$2 ==> "7fffffff"

jshell> Long.toHexString((1 << 32) - 1)
$3 ==> "0"

jshell> Long.toHexString((1L << 32) - 1)
$4 ==> "ffffffff"

Comments
Changeset: 94067446 Author: Aleksey Shipilev <shade@openjdk.org> Date: 2021-04-14 16:16:41 +0000 URL: https://git.openjdk.java.net/jdk/commit/94067446
14-04-2021