amalsaidov opened a new pull request, #674:
URL: https://github.com/apache/dubbo-spi-extensions/pull/674

   ## What this fixes
   
   `OptionUtil.prefixEndOf` builds the exclusive end key of an etcd range query 
(used for prefix watches and child lookups in the etcd3 remoting). The current 
implementation only increments the last byte:
   
   ```java
   endKey[endKey.length - 1] = (byte) (endKey[endKey.length - 1] + 1);
   ```
   
   When the last byte is `0xFF`, incrementing wraps it to `0x00`. The returned 
end key is then lexicographically smaller than the prefix itself, so the range 
`[prefix, end)` is empty and the watch/lookup silently returns nothing for keys 
that end in `0xFF`.
   
   This is the problem reported in #80. The original loop there used `endKey[i] 
< 0xff`, which is always true for a signed `byte` (max value `127` < `255`), so 
the carry was never handled.
   
   ## The fix
   
   Walk the key from the end, increment the first byte that is not `0xFF`, and 
drop the trailing `0xFF` bytes, which is the standard etcd prefix-range 
semantics (same as jetcd's own `OptionUtil`). Comparing the unsigned value 
`(endKey[i] & 0xff) < 0xff` makes the check correct. When every byte is `0xFF` 
there is no greater key, so it returns the existing `NO_PREFIX_END` marker to 
range over the rest of the keyspace. The empty-prefix guard added in #669 is 
preserved (an empty key has no non-`0xFF` byte, so it falls through to 
`NO_PREFIX_END`).
   
   ## Tested
   
   Added `OptionUtilTest` covering:
   - plain ASCII keys (`"a"` -> `"b"`, last byte of a multi-byte key)
   - a trailing `0xFF` carrying to the previous byte and being dropped
   - multiple trailing `0xFF` bytes
   - all-`0xFF` and empty prefixes returning `NO_PREFIX_END`
   - the input `ByteSequence` not being mutated
   
   `./mvnw -pl dubbo-remoting-extensions/dubbo-remoting-etcd3 -am test 
-DskipIntegrationTests=false` -> `Tests run: 7, Failures: 0, Errors: 0`. The 
three trailing-`0xFF` cases fail against the current code and pass with this 
change. The existing etcd integration tests stay `@Disabled` as before.
   
   Fixes #80
   
   ---
   This change was written with the help of Claude Code and directed, reviewed 
and tested by a human contributor.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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