balodesecurity opened a new pull request, #8313: URL: https://github.com/apache/hadoop/pull/8313
## Problem In `NameCache.put()`, when a name's use count crosses the promotion threshold, the cache was populated with the caller's `name` argument rather than the original `useCount.value` that was stored in the transient map: ```java // Before (buggy) cache.put(name, name); ``` This means after promotion the cache holds a different object reference than what was stored before promotion. Any caller that held a reference to the pre-promotion value now has a stale reference, and two distinct `String` objects exist for what should be a single cached identity — wasting memory and breaking reference equality. ## Fix Pass `useCount` into the `promote()` helper and store `useCount.value` instead: ```java // After cache.put(name, useCount.value); ``` This preserves the original object reference across the promotion boundary. ## Testing - Added `TestNameCache#testPromotionPreservesObjectIdentity`: creates a `NameCache` with threshold 2, inserts a non-interned `String`, triggers promotion, and uses `assertSame` to verify the returned reference is identical before and after promotion. - Test passes locally. -- 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]
