LuciferYang opened a new pull request, #12476:
URL: https://github.com/apache/gravitino/pull/12476

   ### What changes are proposed in this pull request?
   
   Make `CallerContext` a truly immutable value object:
   - `withContext` now stores a defensive unmodifiable copy 
(`Collections.unmodifiableMap(new HashMap<>(context))`) instead of the caller's 
map by reference.
   - The `context` field is now `final`, assigned once via a private 
constructor; the `Builder` accumulates the map and `build()` returns a distinct 
`new CallerContext(...)`.
   
   `CallerContext` is published into a `ThreadLocal` and read across modules 
(server fileset/credential ops, event dispatcher, GVFS clients). It is forked 
from Hadoop's `CallerContext`, which is fully immutable, but the Gravitino copy 
had lost that: the map was exposed by reference and a retained `Builder` could 
mutate an already-built instance.
   
   ### Why are the changes needed?
   
   Defense-in-depth for an audit/credential context: prevent a caller's later 
map mutation or a reader's `put`/`remove` from silently corrupting the 
published context, and restore parity with the immutable Hadoop origin. No live 
bug today (all call sites pass fresh maps and only read), but a latent footgun 
on a shared, ThreadLocal-published object.
   
   Fix: #12475
   
   ### Does this PR introduce _any_ user-facing change?
   
   `context()` now returns an unmodifiable map. Within Gravitino nothing breaks 
(all readers are read-only). External GVFS/client code that mutated the 
returned map would now get `UnsupportedOperationException`.
   
   ### How was this patch tested?
   
   Extended `TestCallerContext` (1 → 7 tests): defensive copy, unmodifiability, 
null-rejection contract, empty map, builder-reuse isolation, equals/hashCode 
across a mutated source map. `./gradlew :common:test --tests 
"*.audit.TestCallerContext"` passes 7/7.
   


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