Use try/multi-catch

Change-Id: Icf5042cccb0662d6bd53302800e03211af94c16d
This commit is contained in:
Urs Wolfer 2015-06-24 20:06:25 +02:00 committed by David Pursehouse
parent 8702786e5a
commit 64cfaf242d
39 changed files with 51 additions and 174 deletions

View File

@ -110,9 +110,7 @@ public class GerritServer {
public void run() {
try {
serverStarted.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (BrokenBarrierException e) {
} catch (InterruptedException | BrokenBarrierException e) {
throw new RuntimeException(e);
}
}

View File

@ -98,10 +98,7 @@ public class PrivateInternals_DynamicTypes {
handles.add(item.set(b.getKey(), b.getProvider(), pluginName));
}
}
} catch (RuntimeException e) {
remove(handles);
throw e;
} catch (Error e) {
} catch (RuntimeException | Error e) {
remove(handles);
throw e;
}
@ -130,10 +127,7 @@ public class PrivateInternals_DynamicTypes {
}
}
}
} catch (RuntimeException e) {
remove(handles);
throw e;
} catch (Error e) {
} catch (RuntimeException | Error e) {
remove(handles);
throw e;
}
@ -164,10 +158,7 @@ public class PrivateInternals_DynamicTypes {
}
}
}
} catch (RuntimeException e) {
remove(handles);
throw e;
} catch (Error e) {
} catch (RuntimeException | Error e) {
remove(handles);
throw e;
}

View File

@ -238,11 +238,7 @@ public class CatServlet extends HttpServlet {
return;
}
}
} catch (IOException e) {
getServletContext().log("Cannot read repository", e);
rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
} catch (RuntimeException e) {
} catch (IOException | RuntimeException e) {
getServletContext().log("Cannot read repository", e);
rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;

View File

@ -66,13 +66,8 @@ public abstract class Handler<T> implements Callable<T> {
if (r != null) {
callback.onSuccess(r);
}
} catch (NoSuchProjectException e) {
callback.onFailure(new NoSuchEntityException());
} catch (NoSuchRefException e) {
callback.onFailure(new NoSuchEntityException());
} catch (NoSuchChangeException e) {
} catch (NoSuchProjectException | NoSuchChangeException
| NoSuchRefException e) {
callback.onFailure(new NoSuchEntityException());
} catch (OrmException e) {

View File

@ -234,11 +234,8 @@ class AccountSecurityImpl extends BaseServiceImplementation implements
} else {
throw new EmailTokenVerifier.InvalidTokenException();
}
} catch (EmailTokenVerifier.InvalidTokenException e) {
callback.onFailure(e);
} catch (AccountException e) {
callback.onFailure(e);
} catch (OrmException e) {
} catch (EmailTokenVerifier.InvalidTokenException | OrmException
| AccountException e) {
callback.onFailure(e);
}
}

View File

@ -146,9 +146,7 @@ public abstract class ProjectAccessHandler<T> extends Handler<T> {
"You are not allowed to change the parent project since you are "
+ "not an administrator. You may save the modifications for review "
+ "so that an administrator can approve them.", e);
} catch (ResourceConflictException e) {
throw new UpdateParentFailedException(e.getMessage(), e);
} catch (UnprocessableEntityException e) {
} catch (ResourceConflictException | UnprocessableEntityException e) {
throw new UpdateParentFailedException(e.getMessage(), e);
}
config.getProject().setParentName(parentProjectName);

View File

@ -115,9 +115,7 @@ class LuceneVersionManager implements LifecycleListener {
FileBasedConfig cfg;
try {
cfg = loadGerritIndexConfig(sitePaths);
} catch (ConfigInvalidException e) {
throw fail(e);
} catch (IOException e) {
} catch (ConfigInvalidException | IOException e) {
throw fail(e);
}

View File

@ -145,9 +145,7 @@ public class AuthSMTPClient extends SMTPClient {
Mac mac = Mac.getInstance(macName);
mac.init(new SecretKeySpec(smtpPass.getBytes(UTF_8), macName));
sec = toHex(mac.doFinal(nonce));
} catch (NoSuchAlgorithmException e) {
throw new IOException("Cannot use CRAM-" + alg, e);
} catch (InvalidKeyException e) {
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
throw new IOException("Cannot use CRAM-" + alg, e);
}

View File

@ -80,9 +80,7 @@ public class JythonShell {
try {
shell = console.newInstance();
log.info("Jython shell instance created.");
} catch (InstantiationException e) {
throw noInterpreter(e);
} catch (IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException e) {
throw noInterpreter(e);
}
injectedVariables = new ArrayList<>();
@ -96,13 +94,8 @@ public class JythonShell {
Method m;
m = klazz.getMethod(name, sig);
return m.invoke(instance, args);
} catch (NoSuchMethodException e) {
throw cannotStart(e);
} catch (SecurityException e) {
throw cannotStart(e);
} catch (IllegalArgumentException e) {
throw cannotStart(e);
} catch (IllegalAccessException e) {
} catch (NoSuchMethodException | IllegalAccessException
| IllegalArgumentException | SecurityException e) {
throw cannotStart(e);
}
}

View File

@ -125,12 +125,7 @@ public class BaseInit extends SiteProgram {
run.upgradeSchema();
init.initializer.postRun(createSysInjector(init));
} catch (Exception failure) {
if (init.flags.deleteOnFailure) {
recursiveDelete(getSitePath());
}
throw failure;
} catch (Error failure) {
} catch (Exception | Error failure) {
if (init.flags.deleteOnFailure) {
recursiveDelete(getSitePath());
}

View File

@ -53,9 +53,7 @@ class Libraries {
final Config cfg = new Config();
try {
cfg.fromText(read(RESOURCE_FILE));
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (ConfigInvalidException e) {
} catch (IOException | ConfigInvalidException e) {
throw new RuntimeException(e.getMessage(), e);
}

View File

@ -45,15 +45,9 @@ public abstract class ConsoleUI {
protected static <T extends Enum<?>> T[] all(final T value) {
try {
return (T[]) value.getClass().getMethod("values").invoke(null);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Cannot obtain enumeration values", e);
} catch (SecurityException e) {
throw new IllegalArgumentException("Cannot obtain enumeration values", e);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Cannot obtain enumeration values", e);
} catch (InvocationTargetException e) {
throw new IllegalArgumentException("Cannot obtain enumeration values", e);
} catch (NoSuchMethodException e) {
} catch (IllegalArgumentException | NoSuchMethodException
| InvocationTargetException | IllegalAccessException
| SecurityException e) {
throw new IllegalArgumentException("Cannot obtain enumeration values", e);
}
}

View File

@ -228,9 +228,7 @@ public class LdapGroupBackend implements GroupBackend {
log.warn("Cannot close LDAP query handle", e);
}
}
} catch (NamingException e) {
log.warn("Cannot query LDAP for groups matching requested name", e);
} catch (LoginException e) {
} catch (NamingException | LoginException e) {
log.warn("Cannot query LDAP for groups matching requested name", e);
}
return out;

View File

@ -31,15 +31,9 @@ public class ConfigUtil {
private static <T> T[] allValuesOf(final T defaultValue) {
try {
return (T[]) defaultValue.getClass().getMethod("values").invoke(null);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Cannot obtain enumeration values", e);
} catch (SecurityException e) {
throw new IllegalArgumentException("Cannot obtain enumeration values", e);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Cannot obtain enumeration values", e);
} catch (InvocationTargetException e) {
throw new IllegalArgumentException("Cannot obtain enumeration values", e);
} catch (NoSuchMethodException e) {
} catch (IllegalArgumentException | NoSuchMethodException
| InvocationTargetException | IllegalAccessException
| SecurityException e) {
throw new IllegalArgumentException("Cannot obtain enumeration values", e);
}
}

View File

@ -55,9 +55,7 @@ class GerritServerConfigProvider implements Provider<Config> {
try {
cfg.load();
} catch (IOException e) {
throw new ProvisionException(e.getMessage(), e);
} catch (ConfigInvalidException e) {
} catch (IOException | ConfigInvalidException e) {
throw new ProvisionException(e.getMessage(), e);
}

View File

@ -264,9 +264,7 @@ public class PluginConfigFactory implements ReloadPluginListener {
try {
cfg.load();
} catch (IOException e) {
log.warn("Failed to load " + pluginConfigFile.toAbsolutePath(), e);
} catch (ConfigInvalidException e) {
} catch (IOException | ConfigInvalidException e) {
log.warn("Failed to load " + pluginConfigFile.toAbsolutePath(), e);
}

View File

@ -94,9 +94,7 @@ public class QueryDocumentationExecutor {
out.add(result);
}
return out;
} catch (IOException e) {
throw new DocQueryException(e);
} catch (ParseException e) {
} catch (IOException | ParseException e) {
throw new DocQueryException(e);
}
}

View File

@ -355,8 +355,6 @@ public class LocalDiskRepositoryManager implements GitRepositoryManager {
f.write(Constants.encode(d));
f.commit();
}
} catch (RepositoryNotFoundException e) {
log.error("Cannot update description for " + name, e);
} catch (IOException e) {
log.error("Cannot update description for " + name, e);
}

View File

@ -831,9 +831,7 @@ public class MergeOp {
message(c, "Unspecified merge failure: " + s.name()));
break;
}
} catch (OrmException err) {
logWarn("Error updating change status for " + c.getId(), err);
} catch (IOException err) {
} catch (OrmException | IOException err) {
logWarn("Error updating change status for " + c.getId(), err);
}
}

View File

@ -736,12 +736,7 @@ public class ReceiveCommits {
if (replace.insertPatchSet().checkedGet() != null) {
replace.inputCommand.setResult(OK);
}
} catch (IOException err) {
reject(replace.inputCommand, "internal server error");
log.error(String.format(
"Cannot add patch set to %d of %s",
e.getKey().get(), project.getName()), err);
} catch (InsertException err) {
} catch (IOException | InsertException err) {
reject(replace.inputCommand, "internal server error");
log.error(String.format(
"Cannot add patch set to %d of %s",
@ -2593,9 +2588,7 @@ public class ReceiveCommits {
currentUser.getAccount()).update();
} catch (InsertException e) {
log.error("Can't insert patchset", e);
} catch (IOException e) {
log.error("Can't scan for changes to close", e);
} catch (OrmException e) {
} catch (IOException | OrmException e) {
log.error("Can't scan for changes to close", e);
} catch (SubmoduleException e) {
log.error("Can't complete git links check", e);

View File

@ -92,9 +92,7 @@ public class RenameGroupOp extends DefaultQueueOp {
}
} catch (RepositoryNotFoundException noProject) {
continue;
} catch (ConfigInvalidException err) {
log.error("Cannot rename group " + oldName + " in " + projectName, err);
} catch (IOException err) {
} catch (ConfigInvalidException | IOException err) {
log.error("Cannot rename group " + oldName + " in " + projectName, err);
}
}

View File

@ -159,8 +159,8 @@ public class GroupsCollection implements
try {
AccountGroup.Id legacyId = AccountGroup.Id.parse(id);
return groupControlFactory.controlFor(legacyId).getGroup();
} catch (IllegalArgumentException invalidId) {
} catch (NoSuchGroupException e) {
} catch (IllegalArgumentException | NoSuchGroupException e) {
// Ignored
}
}

View File

@ -308,9 +308,7 @@ public class ChangeSchemas {
checkArgument(f.getName().startsWith("V"));
schema.setVersion(Integer.parseInt(f.getName().substring(1)));
all.put(schema.getVersion(), schema);
} catch (IllegalArgumentException e) {
throw new ExceptionInInitializerError(e);
} catch (IllegalAccessException e) {
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new ExceptionInInitializerError(e);
}
} else {

View File

@ -53,9 +53,7 @@ public class SignedTokenEmailTokenVerifier implements EmailTokenVerifier {
byte[] utf8 = payload.getBytes("UTF-8");
String base64 = Base64.encodeBytes(utf8);
return emailRegistrationToken.newToken(base64);
} catch (XsrfException e) {
throw new IllegalArgumentException(e);
} catch (UnsupportedEncodingException e) {
} catch (XsrfException | UnsupportedEncodingException e) {
throw new IllegalArgumentException(e);
}
}

View File

@ -31,7 +31,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.zip.ZipException;
@ -66,8 +65,6 @@ class InstallPlugin implements RestModifyView<TopLevelResource, Input> {
} else {
try {
in = new URL(input.url).openStream();
} catch (MalformedURLException e) {
throw new BadRequestException(e.getMessage());
} catch (IOException e) {
throw new BadRequestException(e.getMessage());
}

View File

@ -239,9 +239,7 @@ public class CreateBranch implements RestModifyView<ProjectResource, Input> {
}
rw.checkConnectivity();
return rw;
} catch (IncorrectObjectTypeException err) {
throw new InvalidRevisionException();
} catch (MissingObjectException err) {
} catch (IncorrectObjectTypeException | MissingObjectException err) {
throw new InvalidRevisionException();
} catch (IOException err) {
log.error("Repository \"" + repo.getDirectory()

View File

@ -106,11 +106,8 @@ class DashboardsCollection implements
for (ProjectState ps : myCtl.getProjectState().tree()) {
try {
return parse(ps.controlFor(user), ref, path, myCtl);
} catch (AmbiguousObjectException e) {
throw new ResourceNotFoundException(id);
} catch (IncorrectObjectTypeException e) {
throw new ResourceNotFoundException(id);
} catch (ConfigInvalidException e) {
} catch (AmbiguousObjectException | ConfigInvalidException
| IncorrectObjectTypeException e) {
throw new ResourceNotFoundException(id);
} catch (ResourceNotFoundException e) {
continue;

View File

@ -48,9 +48,7 @@ public class GetStatistics implements RestReadView<ProjectResource> {
try (Repository repo = repoManager.openRepository(rsrc.getNameKey())) {
GarbageCollectCommand gc = Git.wrap(repo).gc();
return new RepositoryStatistics(gc.getStatistics());
} catch (GitAPIException e) {
throw new ResourceConflictException(e.getMessage());
} catch (JGitInternalException e) {
} catch (GitAPIException | JGitInternalException e) {
throw new ResourceConflictException(e.getMessage());
} catch (IOException e) {
throw new ResourceNotFoundException(rsrc.getName());

View File

@ -225,9 +225,7 @@ public class ProjectState {
ProjectLevelConfig cfg = new ProjectLevelConfig(fileName, this);
try (Repository git = gitMgr.openRepository(getProject().getNameKey())) {
cfg.load(git);
} catch (IOException e) {
log.warn("Failed to load " + fileName + " for " + getProject().getName(), e);
} catch (ConfigInvalidException e) {
} catch (IOException | ConfigInvalidException e) {
log.warn("Failed to load " + fileName + " for " + getProject().getName(), e);
}

View File

@ -350,9 +350,7 @@ public abstract class QueryBuilder<T> {
throws QueryParseException {
try {
return (Predicate<T>) method.invoke(builder, value);
} catch (RuntimeException e) {
throw error("Error in operator " + name + ":" + value, e);
} catch (IllegalAccessException e) {
} catch (RuntimeException | IllegalAccessException e) {
throw error("Error in operator " + name + ":" + value, e);
} catch (InvocationTargetException e) {
throw error("Error in operator " + name + ":" + value, e.getCause());

View File

@ -96,9 +96,7 @@ public class SchemaUpdater {
if (version == null) {
try {
creator.create(db);
} catch (IOException e) {
throw new OrmException("Cannot initialize schema", e);
} catch (ConfigInvalidException e) {
} catch (IOException | ConfigInvalidException e) {
throw new OrmException("Cannot initialize schema", e);
}

View File

@ -203,11 +203,7 @@ public abstract class BaseCommand implements Command {
final CmdLineParser clp = newCmdLineParser(options);
try {
clp.parseArgument(argv);
} catch (IllegalArgumentException err) {
if (!clp.wasHelpRequestedByOption()) {
throw new UnloggedFailure(1, "fatal: " + err.getMessage());
}
} catch (CmdLineException err) {
} catch (IllegalArgumentException | CmdLineException err) {
if (!clp.wasHelpRequestedByOption()) {
throw new UnloggedFailure(1, "fatal: " + err.getMessage());
}

View File

@ -195,9 +195,7 @@ class DatabasePubKeyAuth implements PublickeyAuthenticator {
try {
byte[] bin = Base64.decodeBase64(line.getBytes("ISO-8859-1"));
keys.add(new Buffer(bin).getRawPublicKey());
} catch (RuntimeException e) {
logBadKey(path, line, e);
} catch (SshException e) {
} catch (RuntimeException | SshException e) {
logBadKey(path, line, e);
}
}

View File

@ -105,10 +105,7 @@ public class SshKeyCacheImpl implements SshKeyCache {
new AccountSshKey(id, SshUtil.toOpenSshPublicKey(encoded));
SshUtil.parse(key);
return key;
} catch (NoSuchAlgorithmException e) {
throw new InvalidSshKeyException();
} catch (InvalidKeySpecException e) {
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
throw new InvalidSshKeyException();
} catch (NoSuchProviderException e) {

View File

@ -60,9 +60,7 @@ public class SshUtil {
}
final byte[] bin = Base64.decodeBase64(Constants.encodeASCII(s));
return new Buffer(bin).getRawPublicKey();
} catch (RuntimeException re) {
throw new InvalidKeySpecException("Cannot parse key", re);
} catch (SshException e) {
} catch (RuntimeException | SshException e) {
throw new InvalidKeySpecException("Cannot parse key", e);
}
}

View File

@ -158,11 +158,7 @@ final class AdminSetParent extends SshCommand {
}
} catch (RepositoryNotFoundException notFound) {
err.append("error: Project ").append(name).append(" not found\n");
} catch (IOException e) {
final String msg = "Cannot update project " + name;
log.error(msg, e);
err.append("error: ").append(msg).append("\n");
} catch (ConfigInvalidException e) {
} catch (IOException | ConfigInvalidException e) {
final String msg = "Cannot update project " + name;
log.error(msg, e);
err.append("error: ").append(msg).append("\n");

View File

@ -49,9 +49,7 @@ final class PluginReloadCommand extends SshCommand {
} else {
try {
loader.reload(names);
} catch (InvalidPluginException e) {
throw die(e.getMessage());
} catch (PluginInstallException e) {
} catch (InvalidPluginException | PluginInstallException e) {
throw die(e.getMessage());
}
}

View File

@ -95,10 +95,7 @@ public class QueryShell {
db.close();
db = null;
}
} catch (OrmException err) {
out.println("fatal: Cannot open connection: " + err.getMessage());
} catch (SQLException err) {
} catch (OrmException | SQLException err) {
out.println("fatal: Cannot open connection: " + err.getMessage());
} finally {
out.flush();
@ -123,10 +120,7 @@ public class QueryShell {
db.close();
db = null;
}
} catch (OrmException err) {
out.println("fatal: Cannot open connection: " + err.getMessage());
} catch (SQLException err) {
} catch (OrmException | SQLException err) {
out.println("fatal: Cannot open connection: " + err.getMessage());
} finally {
out.flush();

View File

@ -161,11 +161,7 @@ final class SetProjectCommand extends SshCommand {
}
} catch (RepositoryNotFoundException notFound) {
err.append("error: Project ").append(name).append(" not found\n");
} catch (IOException e) {
final String msg = "Cannot update project " + name;
log.error(msg, e);
err.append("error: ").append(msg).append("\n");
} catch (ConfigInvalidException e) {
} catch (IOException | ConfigInvalidException e) {
final String msg = "Cannot update project " + name;
log.error(msg, e);
err.append("error: ").append(msg).append("\n");