Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ItzSomebody opened this issue Sep 24, 2023 · 0 comments
Open
Labels
radon issue Radon isn't functioning within normal parameters

Comments

@ItzSomebody
Copy link
Owner

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!

@ItzSomebody ItzSomebody added the radon issue Radon isn't functioning within normal parameters label Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
radon issue Radon isn't functioning within normal parameters
Projects
None yet
Development

No branches or pull requests

1 participant