Fix reenabling of plugins

e51c428fe5 broke the unregistering of plugin
owned SSH command by passing wrong instance to the ConcurrentMap.remove()
function. Currently plugins can not be reenabled.

Change-Id: I2b2dfe6ffe89a426a03d945d9695bc35e7fe9f1a
This commit is contained in:
David Ostrovsky 2013-08-31 11:33:21 +02:00 committed by Shawn Pearce
parent 4cc99757c0
commit bae9e58ddd

View File

@ -53,13 +53,17 @@ public class DispatchCommandProvider implements Provider<DispatchCommand> {
public RegistrationHandle register(final CommandName name,
final Provider<Command> cmd) {
final ConcurrentMap<String, CommandProvider> m = getMap();
if (m.putIfAbsent(name.value(), new CommandProvider(cmd, null)) != null) {
final CommandProvider commandProvider = new CommandProvider(cmd, null);
if (m.putIfAbsent(name.value(), commandProvider) != null) {
throw new IllegalArgumentException(name.value() + " exists");
}
return new RegistrationHandle() {
@Override
public void remove() {
m.remove(name.value(), cmd);
if (!m.remove(name.value(), commandProvider)) {
throw new IllegalStateException(String.format(
"can not unregister command: %s", name.value()));
}
}
};
}