Fix non-unique module handler identifiers (#3592)

Signed-off-by: Jan N. Klug <github@klug.nrw>
pull/3595/head
J-N-K 2023-05-05 20:25:33 +02:00 committed by GitHub
parent d7ba8ad636
commit 28ec419afd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -60,7 +60,7 @@ public abstract class BaseModuleHandlerFactory implements ModuleHandlerFactory {
@Override
@SuppressWarnings("null")
public @Nullable ModuleHandler getHandler(Module module, String ruleUID) {
String id = ruleUID + module.getId();
String id = getModuleIdentifier(ruleUID, module.getId());
ModuleHandler handler = handlers.get(id);
handler = handler == null ? internalCreate(module, ruleUID) : handler;
if (handler != null) {
@ -80,8 +80,12 @@ public abstract class BaseModuleHandlerFactory implements ModuleHandlerFactory {
@Override
public void ungetHandler(Module module, String ruleUID, ModuleHandler handler) {
if (handlers.remove(ruleUID + module.getId(), handler)) {
if (handlers.remove(getModuleIdentifier(ruleUID, module.getId()), handler)) {
handler.dispose();
}
}
protected String getModuleIdentifier(String ruleUid, String moduleId) {
return ruleUid + "$" + moduleId;
}
}

View File

@ -92,7 +92,7 @@ public class CompositeModuleHandlerFactory extends BaseModuleHandlerFactory impl
@SuppressWarnings({ "unchecked" })
@Override
public void ungetHandler(Module module, String childModulePrefix, ModuleHandler handler) {
ModuleHandler handlerOfModule = getHandlers().get(childModulePrefix + module.getId());
ModuleHandler handlerOfModule = getHandlers().get(getModuleIdentifier(childModulePrefix, module.getId()));
if (handlerOfModule instanceof AbstractCompositeModuleHandler) {
AbstractCompositeModuleHandler<ModuleImpl, ?, ?> h = (AbstractCompositeModuleHandler<ModuleImpl, ?, ?>) handlerOfModule;
Set<ModuleImpl> modules = h.moduleHandlerMap.keySet();