Skip to content

Replace IllegalArgumentException with NumberFormatException to improve error message formatting #8556

Description

@NithinU2802

Describe the bug
The digit16 method in file throws a generic IllegalArgumentException when encountering an invalid hexadecimal digit during baggage header decoding. This should be replaced with NumberFormatException, which is more semantically correct for parsing failures.

Steps to reproduce
Replacing the IllegalArgumentException to NumberFormatException.

What did you expect to see?
• Exception type: NumberFormatException
• Error message: Clear indication of the invalid character with byte representation
• JavaDoc: @throws clause documenting the exception

What did you see instead?
Exception type: IllegalArgumentException (generic, not semantically correct for parsing)
JavaDoc: also add @throws documentation

What version and what artifacts are you using?
Artifacts: opentelemetry-api
Version: Latest main branch
How did you reference these artifacts? (excerpt from your build.gradle, pom.xml, etc)
This is part of the core OpenTelemetry Java API for W3C Baggage propagation

Environment
Compiler: Oracle JDK 25.0.1 LTS (64-bit)
OS: Windows 11
Runtime (if different from JDK above): Oracle Java SE Runtime Environment (build 25.0.1+8-LTS-27)
OS (if different from OS compiled on): NA

Additional context
• This addresses a FIXME comment in the original code
• All existing tests pass with this change
• No behavioral changes, only exception type refinement
• Improves code quality

I'm happy to be assigned this issue and work on fixing it!

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

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions