Skip to content

Fix to add null handling to Baggage.fromContext() and Baggage.fromContextOrNull() #8665

Description

@NithinU2802

Describe the bug
Baggage.fromContext(Context context) and Baggage.fromContextOrNull(Context context) in Baggage currently throw NullPointerException when passed a null context because both dereference the supplied Context without a null guard.

Steps to reproduce

  1. To add check point in Baggage.fromContext(Context context) in Baggage with log returns Baggage.empty().
  2. To add check point in Baggage.fromContextOrNull(Context context) in Baggage with log returns null.
  3. Finally, add testcase fromContext_null() in BaggageContextText to validate above changes.

What did you expect to see?

  • Baggage.fromContext(Context context) should log using ApiUsageLogger and return Baggage.empty().
  • Same way for Baggage.fromContextOrNull(null) should log using ApiUsageLogger and return null.

What did you see instead?
In the current scenario Baggage.fromContext(Context context) and Baggage.fromContextOrNull(Context contextl) throw NullPointerException when passed a null context for both the methods.

What version and what artifacts are you using?
Artifacts: opentelemetry-api
Version: main
How did you reference these artifacts? (excerpt from your build.gradle, pom.xml, etc)

Environment
Compiler: Temurin JDK 25
OS: Windows 11
Runtime (if different from JDK above): JDK 25
OS (if different from OS compiled on): (e.g., "Windows Server 2019")

Additional context
I did refer fromContext(context) and fromContextOrNull(context) method of Span.java implemented accordingly.

I'm happy get assign and work on this issue.

Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions