Skip to content

Commit 1b81e8a

Browse files
committed
relaxing reReportToCollector restraint and adding unit test
1 parent 81db67d commit 1b81e8a

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

internal-api/src/main/java/datadog/trace/bootstrap/config/provider/ConfigProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ private static <T> void reportDefault(String key, T defaultValue) {
627627
}
628628

629629
/** Helper class to store resolved configuration values with their metadata */
630-
private static class ConfigValueResolver<T> {
630+
static class ConfigValueResolver<T> {
631631
final T value;
632632
final ConfigOrigin origin;
633633
final int seqId;
@@ -653,7 +653,8 @@ static <T> ConfigValueResolver<T> of(T value, ConfigOrigin origin, int seqId, St
653653

654654
/** Re-reports this resolved value to ConfigCollector with the specified seqId */
655655
void reReportToCollector(String key, int finalSeqId) {
656-
if (value != null && origin != null) {
656+
// Source and value should never be null if there is an initialized ConfigValueResolver
657+
if (origin != null) {
657658
ConfigCollector.get().put(key, value, origin, finalSeqId, configId);
658659
}
659660
}

internal-api/src/test/groovy/datadog/trace/bootstrap/config/provider/ConfigProviderTest.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,4 +475,17 @@ class ConfigProviderTest extends DDSpecification {
475475
def maxSeqId = [defaultSetting.seqId, envSetting.seqId, jvmSetting.seqId, calculatedSetting.seqId].max()
476476
calculatedSetting.seqId == maxSeqId
477477
}
478+
479+
// NOTE: This is a case that SHOULD never occur. #reReportToCollector(String, int) should only be called with valid origins
480+
def "ConfigValueResolver reReportToCollector handles null origin gracefully"() {
481+
setup:
482+
ConfigCollector.get().collect() // clear previous state
483+
ConfigProvider.ConfigValueResolver resolver = ConfigProvider.ConfigValueResolver.of("1")
484+
485+
when:
486+
resolver.reReportToCollector("test.key", 5)
487+
488+
then:
489+
0 * ConfigCollector.get().put(_, _, _, _, _)
490+
}
478491
}

0 commit comments

Comments
 (0)