Fix formatting of user in RestApiServlet if username is not set

The error message from RestApiServlet that is displayed if a user
doesn't have a required capability, prints the user's username. This
username may be null, as fallback now the fullname and preferred email
address of the user are printed.

Change-Id: I786be9d1772b76eb6712d49cebe867b20d32d975
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2012-06-22 19:29:34 +02:00
parent 92edc8e481
commit a25e4dd62c

View File

@@ -14,9 +14,11 @@
package com.google.gerrit.httpd;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.google.gerrit.extensions.annotations.RequiresCapability;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.CapabilityControl;
import com.google.gerrit.util.cli.CmdLineParser;
import com.google.gwtjsonrpc.common.JsonConstants;
@@ -99,7 +101,9 @@ public abstract class RestApiServlet extends HttpServlet {
if (!ctl.canPerform(rc.value()) && !ctl.canAdministrateServer()) {
String msg = String.format(
"fatal: %s does not have \"%s\" capability.",
user.getUserName(), rc.value());
Objects.firstNonNull(user.getUserName(),
((IdentifiedUser)user).getNameEmail()),
rc.value());
throw new RequireCapabilityException(msg);
}
}