Skip to content

Fix ReadOnlyArrayMap null value handling in containsValue #8651

Description

@NithinU2802

Describe the bug
ReadOnlyArrayMap.containsValue(Object) from line 73 does not correctly handle maps that contain null values. The implementation assumes in the way of stored values are non-null and performs the comparison using equals(), which can result in incorrect behavior or a NullPointerException when a value in the map is null.

Steps to reproduce

  1. Update ReadOnlyArrayMap.containsValue(Object) which can handle null.
  2. Add appropriate testcase in ReadOnlyArrayMapTest.

What did you expect to see?
containsValue(null) should return true when the map contains a mapping whose value is null, consistent with the Map.containsValue().

What did you see instead?
containsValue(null) does not handle null values correctly because the implementation assumes in the way of stored values are non-null. This can lead to incorrect results or a NullPointerException when a map contains a null value.

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)
Core OpenTelemetry Java API

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

  • Fix the null handling in ReadOnlyArrayMap.containsValue(null).
  • Add appropriate testcase to ReadOnlyArrayMapTest.

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