From 1ecc9197bea8a566bf4ec6e3afa6b70f55d593ef Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Mon, 6 Nov 2023 19:12:29 +0200 Subject: [PATCH] Add null check to StrictContextStorage (#5954) --- .../java/io/opentelemetry/context/StrictContextStorage.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/context/src/main/java/io/opentelemetry/context/StrictContextStorage.java b/context/src/main/java/io/opentelemetry/context/StrictContextStorage.java index b02d33b4aea..aeed325c364 100644 --- a/context/src/main/java/io/opentelemetry/context/StrictContextStorage.java +++ b/context/src/main/java/io/opentelemetry/context/StrictContextStorage.java @@ -23,6 +23,7 @@ import static java.lang.Thread.currentThread; import io.opentelemetry.context.internal.shaded.WeakConcurrentMap; +import java.lang.ref.Reference; import java.util.Arrays; import java.util.List; import java.util.concurrent.ConcurrentHashMap; @@ -266,7 +267,9 @@ List drainPendingCallers() { public void run() { try { while (!Thread.interrupted()) { - CallerStackTrace caller = map.remove(remove()); + Reference reference = remove(); + // on openj9 ReferenceQueue.remove can return null + CallerStackTrace caller = reference != null ? map.remove(reference) : null; if (caller != null && !caller.closed) { logger.log( Level.SEVERE, "Scope garbage collected before being closed.", callerError(caller));