Repository navigation
Conversation
Uses the is<Type> predicates added in opentelemetry-java#8883 to check what YamlDeclarativeConfigProperties holds before reading it, so the delegate does not log type mismatches for values this class converts. Scalar list elements are stored as Strings on creation, since list elements have no such predicate.
2994cc3 to
d685d3b
Compare
Pull request dashboard statusMerged · refreshed 2026-10-15 17:24 UTC Status above doesn't look right?
|
There was a problem hiding this comment.
🟡 Changes recommended
The decorator exposes a mutable structured-list result where the previous implementation returned an unmodifiable collection.
1 open finding
What changed in this PR
Replaces the copied YAML configuration implementation with a coercing decorator backed by the SDK implementation.
Changes:
- Delegates storage and structure handling to
YamlDeclarativeConfigProperties. - Preserves scalar coercion and adds nested/list coverage.
- Verifies coercion does not emit type-mismatch warnings.
| File | Description |
|---|---|
SpringDeclarativeConfigProperties.java |
Implements the coercing decorator. |
SpringDeclarativeConfigPropertiesTest.java |
Expands coercion and warning tests. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| private static Double doubleOrNull(@Nullable Object value) { | ||
| if (value instanceof Double) { | ||
| return (Double) value; | ||
| private static Boolean parseBoolean(@Nullable String value) { |
There was a problem hiding this comment.
javadoc of getBoolean says that
Implementations should use the same rules as {@link Boolean#parseBoolean(String)} for handling the values.
Boolean#parseBoolean is implemented as return "true".equalsIgnoreCase(s);
There was a problem hiding this comment.
Thanks — switched to Boolean.parseBoolean in f0261a6, for lists too. That makes any non-"true" string a valid false, so I also flipped the isBoolean("string_key_with_env_quoted") assertion in DeclarativeConfigTest (added with the 1.67 bump) to match the contract.
| return (int) longValue; | ||
| } | ||
| Long value = getLong(name); | ||
| if (value == null || value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { |
There was a problem hiding this comment.
Agreed — removed the range check in f0261a6; a Long is now narrowed with Long.intValue() as documented.
getBoolean uses Boolean.parseBoolean rules and getInt narrows a Long with Long.intValue(), as the interface documents.
| } | ||
| return null; | ||
| Long value = getLong(name); | ||
| return value == null ? null : value.intValue(); |
There was a problem hiding this comment.
[P2] [Config] String-to-int conversion now silently wraps out-of-range values.
Routing every value through getLong() before narrowing means a Spring-resolved String "4294967296" now produces getInt() == 0 and isInt() == true. Previously, Integer.parseInt() rejected it, allowing the configured default to apply. The SDK Javadoc permits narrowing an underlying Long, but this also narrows Strings that are not valid integers.
Please delegate native integer/Long reads to delegate.getInt() and retain Integer.parseInt() for Strings. Add positive and negative String-overflow cases alongside the existing native-Long test.
There was a problem hiding this comment.
Right — I applied the Long narrowing too broadly. Fixed in 5f1f90f: native Integer/Long go through delegate.getInt(), Strings still use Integer.parseInt(). Added "2147483648" / "-2147483649" (null, isInt false) plus the MAX_VALUE / MIN_VALUE boundaries next to the native-Long case.
| } | ||
| List<?> list = (List<?>) value; | ||
| if (list.stream().allMatch(SpringDeclarativeConfigProperties::isScalar)) { | ||
| return list.stream().map(String::valueOf).collect(toList()); |
There was a problem hiding this comment.
[P2] [Config] Stringifying list elements turns native numbers into booleans.
This discards every scalar list element's original type. Reading [true, 42, false] as a Boolean list now returns [true, false, false]; previously, the numeric element was dropped. A numeric-only list now returns false entries instead of null, preventing default-list fallback. This affects typed values supplied by declarative model customizers and disagrees with the scalar getter, which still rejects numeric-to-Boolean conversion.
Please preserve original element types for typed-list conversion and apply Boolean.parseBoolean() only to originally String-valued elements. Add coverage for mixed Boolean/numeric lists and numeric-only lists.
There was a problem hiding this comment.
Agreed, stringifying lost the element types. Fixed in 5f1f90f: the decorator keeps the values it was created from and getScalarList converts each element with the same rules as the scalar getters, so Boolean.parseBoolean applies only to String elements. Added [true, 42, false] → [true, false] and [1, 2] → null.
getInt narrows only a native Long and still parses Strings with Integer.parseInt, so an out-of-range String falls back to the default. Scalar lists convert from the original values rather than stringified copies, so Boolean.parseBoolean applies only to String elements.
| if (element instanceof Number) { | ||
| return ((Number) element).doubleValue(); | ||
| } | ||
| return element instanceof String ? parseDouble((String) element) : null; |
There was a problem hiding this comment.
maybe it would be clearer if this was surrounded with if (scalarType == Double.class) {
There was a problem hiding this comment.
Agreed — done in 8aac25a; the fall-through now returns null, which getScalarList never reaches since it checks the supported types first.

Resolves #20433.
SpringDeclarativeConfigPropertieswas a full copy ofYamlDeclarativeConfigPropertieswith coercing getters, kept because wrapping the real one logged a type-mismatch warning whenever a getter guessed the wrong type (TODO: Revisit after open-telemetry/opentelemetry-java#8101). SDK 1.67 addsis<Type>predicates (open-telemetry/opentelemetry-java#8883), so this replaces the copy with a decorator.How it works
getPropertyKeysandgetComponentLoadercome fromYamlDeclarativeConfigProperties.is<Type>and read only that, then convert, so the delegate never logs a mismatch.getScalarListconverts each element from its original type with the same rules as the scalar getters.getStructured/getStructuredListwrap children, so nested config converts too.DeclarativeConfigPropertiesjavadoc:Boolean.parseBooleanrules for booleans, a nativeLongnarrowed withLong.intValue()forgetInt(Strings still parsed withInteger.parseInt), numeric strings parsed, any scalar toString,Longwidened toDouble, and unconvertible list elements dropped. The old copy differed on the first two (it returnednullfor non-true/falsestrings and for out-of-int-range nativeLongvalues); that is aligned here per review.Testing
The first commit extends
SpringDeclarativeConfigPropertiesTestand passes against the old copy; later commits change behavior only where review aligned it with the javadoc, as listed above. I also ran a throwaway differential check of the old copy against the decorator over 534 getter/input combinations: every difference is one of those javadoc alignments, andYamlDeclarativeConfigPropertieslogged nothing. Coverage:@AfterEachcheck thatYamlDeclarativeConfigPropertieslogs no warning in any test:instrumentation:spring:spring-boot-autoconfigure:checkpasses.