Fix NullPointerException in OSGi BundleWiringHelper when bundle reference is stale - #12241
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
Conversation
…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]>
|
🎯 Code Coverage (details) 🔗 Commit SHA: fe3dba3 | Docs | View more details | Give us feedback! |
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
There was a problem hiding this comment.
More details
The stale-bundle guards keep each helper's existing not-found result. The direct advice callers already handle these results correctly.
🤖 Datadog Autotest · Commit ad41da1 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
What Does This Do
Adds a null guard for
origin(theBundle) at the top ofBundleWiringHelper.probeResource(),getResource(), andloadClass(), returning the same "nothing found" result each method already returns for a failed wiring lookup (SKIP_REQUEST,null,nullrespectively).Motivation
BundleReference.getBundle()can returnnullonce the underlying bundle has been uninstalled while its classloader (e.g. Felix'sBundleWiringImpl$BundleClassLoader) is still reachable and gets invoked.BundleWiringHelper.probeResource/getResource/loadClassdereferenced thatBundledirectly without a null check, throwing an NPE out of the widenedloadClass/getResource/getResourceAsStreamadvice inBundleReferenceInstrumentation.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
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