LouisLou2 opened a new issue, #2096:
URL: https://github.com/apache/fury/issues/2096

   ### Search before asking
   
   - [x] I had searched in the [issues](https://github.com/apache/fury/issues) 
and found no similar issues.
   
   
   ### Version
   
   Fury Java 0.10.0
   
   ### Component(s)
   
   Java
   
   ### Minimal reproduce step
   
   1. Use the following method in your Java code:
      ```java
      /** Read {@code len} bytes into a long using little-endian order. */
      public long readBytesAsInt64(int len) {
          int readerIdx = readerIndex;
          int remaining = size - readerIdx;
          if (remaining >= 8) {
              readerIndex = readerIdx + len;
              long v = UNSAFE.getLong(heapMemory, address + readerIdx);
              v = (LITTLE_ENDIAN ? v : Long.reverseBytes(v)) & 
(0xffffffffffffffffL >>> ((8 - len) * 8));
              return v;
          }
          return slowReadBytesAsInt64(remaining, len);
      }
      ```
   
   2. Call this method with `len = 0`.
   
   ### What did you expect to see?
   
   When `len = 0`, I expected the bitwise AND operation (&) with 
`0xffffffffffffffffL >>> 64` to return a value of `0`.
   
   ### What did you see instead?
   
   In Java 23, the following error is reported:  
   `Shift operation '>>>' by overly large constant value 64`
   
   In earlier versions of Java (e.g., 1.8), there is no error, but the result 
does not match expectations. The operation `0xffffffffffffffffL >>> 64` 
essentially leaves the result unchanged, where the `long` value becomes 
populated with unrelated values, leading to unpredictable outcomes.
   
   In Dart, the same mask (`0xffffffffffffffffL >>> 64`) would result in `0` as 
expected.
   
   ### Anything Else?
   
   This issue could lead to unexpected behavior in different Java versions, and 
it may require adjustments to the code to handle `len = 0` safely across all 
environments. Please consider revising the implementation to handle the shift 
operation correctly for `len = 0`.
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to