From 7e2924c7cdacaaf3e72a6680bfaa085d613c2c3e Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Fri, 25 Nov 2022 06:42:11 +0100 Subject: [PATCH] Add null check for the return value of `ReferenceQueue#remove()` (#7304) --- .../cache/weaklockfree/AbstractWeakConcurrentMap.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/cache/weaklockfree/AbstractWeakConcurrentMap.java b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/cache/weaklockfree/AbstractWeakConcurrentMap.java index da8a6938aa30..30aac391bb41 100644 --- a/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/cache/weaklockfree/AbstractWeakConcurrentMap.java +++ b/instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/cache/weaklockfree/AbstractWeakConcurrentMap.java @@ -258,7 +258,9 @@ static void runCleanup() { try { while (!Thread.interrupted()) { Reference reference = REFERENCE_QUEUE.remove(); - removeWeakKey((WeakKey) reference); + if (reference != null) { + removeWeakKey((WeakKey) reference); + } } } catch (InterruptedException ignored) { // do nothing