Skip to content

fix: avoid eager string alloc in setContextAttributesByIdAndBytes validation#606

Merged
jbachorik merged 1 commit into
mainfrom
jb/fix-ctx-npe-alloc
Jun 18, 2026
Merged

fix: avoid eager string alloc in setContextAttributesByIdAndBytes validation#606
jbachorik merged 1 commit into
mainfrom
jb/fix-ctx-npe-alloc

Conversation

@jbachorik

Copy link
Copy Markdown
Collaborator

What does this PR do?

Replace Objects.requireNonNull(utf8[i], "utf8[" + i + "]") with a plain null check so the string concatenation only happens when actually throwing. The original form evaluated the message argument eagerly on every loop iteration — including all non-null cases in the happy path — allocating a string per slot per call.

Motivation

setContextAttributesByIdAndBytes is a hot-path method (vthread mount/unmount reapply). Allocation in its validation loop defeats the purpose of the allocation-free API.

Test plan

  • Existing TagContextTest covers the validation path (null slot throws NPE, oversized bytes throws IAE)
  • No behaviour change: semantics are identical — NPE with the same message, same condition

@jbachorik jbachorik marked this pull request as ready for review June 18, 2026 18:59
@jbachorik jbachorik requested a review from a team as a code owner June 18, 2026 18:59
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 14 Pipeline jobs failed

DataDog/java-profiler | benchmarks-candidate-aarch64: [alloc]   View in Datadog   GitLab

DataDog/java-profiler | benchmarks-candidate-aarch64: [cpu,wall,alloc,memleak]   View in Datadog   GitLab

DataDog/java-profiler | benchmarks-candidate-aarch64: [cpu,wall]   View in Datadog   GitLab

View all 14 failed jobs.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 0b5dd82 | Docs | Datadog PR Page | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #27782406906 | Commit: e53f1ef | Duration: 19m 20s (longest job)

All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - - -
8-ibm - - -
8-j9 - -
8-librca - -
8-orcl - - -
11 - - -
11-j9 - -
11-librca - -
17 - -
17-graal - -
17-j9 - -
17-librca - -
21 - -
21-graal - -
21-librca - -
25 - -
25-graal - -
25-librca - -

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Summary: Total: 32 | Passed: 32 | Failed: 0


Updated: 2026-06-18 19:20:36 UTC

@jbachorik jbachorik merged commit 0e505e4 into main Jun 18, 2026
110 of 122 checks passed
@jbachorik jbachorik deleted the jb/fix-ctx-npe-alloc branch June 18, 2026 19:21
@github-actions github-actions Bot added this to the 1.45.0 milestone Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant