Fix installation of plugins

e51c428fe5ef3960f4990e1c0471d067783d4718 broke the unregistering of plugin
owned SSH command by passing wrong instance to the ConcurrentMap.remove()
function.

bae9e58ddd68992473307787fb01e022f5969fee was trying to fix it, but broke it
for the installation of plugins by throwing the `IllegalStateException` in case
the old registration handle wasn't found. But it's perfectly possible and even
wanted during plugin reloading: registration handle is replaced and the old one
cannot be found.

Moreover, bae9e58ddd68992473307787fb01e022f5969fee didn't fix all places:
the same bug in unregistering of SSH commands in
DispatchCommandProvider.replace() method wasn't fixed.

Change-Id: I21132d4f7aec58347acbf50d75a962cb8251201f
diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/DispatchCommandProvider.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/DispatchCommandProvider.java
index c7594bc..ce1da95 100644
--- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/DispatchCommandProvider.java
+++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/DispatchCommandProvider.java
@@ -60,10 +60,7 @@
     return new RegistrationHandle() {
       @Override
       public void remove() {
-        if (!m.remove(name.value(), commandProvider)) {
-          throw new IllegalStateException(String.format(
-              "can not unregister command: %s", name.value()));
-        }
+        m.remove(name.value(), commandProvider);
       }
     };
   }
@@ -71,11 +68,12 @@
   public RegistrationHandle replace(final CommandName name,
       final Provider<Command> cmd) {
     final ConcurrentMap<String, CommandProvider> m = getMap();
-    m.put(name.value(), new CommandProvider(cmd, null));
+    final CommandProvider commandProvider = new CommandProvider(cmd, null);
+    m.put(name.value(), commandProvider);
     return new RegistrationHandle() {
       @Override
       public void remove() {
-        m.remove(name.value(), cmd);
+        m.remove(name.value(), commandProvider);
       }
     };
   }