Remove declarations of unthrown IOException

Change-Id: I2697644c1364bc993ca526714e606d8cb24364f7
This commit is contained in:
David Pursehouse
2020-03-10 19:12:36 +09:00
parent b1497fdcc0
commit c8562b12cf
21 changed files with 29 additions and 44 deletions

View File

@@ -27,7 +27,6 @@ import com.google.gerrit.common.data.LabelType;
import com.google.gerrit.entities.Account; import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.PatchSetApproval; import com.google.gerrit.entities.PatchSetApproval;
import com.google.gerrit.exceptions.StorageException;
import com.google.gerrit.extensions.client.ChangeKind; import com.google.gerrit.extensions.client.ChangeKind;
import com.google.gerrit.server.change.ChangeKindCache; import com.google.gerrit.server.change.ChangeKindCache;
import com.google.gerrit.server.change.LabelNormalizer; import com.google.gerrit.server.change.LabelNormalizer;
@@ -39,7 +38,6 @@ import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState; import com.google.gerrit.server.project.ProjectState;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
@@ -91,8 +89,6 @@ public class ApprovalInference {
Collection<PatchSetApproval> approvals = Collection<PatchSetApproval> approvals =
getForPatchSetWithoutNormalization(notes, project, psId, rw, repoConfig); getForPatchSetWithoutNormalization(notes, project, psId, rw, repoConfig);
return labelNormalizer.normalize(notes, approvals).getNormalized(); return labelNormalizer.normalize(notes, approvals).getNormalized();
} catch (IOException e) {
throw new StorageException(e);
} }
} }

View File

@@ -131,8 +131,7 @@ public class PatchSetUtil {
} }
/** Check if the current patch set of the change is locked. */ /** Check if the current patch set of the change is locked. */
public void checkPatchSetNotLocked(ChangeNotes notes) public void checkPatchSetNotLocked(ChangeNotes notes) throws ResourceConflictException {
throws IOException, ResourceConflictException {
if (isPatchSetLocked(notes)) { if (isPatchSetLocked(notes)) {
throw new ResourceConflictException( throw new ResourceConflictException(
String.format("The current patch set of change %s is locked", notes.getChangeId())); String.format("The current patch set of change %s is locked", notes.getChangeId()));
@@ -140,7 +139,7 @@ public class PatchSetUtil {
} }
/** Is the current patch set locked against state changes? */ /** Is the current patch set locked against state changes? */
public boolean isPatchSetLocked(ChangeNotes notes) throws IOException { public boolean isPatchSetLocked(ChangeNotes notes) {
Change change = notes.getChange(); Change change = notes.getChange();
if (change.isMerged()) { if (change.isMerged()) {
return false; return false;

View File

@@ -31,7 +31,6 @@ import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.project.ProjectCache; import com.google.gerrit.server.project.ProjectCache;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -82,8 +81,7 @@ public class LabelNormalizer {
* @return copies of approvals normalized to the defined ranges for the label type. Approvals for * @return copies of approvals normalized to the defined ranges for the label type. Approvals for
* unknown labels are not included in the output. * unknown labels are not included in the output.
*/ */
public Result normalize(ChangeNotes notes, Collection<PatchSetApproval> approvals) public Result normalize(ChangeNotes notes, Collection<PatchSetApproval> approvals) {
throws IOException {
List<PatchSetApproval> unchanged = Lists.newArrayListWithCapacity(approvals.size()); List<PatchSetApproval> unchanged = Lists.newArrayListWithCapacity(approvals.size());
List<PatchSetApproval> updated = Lists.newArrayListWithCapacity(approvals.size()); List<PatchSetApproval> updated = Lists.newArrayListWithCapacity(approvals.size());
List<PatchSetApproval> deleted = Lists.newArrayListWithCapacity(approvals.size()); List<PatchSetApproval> deleted = Lists.newArrayListWithCapacity(approvals.size());

View File

@@ -238,7 +238,7 @@ public class RevisionJson {
} }
private Map<String, FetchInfo> makeFetchMap(ChangeData cd, PatchSet in) private Map<String, FetchInfo> makeFetchMap(ChangeData cd, PatchSet in)
throws PermissionBackendException, IOException { throws PermissionBackendException {
Map<String, FetchInfo> r = new LinkedHashMap<>(); Map<String, FetchInfo> r = new LinkedHashMap<>();
for (Extension<DownloadScheme> e : downloadSchemes) { for (Extension<DownloadScheme> e : downloadSchemes) {
String schemeName = e.getExportName(); String schemeName = e.getExportName();
@@ -358,7 +358,7 @@ public class RevisionJson {
: withUser.indexedChange(cd, notesFactory.createFromIndexedChange(cd.change())); : withUser.indexedChange(cd, notesFactory.createFromIndexedChange(cd.change()));
} }
private boolean isWorldReadable(ChangeData cd) throws PermissionBackendException, IOException { private boolean isWorldReadable(ChangeData cd) throws PermissionBackendException {
try { try {
permissionBackendForChange(permissionBackend.user(anonymous), cd) permissionBackendForChange(permissionBackend.user(anonymous), cd)
.check(ChangePermission.READ); .check(ChangePermission.READ);

View File

@@ -413,7 +413,7 @@ public class ChangeEditModifier {
} }
private void assertCanEdit(ChangeNotes notes) private void assertCanEdit(ChangeNotes notes)
throws AuthException, PermissionBackendException, IOException, ResourceConflictException { throws AuthException, PermissionBackendException, ResourceConflictException {
if (!currentUser.get().isIdentifiedUser()) { if (!currentUser.get().isIdentifiedUser()) {
throw new AuthException("Authentication required"); throw new AuthException("Authentication required");
} }

View File

@@ -540,7 +540,7 @@ public class ReplaceOp implements BatchUpdateOp {
} }
} }
private void fireApprovalsEvent(Context ctx) throws IOException { private void fireApprovalsEvent(Context ctx) {
if (approvals.isEmpty()) { if (approvals.isEmpty()) {
return; return;
} }

View File

@@ -142,8 +142,7 @@ public class CommitValidators {
NoteMap rejectCommits, NoteMap rejectCommits,
RevWalk rw, RevWalk rw,
@Nullable Change change, @Nullable Change change,
boolean skipValidation) boolean skipValidation) {
throws IOException {
PermissionBackend.ForRef perm = forProject.ref(branch.branch()); PermissionBackend.ForRef perm = forProject.ref(branch.branch());
ProjectState projectState = ProjectState projectState =
projectCache.get(branch.project()).orElseThrow(illegalState(branch.project())); projectCache.get(branch.project()).orElseThrow(illegalState(branch.project()));
@@ -172,8 +171,7 @@ public class CommitValidators {
IdentifiedUser user, IdentifiedUser user,
SshInfo sshInfo, SshInfo sshInfo,
RevWalk rw, RevWalk rw,
@Nullable Change change) @Nullable Change change) {
throws IOException {
PermissionBackend.ForRef perm = forProject.ref(branch.branch()); PermissionBackend.ForRef perm = forProject.ref(branch.branch());
ProjectState projectState = ProjectState projectState =
projectCache.get(branch.project()).orElseThrow(illegalState(branch.project())); projectCache.get(branch.project()).orElseThrow(illegalState(branch.project()));
@@ -195,8 +193,7 @@ public class CommitValidators {
} }
public CommitValidators forMergedCommits( public CommitValidators forMergedCommits(
PermissionBackend.ForProject forProject, BranchNameKey branch, IdentifiedUser user) PermissionBackend.ForProject forProject, BranchNameKey branch, IdentifiedUser user) {
throws IOException {
// Generally only include validators that are based on permissions of the // Generally only include validators that are based on permissions of the
// user creating a change for a merged commit; generally exclude // user creating a change for a merged commit; generally exclude
// validators that would require amending the change in order to correct. // validators that would require amending the change in order to correct.

View File

@@ -145,7 +145,7 @@ public class Abandon
if (patchSetUtil.isPatchSetLocked(rsrc.getNotes())) { if (patchSetUtil.isPatchSetLocked(rsrc.getNotes())) {
return description; return description;
} }
} catch (StorageException | IOException e) { } catch (StorageException e) {
logger.atSevere().withCause(e).log( logger.atSevere().withCause(e).log(
"Failed to check if the current patch set of change %s is locked", change.getId()); "Failed to check if the current patch set of change %s is locked", change.getId());
return description; return description;

View File

@@ -98,8 +98,7 @@ public class ChangesCollection implements RestCollection<TopLevelResource, Chang
} }
public ChangeResource parse(Change.Id id) public ChangeResource parse(Change.Id id)
throws ResourceConflictException, ResourceNotFoundException, PermissionBackendException, throws ResourceConflictException, ResourceNotFoundException, PermissionBackendException {
IOException {
List<ChangeNotes> notes = changeFinder.find(id); List<ChangeNotes> notes = changeFinder.find(id);
if (notes.isEmpty()) { if (notes.isEmpty()) {
throw new ResourceNotFoundException(toIdString(id)); throw new ResourceNotFoundException(toIdString(id));
@@ -123,7 +122,7 @@ public class ChangesCollection implements RestCollection<TopLevelResource, Chang
return changeResourceFactory.create(notes, user); return changeResourceFactory.create(notes, user);
} }
private boolean canRead(ChangeNotes notes) throws PermissionBackendException, IOException { private boolean canRead(ChangeNotes notes) throws PermissionBackendException {
try { try {
permissionBackend.currentUser().change(notes).check(ChangePermission.READ); permissionBackend.currentUser().change(notes).check(ChangePermission.READ);
} catch (AuthException e) { } catch (AuthException e) {

View File

@@ -311,7 +311,7 @@ public class Move implements RestModifyView<ChangeResource, MoveInput>, UiAction
if (psUtil.isPatchSetLocked(rsrc.getNotes())) { if (psUtil.isPatchSetLocked(rsrc.getNotes())) {
return description; return description;
} }
} catch (StorageException | IOException e) { } catch (StorageException e) {
logger.atSevere().withCause(e).log( logger.atSevere().withCause(e).log(
"Failed to check if the current patch set of change %s is locked", change.getId()); "Failed to check if the current patch set of change %s is locked", change.getId());
return description; return description;

View File

@@ -179,7 +179,7 @@ public class PutMessage implements RestModifyView<ChangeResource, CommitMessageI
} }
private void ensureCanEditCommitMessage(ChangeNotes changeNotes) private void ensureCanEditCommitMessage(ChangeNotes changeNotes)
throws AuthException, PermissionBackendException, IOException, ResourceConflictException { throws AuthException, PermissionBackendException, ResourceConflictException {
if (!userProvider.get().isIdentifiedUser()) { if (!userProvider.get().isIdentifiedUser()) {
throw new AuthException("Authentication required"); throw new AuthException("Authentication required");
} }

View File

@@ -238,7 +238,7 @@ public class Rebase
if (patchSetUtil.isPatchSetLocked(rsrc.getNotes())) { if (patchSetUtil.isPatchSetLocked(rsrc.getNotes())) {
return description; return description;
} }
} catch (StorageException | IOException e) { } catch (StorageException e) {
logger.atSevere().withCause(e).log( logger.atSevere().withCause(e).log(
"Failed to check if the current patch set of change %s is locked", change.getId()); "Failed to check if the current patch set of change %s is locked", change.getId());
return description; return description;

View File

@@ -146,7 +146,7 @@ class RelatedChangesSorter {
private Collection<PatchSetData> walkAncestors( private Collection<PatchSetData> walkAncestors(
ListMultimap<PatchSetData, PatchSetData> parents, PatchSetData start) ListMultimap<PatchSetData, PatchSetData> parents, PatchSetData start)
throws PermissionBackendException, IOException { throws PermissionBackendException {
LinkedHashSet<PatchSetData> result = new LinkedHashSet<>(); LinkedHashSet<PatchSetData> result = new LinkedHashSet<>();
Deque<PatchSetData> pending = new ArrayDeque<>(); Deque<PatchSetData> pending = new ArrayDeque<>();
pending.add(start); pending.add(start);
@@ -166,7 +166,7 @@ class RelatedChangesSorter {
PatchSetData start, PatchSetData start,
List<PatchSetData> otherPatchSetsOfStart, List<PatchSetData> otherPatchSetsOfStart,
Iterable<PatchSetData> ancestors) Iterable<PatchSetData> ancestors)
throws PermissionBackendException, IOException { throws PermissionBackendException {
Set<Change.Id> alreadyEmittedChanges = new HashSet<>(); Set<Change.Id> alreadyEmittedChanges = new HashSet<>();
addAllChangeIds(alreadyEmittedChanges, ancestors); addAllChangeIds(alreadyEmittedChanges, ancestors);
@@ -193,7 +193,7 @@ class RelatedChangesSorter {
Set<Change.Id> alreadyEmittedChanges, Set<Change.Id> alreadyEmittedChanges,
ListMultimap<PatchSetData, PatchSetData> children, ListMultimap<PatchSetData, PatchSetData> children,
List<PatchSetData> start) List<PatchSetData> start)
throws PermissionBackendException, IOException { throws PermissionBackendException {
if (start.isEmpty()) { if (start.isEmpty()) {
return ImmutableList.of(); return ImmutableList.of();
} }

View File

@@ -185,7 +185,7 @@ public class Restore
if (psUtil.isPatchSetLocked(rsrc.getNotes())) { if (psUtil.isPatchSetLocked(rsrc.getNotes())) {
return description; return description;
} }
} catch (StorageException | IOException e) { } catch (StorageException e) {
logger.atSevere().withCause(e).log( logger.atSevere().withCause(e).log(
"Failed to check if the current patch set of change %s is locked", change.getId()); "Failed to check if the current patch set of change %s is locked", change.getId());
return description; return description;

View File

@@ -106,7 +106,7 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
} }
} }
private boolean visible(ChangeResource change) throws PermissionBackendException, IOException { private boolean visible(ChangeResource change) throws PermissionBackendException {
try { try {
permissionBackend permissionBackend
.user(change.getUser()) .user(change.getUser())

View File

@@ -136,7 +136,7 @@ public class ProjectsCollection
@Nullable @Nullable
private ProjectResource _parse(String id, boolean checkAccess) private ProjectResource _parse(String id, boolean checkAccess)
throws IOException, PermissionBackendException, ResourceConflictException { throws PermissionBackendException, ResourceConflictException {
id = ProjectUtil.sanitizeProjectName(id); id = ProjectUtil.sanitizeProjectName(id);
Project.NameKey nameKey = Project.nameKey(id); Project.NameKey nameKey = Project.nameKey(id);

View File

@@ -149,7 +149,7 @@ public class MergeSuperSet {
*/ */
private ChangeSet topicClosure( private ChangeSet topicClosure(
ChangeSet changeSet, CurrentUser user, Set<String> topicsSeen, Set<String> visibleTopicsSeen) ChangeSet changeSet, CurrentUser user, Set<String> topicsSeen, Set<String> visibleTopicsSeen)
throws PermissionBackendException, IOException { throws PermissionBackendException {
List<ChangeData> visibleChanges = new ArrayList<>(); List<ChangeData> visibleChanges = new ArrayList<>();
List<ChangeData> nonVisibleChanges = new ArrayList<>(); List<ChangeData> nonVisibleChanges = new ArrayList<>();

View File

@@ -30,7 +30,6 @@ import com.google.gerrit.server.project.ProjectState;
import com.google.gerrit.server.restapi.change.ChangesCollection; import com.google.gerrit.server.restapi.change.ChangesCollection;
import com.google.gerrit.sshd.BaseCommand.UnloggedFailure; import com.google.gerrit.sshd.BaseCommand.UnloggedFailure;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -55,13 +54,13 @@ public class ChangeArgumentParser {
} }
public void addChange(String id, Map<Change.Id, ChangeResource> changes) public void addChange(String id, Map<Change.Id, ChangeResource> changes)
throws UnloggedFailure, PermissionBackendException, IOException { throws UnloggedFailure, PermissionBackendException {
addChange(id, changes, null); addChange(id, changes, null);
} }
public void addChange( public void addChange(
String id, Map<Change.Id, ChangeResource> changes, @Nullable ProjectState projectState) String id, Map<Change.Id, ChangeResource> changes, @Nullable ProjectState projectState)
throws UnloggedFailure, PermissionBackendException, IOException { throws UnloggedFailure, PermissionBackendException {
addChange(id, changes, projectState, true); addChange(id, changes, projectState, true);
} }
@@ -70,7 +69,7 @@ public class ChangeArgumentParser {
Map<Change.Id, ChangeResource> changes, Map<Change.Id, ChangeResource> changes,
@Nullable ProjectState projectState, @Nullable ProjectState projectState,
boolean useIndex) boolean useIndex)
throws UnloggedFailure, PermissionBackendException, IOException { throws UnloggedFailure, PermissionBackendException {
List<ChangeNotes> matched = useIndex ? changeFinder.find(id) : changeFromNotesFactory(id); List<ChangeNotes> matched = useIndex ? changeFinder.find(id) : changeFromNotesFactory(id);
List<ChangeNotes> toAdd = new ArrayList<>(changes.size()); List<ChangeNotes> toAdd = new ArrayList<>(changes.size());
boolean canMaintainServer; boolean canMaintainServer;

View File

@@ -24,7 +24,6 @@ import com.google.gerrit.sshd.ChangeArgumentParser;
import com.google.gerrit.sshd.CommandMetaData; import com.google.gerrit.sshd.CommandMetaData;
import com.google.gerrit.sshd.SshCommand; import com.google.gerrit.sshd.SshCommand;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.io.IOException;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Argument;
@@ -44,7 +43,7 @@ final class IndexChangesCommand extends SshCommand {
void addChange(String token) { void addChange(String token) {
try { try {
changeArgumentParser.addChange(token, changes, null, false); changeArgumentParser.addChange(token, changes, null, false);
} catch (UnloggedFailure | StorageException | PermissionBackendException | IOException e) { } catch (UnloggedFailure | StorageException | PermissionBackendException e) {
writeError("warning", e.getMessage()); writeError("warning", e.getMessage());
} }
} }

View File

@@ -31,7 +31,6 @@ import com.google.gerrit.sshd.ChangeArgumentParser;
import com.google.gerrit.sshd.CommandMetaData; import com.google.gerrit.sshd.CommandMetaData;
import com.google.gerrit.sshd.SshCommand; import com.google.gerrit.sshd.SshCommand;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@@ -73,7 +72,7 @@ public class SetReviewersCommand extends SshCommand {
void addChange(String token) { void addChange(String token) {
try { try {
changeArgumentParser.addChange(token, changes, projectState); changeArgumentParser.addChange(token, changes, projectState);
} catch (IOException | UnloggedFailure e) { } catch (UnloggedFailure e) {
throw new IllegalArgumentException(e.getMessage(), e); throw new IllegalArgumentException(e.getMessage(), e);
} catch (StorageException e) { } catch (StorageException e) {
throw new IllegalArgumentException("database is down", e); throw new IllegalArgumentException("database is down", e);

View File

@@ -259,8 +259,7 @@ public class AccountIT extends AbstractDaemonTest {
boolean exclusive, boolean exclusive,
String labelName, String labelName,
int min, int min,
int max) int max) {
throws IOException {
ProjectConfig cfg = projectCache.get(project).orElseThrow(illegalState(project)).getConfig(); ProjectConfig cfg = projectCache.get(project).orElseThrow(illegalState(project)).getConfig();
AccessSection accessSection = cfg.getAccessSection(ref); AccessSection accessSection = cfg.getAccessSection(ref);
assertThat(accessSection).isNotNull(); assertThat(accessSection).isNotNull();