From 0b5dd82cf5ffa8fdd99659d63460600ea93fd0db Mon Sep 17 00:00:00 2001 From: Jaroslav Bachorik Date: Thu, 18 Jun 2026 20:56:38 +0200 Subject: [PATCH] fix: avoid eager string alloc in setContextAttributesByIdAndBytes validation --- .../src/main/java/com/datadoghq/profiler/ThreadContext.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ddprof-lib/src/main/java/com/datadoghq/profiler/ThreadContext.java b/ddprof-lib/src/main/java/com/datadoghq/profiler/ThreadContext.java index 1faffb69a..d5f9c0e2a 100644 --- a/ddprof-lib/src/main/java/com/datadoghq/profiler/ThreadContext.java +++ b/ddprof-lib/src/main/java/com/datadoghq/profiler/ThreadContext.java @@ -385,8 +385,10 @@ public boolean setContextAttributesByIdAndBytes(int[] constantIds, byte[][] utf8 // the record detached (valid=0) after an exception unwinds past attach(). for (int i = 0; i < len; i++) { if (constantIds[i] > 0) { - byte[] bytes = Objects.requireNonNull(utf8[i], "utf8[" + i + "]"); - if (bytes.length > MAX_VALUE_BYTES) { + if (utf8[i] == null) { + throw new NullPointerException("utf8[" + i + "]"); + } + if (utf8[i].length > MAX_VALUE_BYTES) { throw new IllegalArgumentException("utf8[" + i + "].length exceeds MAX_VALUE_BYTES"); } }