Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ public final class StableConfig {
public StableConfig(Object yaml) {
Map<Object, Object> map = (Map<Object, Object>) yaml;
this.configId = map.get("config_id") == null ? null : String.valueOf(map.get("config_id"));

// getOrDefault returns null if key exists with null value, so we need explicit null check
Map<String, Object> apmConfigDefault =
(Map<String, Object>) map.get("apm_configuration_default");
this.apmConfigurationDefault =
unmodifiableMap(
(Map<String, Object>) map.getOrDefault("apm_configuration_default", emptyMap()));
unmodifiableMap(apmConfigDefault != null ? apmConfigDefault : emptyMap());

this.apmConfigurationRules = parseRules(map);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,46 @@ apm_configuration_rules:
"{{environment_variables['']}}" | "Empty environment variable name in template"
"{{environment_variables['DD_KEY']}" | "Unterminated template in config"
}

def "test null and empty values in YAML"() {
given:
Path filePath = Files.createTempFile("testFile_", ".yaml")

when:
String yaml = """
config_id: "12345"
apm_configuration_default:
apm_configuration_rules:
"""
Files.write(filePath, yaml.getBytes())
StableConfigSource.StableConfig cfg = StableConfigParser.parse(filePath.toString())

then:
cfg.getConfigId() == "12345"
cfg.getKeys().isEmpty()

cleanup:
Files.delete(filePath)
}

def "test completely empty values in YAML"() {
given:
Path filePath = Files.createTempFile("testFile_", ".yaml")

when:
String yaml = """
config_id: "12345"
apm_configuration_default:
apm_configuration_rules:
"""
Files.write(filePath, yaml.getBytes())
StableConfigSource.StableConfig cfg = StableConfigParser.parse(filePath.toString())

then:
cfg.getConfigId() == "12345"
cfg.getKeys().isEmpty()

cleanup:
Files.delete(filePath)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,31 @@ class StableConfigSourceTest extends DDSpecification {
"12345" | "this is not yaml format!"
}

def "test null values in YAML"() {
when:
Path filePath = Files.createTempFile("testFile_", ".yaml")
then:
if (filePath == null) {
throw new AssertionError("Failed to create: " + filePath)
}

when:
// Test the scenario where YAML contains null values for apm_configuration_default and apm_configuration_rules
String yaml = """
config_id: "12345"
apm_configuration_default:
apm_configuration_rules:
"""
Files.write(filePath, yaml.getBytes())
StableConfigSource stableCfg = new StableConfigSource(filePath.toString(), ConfigOrigin.LOCAL_STABLE_CONFIG)

then:
// Should not throw NullPointerException and should handle null values gracefully
stableCfg.getConfigId() == "12345"
stableCfg.getKeys().size() == 0
Files.delete(filePath)
}

def "test file valid format"() {
given:
Path filePath = Files.createTempFile("testFile_", ".yaml")
Expand Down