JDK-8288414 : Long::compress/expand samples are not correct
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 19
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-06-14
  • Updated: 2022-06-16
  • Resolved: 2022-06-15
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 19 JDK 20
19 masterFixed 20Fixed
Related Reports
Relates :  
Description
The samples provided in java doc https://download.java.net/java/early_access/jdk19/docs/api/java.base/java/lang/Long.html#compress(long,long)  looks not resulting as it states.

For example :

Consider the simple case of compressing the digits of a hexadecimal value:

// Compressing drink to food
compress(0xCAFEBABE, 0xFF00FFF0) == 0xCABAB

The result is  if(Long.compress(0xCAFEBABE, 0xFF00FFF0) == 0xCABAB){} 
different.

And same for subsequent samples in case of Long 

// Returns 1 if the bit at position n is one
compress(x, 1 << n) == (x >> n & 1)

// Logical shift right
compress(x, -1 << n) == x >>> n
....


But these samples works as stated in case of Integer.






Comments
Changeset: 395aea30 Author: Paul Sandoz <psandoz@openjdk.org> Date: 2022-06-15 19:21:13 +0000 URL: https://git.openjdk.org/jdk19/commit/395aea307faa96bf78ddc15798ba7d855c2db170
15-06-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk19/pull/14 Date: 2022-06-14 16:28:37 +0000
14-06-2022

Need to use explicit long constants
14-06-2022