ChangeUtil: Perform some code clean ups

Remove exception declarations that aren't thrown and use utility method
to check for string emptiness.

Change-Id: Icbe4228624366b6d4d95c59d0d45f9820dd412a2
This commit is contained in:
David Ostrovsky
2014-10-24 09:00:32 +02:00
parent d3f5711aa1
commit effb2b9387
2 changed files with 7 additions and 9 deletions

View File

@@ -20,6 +20,7 @@ import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS; import static java.util.concurrent.TimeUnit.SECONDS;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import com.google.gerrit.common.TimeUtil; import com.google.gerrit.common.TimeUtil;
@@ -375,14 +376,13 @@ public class ChangeUtil {
} }
public Change.Id editCommitMessage(ChangeControl ctl, PatchSet ps, public Change.Id editCommitMessage(ChangeControl ctl, PatchSet ps,
String message, PersonIdent myIdent) String message, PersonIdent myIdent) throws NoSuchChangeException,
throws NoSuchChangeException, EmailException, OrmException, OrmException, MissingObjectException, IncorrectObjectTypeException,
MissingObjectException, IncorrectObjectTypeException, IOException, IOException, InvalidChangeOperationException {
InvalidChangeOperationException, PatchSetInfoNotAvailableException {
Change change = ctl.getChange(); Change change = ctl.getChange();
Change.Id changeId = change.getId(); Change.Id changeId = change.getId();
if (message == null || message.length() == 0) { if (Strings.isNullOrEmpty(message)) {
throw new InvalidChangeOperationException( throw new InvalidChangeOperationException(
"The commit message cannot be empty"); "The commit message cannot be empty");
} }

View File

@@ -28,7 +28,6 @@ import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.GerritPersonIdent; import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.change.ChangeJson.ChangeInfo; import com.google.gerrit.server.change.ChangeJson.ChangeInfo;
import com.google.gerrit.server.change.EditMessage.Input; import com.google.gerrit.server.change.EditMessage.Input;
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
import com.google.gerrit.server.project.InvalidChangeOperationException; import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.OrmException;
@@ -84,8 +83,7 @@ class EditMessage implements RestModifyView<RevisionResource, Input>,
throw new BadRequestException(e.getMessage()); throw new BadRequestException(e.getMessage());
} catch (NoSuchChangeException e) { } catch (NoSuchChangeException e) {
throw new ResourceNotFoundException(); throw new ResourceNotFoundException();
} catch (MissingObjectException | IncorrectObjectTypeException } catch (MissingObjectException | IncorrectObjectTypeException e) {
| PatchSetInfoNotAvailableException e) {
throw new ResourceConflictException(e.getMessage()); throw new ResourceConflictException(e.getMessage());
} }
} }