Allow user name to be cleared when unset in LDAP

If the user name is set in Gerrit, but is no longer configured
in LDAP, allow it to be cleared by passing in a null name to the
ChangeUserName action.

Change-Id: Ie52fdf5b899e61456ea268aef93795ca00eed213
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/ReleaseNotes/ReleaseNotes-2.1.2.4.txt b/ReleaseNotes/ReleaseNotes-2.1.2.4.txt
index f511c27..c651b69 100644
--- a/ReleaseNotes/ReleaseNotes-2.1.2.4.txt
+++ b/ReleaseNotes/ReleaseNotes-2.1.2.4.txt
@@ -32,6 +32,13 @@
 properly from the embedded Gerrit SSH or HTTP daemon.  Fixed upstream
 in JGit 0.7.0, but we never picked up the bug fix release.
 
+* Allow LDAP to unset the user name
++
+If the user name is configured to be set only by the LDAP directory,
+and an account has a user name, but the name is no longer present
+in the directory, Gerrit crashed during sign-in while trying to
+clear out the user name.  Fixed.
+
 Documentation Corrections
 ~~~~~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/account/ChangeUserName.java b/gerrit-server/src/main/java/com/google/gerrit/server/account/ChangeUserName.java
index d8951bf..1509299 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/account/ChangeUserName.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/account/ChangeUserName.java
@@ -36,6 +36,8 @@
 import java.util.concurrent.Callable;
 import java.util.regex.Pattern;
 
+import javax.annotation.Nullable;
+
 /** Operation to change the username of an account. */
 public class ChangeUserName implements Callable<VoidResult> {
   private static final Pattern USER_NAME_PATTERN =
@@ -77,7 +79,7 @@
       final SshKeyCache sshKeyCache,
 
       @Assisted final ReviewDb db, @Assisted final IdentifiedUser user,
-      @Assisted final String newUsername) {
+      @Nullable @Assisted final String newUsername) {
     this.accountCache = accountCache;
     this.sshKeyCache = sshKeyCache;