teragrep / cfe_31

0 stars 0 forks source link

Fix bad looping key-value lookups #52

Open MoonBow-1 opened 2 months ago

MoonBow-1 commented 2 months ago

Description

This issue was raised in the review for #49:

Bad version:

for (Entry<String, JsonValue> entry : this.jsonEntry.getJsonObject("something").entrySet()) {
    String key = entry.getKey();
    JsonValue value = entry.getValue();
    map.putIfAbsent(
        key,
        ((JsonString) value).getString()
    );
}

Good version:

JsonObject jsonObject = this.jsonEntry.getJsonObject("something");
for (String key : jsonObject.keySet()) {
    map.putIfAbsent(
        key,
        jsonObject.getString(key)
    );
}

This removes the need for some bad casting required to get the string

MoonBow-1 commented 1 week ago

Reviewed internally by @51-code We're discussing some points regarding the Exceptions thrown in the tests