Skip to content

Fix NullPointerException in OSGi BundleWiringHelper when bundle reference is stale - #12241

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
masterfrom
dougqh/fix-osgi-bundle-wiring-npe
Aug 21, 2026
Merged

gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
masterfrom
dougqh/fix-osgi-bundle-wiring-npe

Conversation

@dougqh

@dougqh dougqh commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Adds a null guard for origin (the Bundle) at the top of BundleWiringHelper.probeResource(), getResource(), and loadClass(), returning the same "nothing found" result each method already returns for a failed wiring lookup (SKIP_REQUEST, null, null respectively).

Motivation

BundleReference.getBundle() can return null once the underlying bundle has been uninstalled while its classloader (e.g. Felix's BundleWiringImpl$BundleClassLoader) is still reachable and gets invoked. BundleWiringHelper.probeResource/getResource/loadClass dereferenced that Bundle directly without a null check, throwing an NPE out of the widened loadClass/getResource/getResourceAsStream advice in BundleReferenceInstrumentation.

Found via Datadog Error Tracking issue c62bcc56-aab2-11f0-bae4-da7ad0900002 (4.6M+ occurrences over 90d, logged via "Failed to handle exception in instrumentation for ... BundleClassLoader").

Additional Notes

  • No existing test harness for this module (no src/test); happy to add one covering the stale-bundle-reference case if desired.

Test plan

  • ./gradlew :dd-java-agent:instrumentation:osgi-4.3:compileJava — succeeds
  • ./gradlew :dd-java-agent:instrumentation:osgi-4.3:spotlessApply — applied, diff is clean

🤖 Generated with Claude Code

…is stale

BundleReference.getBundle() can return null once the bundle has been
uninstalled while a classloader reference (e.g. Felix's
BundleWiringImpl$BundleClassLoader) still lingers. The OSGi widen
helper methods dereferenced that bundle directly, throwing an NPE out
of loadClass/getResource that surfaced as an instrumentation error.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@dougqh dougqh added inst: java Core Java language instrumentation tag: ai generated Largely based on code generated by an AI or LLM type: bug fix Bug fix labels Aug 19, 2026
@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Aug 19, 2026

Copy link
Copy Markdown

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 69.74% (+11.12%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: fe3dba3 | Docs | View more details | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 13.98 s 13.96 s [-0.5%; +0.9%] (no difference)
startup:insecure-bank:tracing:Agent 12.94 s 12.91 s [-0.4%; +0.9%] (no difference)
startup:petclinic:appsec:Agent 16.94 s 16.03 s [+1.5%; +9.9%] (significantly worse)
startup:petclinic:iast:Agent 16.86 s 16.96 s [-1.3%; +0.2%] (no difference)
startup:petclinic:profiling:Agent 16.77 s 16.66 s [-0.5%; +1.9%] (no difference)
startup:petclinic:sca:Agent 16.96 s 16.69 s [+0.6%; +2.7%] (maybe worse)
startup:petclinic:tracing:Agent 16.18 s 16.27 s [-1.5%; +0.4%] (no difference)

Commit: fe3dba3a · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@dougqh
dougqh marked this pull request as ready for review August 21, 2026 13:29
@dougqh
dougqh requested a review from a team as a code owner August 21, 2026 13:29
@dougqh
dougqh requested review from ValentinZakharov and removed request for a team August 21, 2026 13:29

@mcculls mcculls left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@dougqh
dougqh enabled auto-merge August 21, 2026 14:05

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datadog Autotest: PASS

More details

The stale-bundle guards keep each helper's existing not-found result. The direct advice callers already handle these results correctly.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Datadog Autotest · Commit ad41da1 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

@dougqh
dougqh added this pull request to the merge queue Aug 21, 2026
@dd-octo-sts

dd-octo-sts Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Aug 21, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-08-21 14:43:37 UTC ℹ️ Start processing command /merge


2026-08-21 14:43:41 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-08-21 15:39:41 UTC ℹ️ MergeQueue: This merge request was merged

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 21, 2026
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit b84471f into master Aug 21, 2026
590 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the dougqh/fix-osgi-bundle-wiring-npe branch August 21, 2026 15:39
@github-actions github-actions Bot added this to the 1.66.0 milestone Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: java Core Java language instrumentation tag: ai generated Largely based on code generated by an AI or LLM type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants