Skip to content

Fix/declarative config no exceptions#8079

Open
Bhagirath00 wants to merge 2 commits intoopen-telemetry:mainfrom
Bhagirath00:fix/declarative-config-no-exceptions
Open

Fix/declarative config no exceptions#8079
Bhagirath00 wants to merge 2 commits intoopen-telemetry:mainfrom
Bhagirath00:fix/declarative-config-no-exceptions

Conversation

@Bhagirath00
Copy link

issue: #7929

Description:

This PR updates the DeclarativeConfigProperties API to return null instead of throwing a DeclarativeConfigException when a property exists but has a different data type than requested (e.g., calling getBoolean on a String value).

Changes:

In DeclarativeConfigProperties.java (API): Updated Javadocs for all getter methods to explicitly state that they return null on type mismatch.
In YamlDeclarativeConfigPropertiesTest.java (Tests): Added comprehensive verification tests to ensure that getString, getBoolean, getInt, getStructured, and getStructuredList all return null correctly when a type mismatch occurs.

Verification Results:

All tests in the incubator module passed successfully:

Unit Tests Verification Command: ./gradlew :sdk-extensions:incubator:test ...

Parallel Configuration Cache is an incubating feature.
Reusing configuration cache.

BUILD SUCCESSFUL in 5s
109 actionable tasks: 4 executed, 105 up-to-date
Configuration cache entry reused.

Code Style Check Command: ./gradlew spotlessCheck

Parallel Configuration Cache is an incubating feature.
Calculating task graph as no cached configuration is available for tasks: spotlessCheck

BUILD SUCCESSFUL in 11s
282 actionable tasks: 282 up-to-date
Configuration cache entry stored.

@Bhagirath00 Bhagirath00 requested a review from a team as a code owner February 13, 2026 06:35
@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.20%. Comparing base (fff95e0) to head (6eed41c).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8079   +/-   ##
=========================================
  Coverage     90.20%   90.20%           
- Complexity     7592     7607   +15     
=========================================
  Files           841      843    +2     
  Lines         22911    22935   +24     
  Branches       2288     2291    +3     
=========================================
+ Hits          20666    20689   +23     
  Misses         1529     1529           
- Partials        716      717    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

return carrier.get(key.toUpperCase(Locale.ROOT));
}

@Override
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be safer in case of refactoring: return EnvironmentGetter.class.getName()

@Nullable
@Override
public String get(@Nullable Map<String, String> carrier, String key) {
if (carrier == null || key == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should key be validated against null? It is not annotated with @Nullable, as carrier is.

* TRACESTATE}, {@code BAGGAGE}). This getter translates keys to uppercase before looking them up in
* the carrier.
*/
public enum EnvironmentGetter implements TextMapGetter<Map<String, String>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this class intentionally in this PR? I don't see it is used anywhere besides the test

* TRACESTATE}, {@code BAGGAGE}). This setter translates keys to uppercase before inserting them
* into the carrier.
*/
public enum EnvironmentSetter implements TextMapSetter<Map<String, String>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I have similar comments as for EnvironmentGetter class

assertThat(otherProps.getDouble("str_key")).isNull();
assertThat(otherProps.getBoolean("str_key")).isNull();
assertThat(otherProps.getScalarList("str_key", String.class)).isNull();
assertThat(otherProps.getScalarList("str_list_key", Long.class)).isNull();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be good to add also a cases for Boolean and Double list element types?

}

@Test
void wrongType() {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about adding test cases with default returned when wrong type is requested?

@jack-berg
Copy link
Member

Verification Results:

No need to bloat the PR description with this type of data which the build checks already tell us ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants