s8sankalp opened a new pull request, #712:
URL: https://github.com/apache/commons-collections/pull/712

   ## Description
   
   This PR fixes **COLLECTIONS-714**, where `PatriciaTrie` cannot distinguish 
between the keys `"x"` and `"x\u0000"`.
   
   The root cause is in `StringKeyAnalyzer`. It treats the end of a string as 
`'\u0000'`, so when comparing keys of different lengths, an actual `'\u0000'` 
character becomes indistinguishable from the end of the string. As a result, 
`bitIndex()` returns `EQUAL_BIT_KEY` for keys that are not equal, causing 
`PatriciaTrie.put()` to replace an existing entry instead of inserting a new 
one.
   
   This patch changes the internal bit representation used by 
`StringKeyAnalyzer`. Each character position is represented using a presence 
bit followed by the 16 character bits. The presence bit indicates whether a 
character exists at that position, allowing the analyzer to distinguish between 
the end of a string and an actual `'\u0000'` character.
   
   With this representation:
   
   * `"x"` and `"x\u0000"` are treated as distinct keys.
   * Prefix keys branch at the presence bit of the first missing character, 
avoiding duplicate branching indices.
   * The existing ordering semantics of `PatriciaTrie` are preserved.
   
   The following regression tests were added:
   
   * `testNullTerminatedKey1`
   * `testNullTerminatedKey2`
   
   Both insertion orders are covered to verify that the keys coexist correctly 
and can be retrieved independently.
   
   The project was built successfully, and the full Maven test suite completed 
successfully with no test failures or regressions.
   


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

Reply via email to