Skip to content

Commit 52ea54c

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

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,14 @@ 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
*/
154+
@Deprecated(since = "1.1", forRemoval = true)
153155
public boolean removeThreadLocalAccessor(String key) {
156+
return removeThreadLocalAccessorForKey(key);
157+
}
158+
159+
public boolean removeThreadLocalAccessorForKey(Object key) {
154160
for (ThreadLocalAccessor<?> existing : this.threadLocalAccessors) {
155161
if (existing.key().equals(key)) {
156162
return this.threadLocalAccessors.remove(existing);

0 commit comments

Comments
 (0)