Skip to content

Commit 5879ea4

Browse files
committed
fix: Allow to remove a ThreadLocalAccessor by Key of Type Object
The `ThreadLocalAccessor.key()` is of Type Object. Thus, when it comes to delete a predefined `ThreadLocalAccessor` which have a non-String key, it's becomes impossible to delete. This behavior was observed while attempting to remove `org.springframework.security.core.context.ReactiveSecurityContextHolderThreadLocalAccessor` from the `ContextRegistry`, which have a key of type `java.lang.Class`. This change will add a dedicated method to allow deleting a `ThreadLocalAccessor` identified by its key of type `java.lang.Object`. Signed-off-by: Boubaker Khanfir <[email protected]>
1 parent ad193c8 commit 5879ea4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

context-propagation/src/main/java/io/micrometer/context/ContextRegistry.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,18 @@ public ContextRegistry registerThreadLocalAccessor(ThreadLocalAccessor<?> access
149149
* Removes a {@link ThreadLocalAccessor}.
150150
* @param key under which the accessor got registered
151151
* @return {@code true} when accessor got successfully removed
152+
* @deprecated use {@link ContextRegistry#removeThreadLocalAccessorForKey(Object)} instead
152153
*/
153154
public boolean removeThreadLocalAccessor(String key) {
155+
return removeThreadLocalAccessorForKey(key);
156+
}
157+
158+
/**
159+
* Removes a {@link ThreadLocalAccessor}.
160+
* @param key under which the accessor got registered
161+
* @return {@code true} when accessor got successfully removed
162+
*/
163+
public boolean removeThreadLocalAccessorForKey(Object key) {
154164
for (ThreadLocalAccessor<?> existing : this.threadLocalAccessors) {
155165
if (existing.key().equals(key)) {
156166
return this.threadLocalAccessors.remove(existing);

0 commit comments

Comments
 (0)