Skip to content

Conversation

archiecobbs
Copy link
Contributor

@archiecobbs archiecobbs commented Sep 4, 2025

When bit shifting an int or long value by an amount X, all but the last 5 or 6 (respectively) bits of X are ignored.

This can create a trap for the unwary, as in this example:

public long readLongBigEndian(byte[] buf, int offset) {
    return ((buf[offset + 0] & 0xff) << 56)   // BUG HERE
         | ((buf[offset + 1] & 0xff) << 48)   // BUG HERE
         | ((buf[offset + 2] & 0xff) << 40)   // BUG HERE
         | ((buf[offset + 3] & 0xff) << 32)   // BUG HERE
         | ((buf[offset + 4] & 0xff) << 24)
         | ((buf[offset + 5] & 0xff) << 16)
         | ((buf[offset + 6] & 0xff) << 8)
         | ((buf[offset + 7] & 0xff);
}

This PR adds a new warning when the compiler detects an out-of-range bit shift, i.e., an int bit shift not in the range [0...31] or a long bit shift not in the range [0...63].


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires CSR request JDK-8366919 to be approved

Issues

  • JDK-5038439: Warning message for literal shift amounts outside the canonical domain (Enhancement - P4)
  • JDK-8366919: Warning message for literal shift amounts outside the canonical domain (CSR)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27102/head:pull/27102
$ git checkout pull/27102

Update a local copy of the PR:
$ git checkout pull/27102
$ git pull https://git.openjdk.org/jdk.git pull/27102/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27102

View PR using the GUI difftool:
$ git pr show -t 27102

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27102.diff

@archiecobbs
Copy link
Contributor Author

/csr

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 4, 2025

👋 Welcome back acobbs! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Sep 4, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Sep 4, 2025
@openjdk
Copy link

openjdk bot commented Sep 4, 2025

@archiecobbs has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@archiecobbs please create a CSR request for issue JDK-5038439 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

@openjdk
Copy link

openjdk bot commented Sep 4, 2025

@archiecobbs The following labels will be automatically applied to this pull request:

  • build
  • compiler
  • hotspot-compiler
  • security

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

1 participant