> 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]`.

Archie Cobbs has updated the pull request incrementally with two additional 
commits since the last revision:

 - Use -> in switch statement.
 - Update copyright year.

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/27102/files
  - new: https://git.openjdk.org/jdk/pull/27102/files/021e0fb3..89fe2fb1

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=27102&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=27102&range=01-02

  Stats: 7 lines in 2 files changed: 1 ins; 0 del; 6 mod
  Patch: https://git.openjdk.org/jdk/pull/27102.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/27102/head:pull/27102

PR: https://git.openjdk.org/jdk/pull/27102

Reply via email to