Skip to content

Bad usage of Map in ExclusionManager can lead to undesired effects #106

Description

@ItzSomebody

The current implementation of ExclusionManager takes a Map<String, String> as a constructor as a collection of patterns.

public ExclusionManager(Map<String, String> patterns) {
this.exclusions = new HashSet<>(patterns.size());
this.cache = new HashMap<>();
patterns.forEach((k, v) -> {
var invert = false;
if (k.startsWith("!")) {
invert = true;
k = k.substring(1);
}
exclusions.add(new Exclusion(v, Exclusion.ExclusionType.forIdentifier(k), invert));
});
}

This is a flawed implementation because it allows for overwriting exclusion patterns in the map, causing them to vanish. Need to also change this line as well:

public class ExclusionsDeserializer extends JsonDeserializer<ExclusionManager> {
@Override
public ExclusionManager deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
JsonNode node = p.getCodec().readTree(p);
var map = new HashMap<String, String>();
node.fields().forEachRemaining(entry -> map.put(entry.getKey(), entry.getValue().asText()));
return new ExclusionManager(map);
}
}

Thanks to lokirus for finding the side effects of my dumb code logic errors!

Metadata

Metadata

Assignees

No one assigned

    Labels

    radon issueRadon isn't functioning within normal parameters

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions