From fb1ede53059343e6d23c6d23ae4a42b8dbe34313 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Sat, 10 Oct 2015 10:10:23 +0200 Subject: [PATCH] Remove unneeded exception declarations from REST handlers Change-Id: I75a166d332aa153843fa363f9f54002e15f448bb --- .../httpd/rpc/project/ReviewProjectAccess.java | 5 ++--- .../gerrit/server/api/changes/ChangeApiImpl.java | 12 +++++------- .../gerrit/server/api/changes/RevisionApiImpl.java | 2 +- .../com/google/gerrit/server/change/ChangeEdits.java | 7 +++---- .../com/google/gerrit/server/change/CherryPick.java | 4 +--- .../google/gerrit/server/change/CreateChange.java | 7 +++---- .../gerrit/server/change/DeleteChangeEdit.java | 4 +--- .../google/gerrit/server/change/PostReviewers.java | 3 +-- .../gerrit/server/change/PublishChangeEdit.java | 4 +--- .../com/google/gerrit/server/change/PutTopic.java | 4 +--- .../com/google/gerrit/server/change/Restore.java | 6 ++---- .../java/com/google/gerrit/server/change/Revert.java | 3 +-- .../google/gerrit/server/change/TestSubmitRule.java | 3 +-- .../com/google/gerrit/server/config/PostCaches.java | 6 ++---- .../com/google/gerrit/server/group/CreateGroup.java | 3 +-- .../java/com/google/gerrit/server/group/PutName.java | 4 +--- .../com/google/gerrit/server/project/BanCommit.java | 2 +- .../gerrit/sshd/commands/BanCommitCommand.java | 2 +- 18 files changed, 29 insertions(+), 52 deletions(-) diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/project/ReviewProjectAccess.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/project/ReviewProjectAccess.java index 8b26e71e2c..5b3b064ad8 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/project/ReviewProjectAccess.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/project/ReviewProjectAccess.java @@ -20,7 +20,6 @@ import com.google.gerrit.common.TimeUtil; import com.google.gerrit.common.data.AccessSection; import com.google.gerrit.common.data.GlobalCapability; import com.google.gerrit.common.data.PermissionRule; -import com.google.gerrit.common.errors.EmailException; import com.google.gerrit.extensions.api.changes.AddReviewerInput; import com.google.gerrit.extensions.restapi.ResourceNotFoundException; import com.google.gerrit.extensions.restapi.RestApiException; @@ -172,7 +171,7 @@ public class ReviewProjectAccess extends ProjectAccessHandler { AddReviewerInput input = new AddReviewerInput(); input.reviewer = projectOwners; reviewersProvider.get().apply(rsrc, input); - } catch (IOException | OrmException | RestApiException | EmailException e) { + } catch (IOException | OrmException | RestApiException e) { // one of the owner groups is not visible to the user and this it why it // can't be added as reviewer } @@ -188,7 +187,7 @@ public class ReviewProjectAccess extends ProjectAccessHandler { AddReviewerInput input = new AddReviewerInput(); input.reviewer = r.getGroup().getUUID().get(); reviewersProvider.get().apply(rsrc, input); - } catch (IOException | OrmException | RestApiException | EmailException e) { + } catch (IOException | OrmException | RestApiException e) { // ignore } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/ChangeApiImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/ChangeApiImpl.java index 605e0e7ade..b55642cccc 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/ChangeApiImpl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/ChangeApiImpl.java @@ -14,7 +14,6 @@ package com.google.gerrit.server.api.changes; -import com.google.gerrit.common.errors.EmailException; import com.google.gerrit.extensions.api.changes.AbandonInput; import com.google.gerrit.extensions.api.changes.AddReviewerInput; import com.google.gerrit.extensions.api.changes.ChangeApi; @@ -51,7 +50,6 @@ import com.google.gerrit.server.change.Revisions; import com.google.gerrit.server.change.SubmittedTogether; import com.google.gerrit.server.change.SuggestReviewers; import com.google.gerrit.server.git.UpdateException; -import com.google.gerrit.server.project.InvalidChangeOperationException; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Provider; @@ -180,7 +178,7 @@ class ChangeApiImpl implements ChangeApi { public void restore(RestoreInput in) throws RestApiException { try { restore.apply(change, in); - } catch (OrmException | IOException | UpdateException e) { + } catch (OrmException | UpdateException e) { throw new RestApiException("Cannot restore change", e); } } @@ -194,7 +192,7 @@ class ChangeApiImpl implements ChangeApi { public ChangeApi revert(RevertInput in) throws RestApiException { try { return changeApi.id(revert.apply(change, in)._number); - } catch (OrmException | EmailException | IOException | UpdateException e) { + } catch (OrmException | IOException | UpdateException e) { throw new RestApiException("Cannot revert change", e); } } @@ -219,7 +217,7 @@ class ChangeApiImpl implements ChangeApi { in.topic = topic; try { putTopic.apply(change, in); - } catch (OrmException | IOException | UpdateException e) { + } catch (UpdateException e) { throw new RestApiException("Cannot set topic", e); } } @@ -235,7 +233,7 @@ class ChangeApiImpl implements ChangeApi { public void addReviewer(AddReviewerInput in) throws RestApiException { try { postReviewers.apply(change, in); - } catch (OrmException | EmailException | IOException e) { + } catch (OrmException | IOException e) { throw new RestApiException("Cannot add change reviewer", e); } } @@ -292,7 +290,7 @@ class ChangeApiImpl implements ChangeApi { try { Response edit = editDetail.apply(change); return edit.isNone() ? null : edit.value(); - } catch (IOException | OrmException | InvalidChangeOperationException e) { + } catch (IOException | OrmException e) { throw new RestApiException("Cannot retrieve change edit", e); } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/RevisionApiImpl.java b/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/RevisionApiImpl.java index 29794c00d6..0926142ae2 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/RevisionApiImpl.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/api/changes/RevisionApiImpl.java @@ -212,7 +212,7 @@ class RevisionApiImpl implements RevisionApi { public ChangeApi cherryPick(CherryPickInput in) throws RestApiException { try { return changes.id(cherryPick.apply(revision, in)._number); - } catch (OrmException | EmailException | IOException | UpdateException e) { + } catch (OrmException | IOException | UpdateException e) { throw new RestApiException("Cannot cherry pick", e); } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeEdits.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeEdits.java index 73f9cabeae..cb3729b9b6 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeEdits.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeEdits.java @@ -272,8 +272,7 @@ public class ChangeEdits implements @Override public Response apply(ChangeResource rsrc) throws AuthException, - IOException, InvalidChangeOperationException, - ResourceNotFoundException, OrmException { + IOException, ResourceNotFoundException, OrmException { Optional edit = editUtil.byChange(rsrc.getChange()); if (!edit.isPresent()) { return Response.none(); @@ -382,7 +381,7 @@ public class ChangeEdits implements @Override public Response apply(ChangeEditResource rsrc, Input input) - throws AuthException, ResourceConflictException, IOException { + throws AuthException, ResourceConflictException { String path = rsrc.getPath(); if (Strings.isNullOrEmpty(path) || path.charAt(0) == '/') { throw new ResourceConflictException("Invalid path: " + path); @@ -442,7 +441,7 @@ public class ChangeEdits implements @Override public Response apply(ChangeEditResource rsrc) - throws ResourceNotFoundException, IOException { + throws IOException { try { return Response.ok(fileContentUtil.getContent( rsrc.getControl().getProjectControl().getProjectState(), diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/CherryPick.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/CherryPick.java index 56fb0fa3da..b0f14af905 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/CherryPick.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/CherryPick.java @@ -14,7 +14,6 @@ package com.google.gerrit.server.change; -import com.google.gerrit.common.errors.EmailException; import com.google.gerrit.extensions.api.changes.CherryPickInput; import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.extensions.restapi.AuthException; @@ -57,8 +56,7 @@ public class CherryPick implements RestModifyView apply(TopLevelResource parent, - ChangeInfo input) - throws AuthException, OrmException, IOException, - InvalidChangeOperationException, RestApiException, UpdateException { + public Response apply(TopLevelResource parent, ChangeInfo input) + throws OrmException, IOException, InvalidChangeOperationException, + RestApiException, UpdateException { if (Strings.isNullOrEmpty(input.project)) { throw new BadRequestException("project must be non-empty"); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/DeleteChangeEdit.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/DeleteChangeEdit.java index 9bb1f02d91..495e6954e0 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/DeleteChangeEdit.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/DeleteChangeEdit.java @@ -22,7 +22,6 @@ import com.google.gerrit.extensions.restapi.RestModifyView; import com.google.gerrit.server.change.DeleteChangeEdit.Input; import com.google.gerrit.server.edit.ChangeEdit; import com.google.gerrit.server.edit.ChangeEditUtil; -import com.google.gerrit.server.project.InvalidChangeOperationException; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -42,8 +41,7 @@ public class DeleteChangeEdit implements RestModifyView { @Override public Response apply(ChangeResource rsrc, Input input) - throws AuthException, ResourceNotFoundException, IOException, - InvalidChangeOperationException { + throws AuthException, ResourceNotFoundException, IOException { Optional edit = editUtil.byChange(rsrc.getChange()); if (edit.isPresent()) { editUtil.delete(edit.get()); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReviewers.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReviewers.java index 4b541b067a..3ab84ab3e7 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReviewers.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReviewers.java @@ -21,7 +21,6 @@ import com.google.common.collect.Maps; import com.google.common.util.concurrent.CheckedFuture; import com.google.gerrit.common.ChangeHooks; import com.google.gerrit.common.data.GroupDescription; -import com.google.gerrit.common.errors.EmailException; import com.google.gerrit.common.errors.NoSuchGroupException; import com.google.gerrit.extensions.api.changes.AddReviewerInput; import com.google.gerrit.extensions.restapi.AuthException; @@ -129,7 +128,7 @@ public class PostReviewers implements RestModifyView apply(ChangeResource rsrc, Publish.Input in) - throws NoSuchProjectException, - IOException, InvalidChangeOperationException, OrmException, + throws NoSuchProjectException, IOException, OrmException, RestApiException, UpdateException { Capable r = rsrc.getControl().getProjectControl().canPushToAtLeastOneRef(); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/PutTopic.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/PutTopic.java index 6366e7b478..1061d4b268 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/PutTopic.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/PutTopic.java @@ -40,7 +40,6 @@ import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; -import java.io.IOException; import java.util.Collections; @Singleton @@ -69,8 +68,7 @@ public class PutTopic implements RestModifyView, @Override public Response apply(ChangeResource req, Input input) - throws AuthException, UpdateException, RestApiException, OrmException, - IOException { + throws UpdateException, RestApiException { ChangeControl ctl = req.getControl(); if (!ctl.canEditTopicName()) { throw new AuthException("changing topic not permitted"); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/Restore.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/Restore.java index 8b3a110040..5b0eb6deaf 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/Restore.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/Restore.java @@ -47,7 +47,6 @@ import com.google.inject.Singleton; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; import java.util.Collections; @Singleton @@ -78,9 +77,8 @@ public class Restore implements RestModifyView, } @Override - public ChangeInfo apply(ChangeResource req, final RestoreInput input) - throws AuthException, RestApiException, UpdateException, OrmException, - IOException { + public ChangeInfo apply(ChangeResource req, RestoreInput input) + throws RestApiException, UpdateException, OrmException { ChangeControl ctl = req.getControl(); if (!ctl.canRestore()) { throw new AuthException("restore not permitted"); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/Revert.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/Revert.java index ef0231ea42..dc2ed5dffb 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/Revert.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/Revert.java @@ -16,7 +16,6 @@ package com.google.gerrit.server.change; import com.google.common.base.Strings; import com.google.gerrit.common.TimeUtil; -import com.google.gerrit.common.errors.EmailException; import com.google.gerrit.extensions.api.changes.RevertInput; import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.extensions.restapi.AuthException; @@ -58,7 +57,7 @@ public class Revert implements RestModifyView, @Override public ChangeInfo apply(ChangeResource req, RevertInput input) - throws IOException, OrmException, EmailException, RestApiException, + throws IOException, OrmException, RestApiException, UpdateException { ChangeControl control = req.getControl(); Change change = req.getChange(); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/TestSubmitRule.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/TestSubmitRule.java index 31e34cfb17..95a701e52e 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/TestSubmitRule.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/TestSubmitRule.java @@ -20,7 +20,6 @@ import com.google.common.collect.Maps; import com.google.gerrit.common.data.SubmitRecord; import com.google.gerrit.extensions.common.AccountInfo; import com.google.gerrit.extensions.restapi.AuthException; -import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.DefaultInput; import com.google.gerrit.extensions.restapi.RestModifyView; import com.google.gerrit.reviewdb.server.ReviewDb; @@ -70,7 +69,7 @@ public class TestSubmitRule implements RestModifyView { @Override public List apply(RevisionResource rsrc, Input input) - throws AuthException, BadRequestException, OrmException { + throws AuthException, OrmException { if (input == null) { input = new Input(); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/PostCaches.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/PostCaches.java index 44a70d4f47..5178210099 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/config/PostCaches.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/PostCaches.java @@ -22,7 +22,6 @@ import com.google.gerrit.extensions.annotations.RequiresAnyCapability; import com.google.gerrit.extensions.registration.DynamicMap; import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.BadRequestException; -import com.google.gerrit.extensions.restapi.ResourceNotFoundException; import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.RestModifyView; import com.google.gerrit.extensions.restapi.UnprocessableEntityException; @@ -68,9 +67,8 @@ public class PostCaches implements RestModifyView { } @Override - public Object apply(ConfigResource rsrc, Input input) throws AuthException, - ResourceNotFoundException, BadRequestException, - UnprocessableEntityException { + public Object apply(ConfigResource rsrc, Input input) + throws AuthException, BadRequestException, UnprocessableEntityException { if (input == null || input.operation == null) { throw new BadRequestException("operation must be specified"); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/group/CreateGroup.java b/gerrit-server/src/main/java/com/google/gerrit/server/group/CreateGroup.java index 09865849e7..4e67c02242 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/group/CreateGroup.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/group/CreateGroup.java @@ -23,7 +23,6 @@ import com.google.gerrit.extensions.annotations.RequiresCapability; import com.google.gerrit.extensions.api.groups.GroupInput; import com.google.gerrit.extensions.common.GroupInfo; import com.google.gerrit.extensions.registration.DynamicSet; -import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.ResourceConflictException; import com.google.gerrit.extensions.restapi.RestModifyView; @@ -96,7 +95,7 @@ public class CreateGroup implements RestModifyView @Override public GroupInfo apply(TopLevelResource resource, GroupInput input) - throws AuthException, BadRequestException, UnprocessableEntityException, + throws BadRequestException, UnprocessableEntityException, ResourceConflictException, OrmException { if (input == null) { input = new GroupInput(); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/group/PutName.java b/gerrit-server/src/main/java/com/google/gerrit/server/group/PutName.java index ba28cd14ee..826616218e 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/group/PutName.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/group/PutName.java @@ -22,7 +22,6 @@ import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.DefaultInput; import com.google.gerrit.extensions.restapi.MethodNotAllowedException; import com.google.gerrit.extensions.restapi.ResourceConflictException; -import com.google.gerrit.extensions.restapi.ResourceNotFoundException; import com.google.gerrit.extensions.restapi.RestModifyView; import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.AccountGroupName; @@ -71,8 +70,7 @@ public class PutName implements RestModifyView { @Override public String apply(GroupResource rsrc, Input input) throws MethodNotAllowedException, AuthException, BadRequestException, - ResourceNotFoundException, ResourceConflictException, OrmException, - NoSuchGroupException { + ResourceConflictException, OrmException, NoSuchGroupException { if (rsrc.toAccountGroup() == null) { throw new MethodNotAllowedException(); } else if (!rsrc.getControl().isOwner()) { diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/project/BanCommit.java b/gerrit-server/src/main/java/com/google/gerrit/server/project/BanCommit.java index ef153ced1d..f0c2b78250 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/project/BanCommit.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/project/BanCommit.java @@ -60,7 +60,7 @@ public class BanCommit implements RestModifyView { @Override public BanResultInfo apply(ProjectResource rsrc, Input input) throws UnprocessableEntityException, AuthException, - ResourceConflictException, IOException, InterruptedException { + ResourceConflictException, IOException { BanResultInfo r = new BanResultInfo(); if (input != null && input.commits != null && !input.commits.isEmpty()) { List commitsToBan = new ArrayList<>(input.commits.size()); diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/BanCommitCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/BanCommitCommand.java index 647d28d650..ec8b94d602 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/BanCommitCommand.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/BanCommitCommand.java @@ -71,7 +71,7 @@ public class BanCommitCommand extends SshCommand { printCommits(r.newlyBanned, "The following commits were banned"); printCommits(r.alreadyBanned, "The following commits were already banned"); printCommits(r.ignored, "The following ids do not represent commits and were ignored"); - } catch (RestApiException | IOException | InterruptedException e) { + } catch (RestApiException | IOException e) { throw die(e); } }