Correct command meta alias removal behavior and add appropriate unit tests.

Apparently @hugmanrique caught the issue but suggested the wrong fix. This is the correct fix, and respects the Javadoc.
This commit is contained in:
Andrew Steinborn
2021-10-31 19:05:21 -04:00
parent 895eb1a424
commit 0b0c36dcfc
3 changed files with 62 additions and 4 deletions

View File

@@ -156,11 +156,23 @@ public class VelocityCommandManager implements CommandManager {
// The literals of secondary aliases will preserve the children of
// the removed literal in the graph.
dispatcher.getRoot().removeChildByName(alias.toLowerCase(Locale.ENGLISH));
commandMetas.remove(alias);
} finally {
lock.writeLock().unlock();
}
}
CommandMeta meta = commandMetas.get(alias);
if (meta != null) {
for (String metaAlias : meta.getAliases()) {
commandMetas.remove(metaAlias, meta);
@Override
public void unregister(CommandMeta meta) {
Preconditions.checkNotNull(meta, "meta");
lock.writeLock().lock();
try {
// The literals of secondary aliases will preserve the children of
// the removed literal in the graph.
for (String alias : meta.getAliases()) {
final String lowercased = alias.toLowerCase(Locale.ENGLISH);
if (commandMetas.remove(lowercased, meta)) {
dispatcher.getRoot().removeChildByName(lowercased);
}
}
} finally {