Merge branch 'stable-2.16' into stable-3.0

* stable-2.16:
  ErrorProne: Enable and fix UnusedException check
  Update git submodules

Also fix a few more instances of UnusedException.

Change-Id: Ia9864e78004f17508e13f4bf49d895d470da4942
This commit is contained in:
David Pursehouse
2020-01-24 09:21:23 +09:00
100 changed files with 232 additions and 147 deletions

View File

@@ -235,7 +235,7 @@ class InProcessProtocol extends TestProtocol<Context> {
try {
perm.check(ProjectPermission.RUN_UPLOAD_PACK);
} catch (AuthException e) {
throw new ServiceNotAuthorizedException();
throw new ServiceNotAuthorizedException(e.getMessage(), e);
} catch (PermissionBackendException e) {
throw new RuntimeException(e);
}
@@ -308,7 +308,7 @@ class InProcessProtocol extends TestProtocol<Context> {
.project(req.project)
.check(ProjectPermission.RUN_RECEIVE_PACK);
} catch (AuthException e) {
throw new ServiceNotAuthorizedException();
throw new ServiceNotAuthorizedException(e.getMessage(), e);
} catch (PermissionBackendException e) {
throw new RuntimeException(e);
}

View File

@@ -23,4 +23,8 @@ public class InvalidSshKeyException extends Exception {
public InvalidSshKeyException() {
super(MESSAGE);
}
public InvalidSshKeyException(Throwable cause) {
super(MESSAGE, cause);
}
}

View File

@@ -26,4 +26,12 @@ public class MethodNotAllowedException extends RestApiException {
public MethodNotAllowedException(String msg) {
super(msg);
}
/**
* @param msg error text for client describing why the method is not allowed.
* @param cause reason for the method not being allowed.
*/
public MethodNotAllowedException(String msg, Throwable cause) {
super(msg, cause);
}
}

View File

@@ -25,4 +25,8 @@ public class NotImplementedException extends UnsupportedOperationException {
public NotImplementedException(String message) {
super(message);
}
public NotImplementedException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -34,6 +34,10 @@ public class ResourceNotFoundException extends RestApiException {
super("Not found: " + id.get());
}
public ResourceNotFoundException(IdString id, Throwable cause) {
super("Not found: " + id.get(), cause);
}
@SuppressWarnings("unchecked")
@Override
public ResourceNotFoundException caching(CacheControl c) {

View File

@@ -131,7 +131,7 @@ public class HtmlDomUtil {
try {
d = newBuilder().newDocument();
} catch (ParserConfigurationException e) {
throw new IOException("Cannot clone document");
throw new IOException("Cannot clone document", e);
}
Node n = d.importNode(doc.getDocumentElement(), true);
d.appendChild(n);

View File

@@ -195,7 +195,7 @@ class ProjectOAuthFilter implements Filter {
defaultAuthPlugin = loginProvider.getPluginName();
defaultAuthProvider = loginProvider.getExportName();
} catch (NoSuchElementException e) {
throw new ServletException("No OAuth login provider installed");
throw new ServletException("No OAuth login provider installed", e);
} catch (IllegalArgumentException e) {
// multiple providers found => do not pick any
}

View File

@@ -61,9 +61,11 @@ class PluginServletContext {
try {
handler = API.class.getDeclaredMethod(method.getName(), method.getParameterTypes());
} catch (NoSuchMethodException e) {
throw new NoSuchMethodError(
String msg =
String.format(
"%s does not implement %s", PluginServletContext.class, method.toGenericString()));
"%s does not implement %s", PluginServletContext.class, method.toGenericString());
logger.atSevere().withCause(e).log(msg);
throw new NoSuchMethodError(msg);
}
return handler.invoke(this, args);
}

View File

@@ -63,8 +63,9 @@ public class BazelBuild {
try {
status = rebuild.waitFor();
} catch (InterruptedException e) {
throw new InterruptedIOException(
"interrupted waiting for: " + Joiner.on(' ').join(proc.command()));
String msg = "interrupted waiting for: " + Joiner.on(' ').join(proc.command());
logger.atSevere().withCause(e).log(msg);
throw new InterruptedIOException(msg);
}
if (status != 0) {
logger.atWarning().log("build failed: %s", new String(out, UTF_8));

View File

@@ -889,7 +889,7 @@ public class RestApiServlet extends HttpServlet {
try {
first = json.peek();
} catch (EOFException e) {
throw new BadRequestException("Expected JSON object");
throw new BadRequestException("Expected JSON object", e);
}
if (first == JsonToken.STRING) {
return parseString(json.nextString(), type);

View File

@@ -167,7 +167,7 @@ public class QueryBuilder<V> {
// subclasses of OperatorPredicate.
value = Integer.parseInt(p.getValue());
} catch (NumberFormatException e) {
throw new QueryParseException("not an integer: " + p.getValue());
throw new QueryParseException("not an integer: " + p.getValue(), e);
}
return new TermQuery(intTerm(p.getField().getName(), value));
}

View File

@@ -331,7 +331,7 @@ public class BaseInit extends SiteProgram {
IoUtil.loadJARs(secureStoreLib);
return new SecureStoreInitData(secureStoreLib, secureStores.get(0));
} catch (IOException e) {
throw new InvalidSecureStoreException(String.format("%s is not a valid jar", secureStore));
throw new InvalidSecureStoreException(String.format("%s is not a valid jar", secureStore), e);
}
}

View File

@@ -169,7 +169,7 @@ class InitHttpd implements InitStep {
uri = new URI(s + "://" + uri.getHost() + uri.getPath());
}
} catch (URISyntaxException e) {
throw die("invalid httpd.listenUrl");
throw die("invalid httpd.listenUrl", e);
}
httpd.set("listenUrl", urlbuf.toString());
gerrit.string("Canonical URL", "canonicalWebUrl", uri.toString());

View File

@@ -318,7 +318,7 @@ public class ApprovalsUtil {
forChange.check(new LabelPermission.WithValue(name, value));
} catch (AuthException e) {
throw new AuthException(
String.format("applying label \"%s\": %d is restricted", name, value));
String.format("applying label \"%s\": %d is restricted", name, value), e);
}
}
}

View File

@@ -390,7 +390,7 @@ public class AccountManager {
try {
groupsUpdate.updateGroup(groupUuid, groupUpdate);
} catch (NoSuchGroupException e) {
throw new AccountException(String.format("Group %s not found", groupUuid));
throw new AccountException(String.format("Group %s not found", groupUuid), e);
}
}

View File

@@ -24,6 +24,7 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.flogger.FluentLogger;
import com.google.common.hash.Hashing;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.client.AuthType;
@@ -43,6 +44,8 @@ import org.eclipse.jgit.lib.ObjectId;
@AutoValue
public abstract class ExternalId implements Serializable {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
// If these regular expressions are modified the same modifications should be done to the
// corresponding regular expressions in the
// com.google.gerrit.client.account.UsernameField class.
@@ -391,11 +394,12 @@ public abstract class ExternalId implements Serializable {
}
return accountId;
} catch (IllegalArgumentException e) {
throw invalidConfig(
noteId,
String msg =
String.format(
"Value %s for '%s.%s.%s' is invalid, expected account ID",
accountIdStr, EXTERNAL_ID_SECTION, externalIdKeyStr, ACCOUNT_ID_KEY));
accountIdStr, EXTERNAL_ID_SECTION, externalIdKeyStr, ACCOUNT_ID_KEY);
logger.atSevere().withCause(e).log(msg);
throw invalidConfig(noteId, msg);
}
}

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.server.args4j;
import static com.google.gerrit.util.cli.Localizable.localizable;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.exceptions.StorageException;
import com.google.gerrit.extensions.client.AuthType;
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
@@ -38,6 +39,8 @@ import org.kohsuke.args4j.spi.Parameters;
import org.kohsuke.args4j.spi.Setter;
public class AccountIdHandler extends OptionHandler<Account.Id> {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final AccountResolver accountResolver;
private final AccountManager accountManager;
private final AuthType authType;
@@ -78,11 +81,15 @@ public class AccountIdHandler extends OptionHandler<Account.Id> {
case OPENID:
case OPENID_SSO:
default:
throw new CmdLineException(owner, localizable("user \"%s\" not found"), token);
String msg = "user \"%s\" not found";
logger.atSevere().withCause(e).log(msg, token);
throw new CmdLineException(owner, localizable(msg), token);
}
}
} catch (StorageException e) {
throw new CmdLineException(owner, localizable("database is down"));
String msg = "database is down";
logger.atSevere().withCause(e).log(msg);
throw new CmdLineException(owner, localizable(msg));
} catch (IOException e) {
throw new CmdLineException(owner, "Failed to load account", e);
} catch (ConfigInvalidException e) {
@@ -102,7 +109,9 @@ public class AccountIdHandler extends OptionHandler<Account.Id> {
req.setSkipAuthentication(true);
return accountManager.authenticate(req).getAccountId();
} catch (AccountException e) {
throw new CmdLineException(owner, localizable("user \"%s\" not found"), user);
String msg = "user \"%s\" not found";
logger.atSevere().withCause(e).log(msg, user);
throw new CmdLineException(owner, localizable(msg), user);
}
}

View File

@@ -66,7 +66,7 @@ public class ChangeIdHandler extends OptionHandler<Change.Id> {
return 1;
}
} catch (IllegalArgumentException e) {
throw new CmdLineException(owner, localizable("Change-Id is not valid"));
throw new CmdLineException(owner, localizable("Change-Id is not valid: %s"), e.getMessage());
} catch (StorageException e) {
throw new CmdLineException(owner, localizable("Database error: %s"), e.getMessage());
}

View File

@@ -43,7 +43,8 @@ public class PatchSetIdHandler extends OptionHandler<PatchSet.Id> {
try {
id = PatchSet.Id.parse(token);
} catch (IllegalArgumentException e) {
throw new CmdLineException(owner, localizable("\"%s\" is not a valid patch set"), token);
throw new CmdLineException(
owner, localizable("\"%s\" is not a valid patch set: %s"), token, e.getMessage());
}
setter.addValue(id);

View File

@@ -89,7 +89,7 @@ public class ProjectHandler extends OptionHandler<ProjectState> {
permissionBackend.currentUser().project(nameKey).check(permissionToCheck);
} catch (AuthException e) {
throw new CmdLineException(
owner, localizable(new NoSuchProjectException(nameKey).getMessage()));
owner, localizable(new NoSuchProjectException(nameKey, e).getMessage()));
} catch (PermissionBackendException | IOException e) {
logger.atWarning().withCause(e).log("Cannot load project %s", nameWithoutSuffix);
throw new CmdLineException(

View File

@@ -37,7 +37,7 @@ public enum IntegerCacheSerializer implements CacheSerializer<Integer> {
cout.writeInt32NoTag(requireNonNull(object));
cout.flush();
} catch (IOException e) {
throw new IllegalStateException("Failed to serialize int");
throw new IllegalStateException("Failed to serialize int", e);
}
int n = cout.getTotalBytesWritten();
return n == buf.length ? buf : Arrays.copyOfRange(buf, 0, n);
@@ -50,7 +50,7 @@ public enum IntegerCacheSerializer implements CacheSerializer<Integer> {
try {
ret = cin.readRawVarint32();
} catch (IOException e) {
throw new IllegalArgumentException("Failed to deserialize int");
throw new IllegalArgumentException("Failed to deserialize int", e);
}
int n = cin.getTotalBytesRead();
if (n != in.length) {

View File

@@ -50,7 +50,7 @@ public class PureRevert {
try {
claimedOriginalObjectId = ObjectId.fromString(claimedOriginal.get());
} catch (InvalidObjectIdException e) {
throw new BadRequestException("invalid object ID");
throw new BadRequestException("invalid object ID", e);
}
return pureRevertCache.isPureRevert(

View File

@@ -30,7 +30,6 @@ import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config;
public class ConfigUtil {
@SuppressWarnings("unchecked")
private static <T> T[] allValuesOf(T defaultValue) {
try {
@@ -182,7 +181,7 @@ public class ConfigUtil {
try {
return getTimeUnit(s, defaultValue, wantUnit);
} catch (IllegalArgumentException notTime) {
throw notTimeUnit(section, subsection, setting, valueString);
throw notTimeUnit(section, subsection, setting, valueString, notTime);
}
}
@@ -250,7 +249,7 @@ public class ConfigUtil {
try {
return wantUnit.convert(Long.parseLong(digits) * inputMul, inputUnit);
} catch (NumberFormatException nfe) {
throw notTimeUnit(valueString);
throw notTimeUnit(valueString, nfe);
}
}
@@ -421,13 +420,21 @@ public class ConfigUtil {
}
private static IllegalArgumentException notTimeUnit(
final String section,
final String subsection,
final String setting,
final String valueString) {
return new IllegalArgumentException(
"Invalid time unit value: "
+ section
String section, String subsection, String setting, String valueString, Throwable why) {
return notTimeUnit(
section
+ (subsection != null ? "." + subsection : "")
+ "."
+ setting
+ " = "
+ valueString,
why);
}
private static IllegalArgumentException notTimeUnit(
String section, String subsection, String setting, String valueString) {
return notTimeUnit(
section
+ (subsection != null ? "." + subsection : "")
+ "."
+ setting
@@ -439,5 +446,9 @@ public class ConfigUtil {
return new IllegalArgumentException("Invalid time unit value: " + val);
}
private static IllegalArgumentException notTimeUnit(String val, Throwable why) {
return new IllegalArgumentException("Invalid time unit value: " + val, why);
}
private ConfigUtil() {}
}

View File

@@ -748,6 +748,7 @@ public class MergeUtil {
try {
failed(rw, mergeTip, n, getCommitMergeStatus(e.getReason()));
} catch (IOException e2) {
logger.atSevere().withCause(e2).log("Failed to set merge failure status for " + n.name());
throw new IntegrationException("Cannot merge " + n.name(), e);
}
} catch (IOException e) {

View File

@@ -163,7 +163,7 @@ public class PureRevertCache {
try {
claimedOriginalCommit = rw.parseCommit(original);
} catch (InvalidObjectIdException | MissingObjectException e) {
throw new BadRequestException("invalid object ID");
throw new BadRequestException("invalid object ID", e);
}
if (claimedOriginalCommit.getParentCount() == 0) {
throw new BadRequestException("can't check against initial commit");

View File

@@ -27,6 +27,11 @@ public class CommitValidationException extends ValidationException {
this.messages = ImmutableList.of(message);
}
public CommitValidationException(String reason, CommitValidationMessage message, Throwable why) {
super(reason, why);
this.messages = ImmutableList.of(message);
}
public CommitValidationException(String reason, List<CommitValidationMessage> messages) {
super(reason);
this.messages = ImmutableList.copyOf(messages);

View File

@@ -467,7 +467,7 @@ public class CommitValidators {
perm.check(RefPermission.MERGE);
return Collections.emptyList();
} catch (AuthException e) {
throw new CommitValidationException("you are not allowed to upload merges");
throw new CommitValidationException("you are not allowed to upload merges", e);
} catch (PermissionBackendException e) {
logger.atSevere().withCause(e).log("cannot check MERGE");
throw new CommitValidationException("internal auth error");
@@ -564,7 +564,7 @@ public class CommitValidators {
perm.check(RefPermission.FORGE_COMMITTER);
} catch (AuthException denied) {
throw new CommitValidationException(
"not Signed-off-by author/committer/uploader in message footer");
"not Signed-off-by author/committer/uploader in message footer", denied);
} catch (PermissionBackendException e) {
logger.atSevere().withCause(e).log("cannot check FORGE_COMMITTER");
throw new CommitValidationException("internal auth error");
@@ -599,7 +599,7 @@ public class CommitValidators {
return Collections.emptyList();
} catch (AuthException e) {
throw new CommitValidationException(
"invalid author", invalidEmail("author", author, user, urlFormatter));
"invalid author", invalidEmail("author", author, user, urlFormatter), e);
} catch (PermissionBackendException e) {
logger.atSevere().withCause(e).log("cannot check FORGE_AUTHOR");
throw new CommitValidationException("internal auth error");
@@ -632,7 +632,7 @@ public class CommitValidators {
return Collections.emptyList();
} catch (AuthException e) {
throw new CommitValidationException(
"invalid committer", invalidEmail("committer", committer, user, urlFormatter));
"invalid committer", invalidEmail("committer", committer, user, urlFormatter), e);
} catch (PermissionBackendException e) {
logger.atSevere().withCause(e).log("cannot check FORGE_COMMITTER");
throw new CommitValidationException("internal auth error");
@@ -671,7 +671,8 @@ public class CommitValidators {
"pushing merge commit %s by %s requires '%s' permission",
receiveEvent.commit.getId(),
gerritIdent.getEmailAddress(),
RefPermission.FORGE_SERVER.name()));
RefPermission.FORGE_SERVER.name()),
denied);
} catch (PermissionBackendException e) {
logger.atSevere().withCause(e).log("cannot check FORGE_SERVER");
throw new CommitValidationException("internal auth error");

View File

@@ -28,4 +28,8 @@ public class MergeValidationException extends ValidationException {
public MergeValidationException(String msg) {
super(msg);
}
public MergeValidationException(String msg, Throwable why) {
super(msg, why);
}
}

View File

@@ -178,7 +178,7 @@ public class MergeValidators {
try {
permissionBackend.user(caller).check(GlobalPermission.ADMINISTRATE_SERVER);
} catch (AuthException e) {
throw new MergeValidationException(SET_BY_ADMIN);
throw new MergeValidationException(SET_BY_ADMIN, e);
} catch (PermissionBackendException e) {
logger.atWarning().withCause(e).log("Cannot check ADMINISTRATE_SERVER");
throw new MergeValidationException("validation unavailable");
@@ -190,7 +190,7 @@ public class MergeValidators {
.project(destProject.getNameKey())
.check(ProjectPermission.WRITE_CONFIG);
} catch (AuthException e) {
throw new MergeValidationException(SET_BY_OWNER);
throw new MergeValidationException(SET_BY_OWNER, e);
} catch (PermissionBackendException e) {
logger.atWarning().withCause(e).log("Cannot check WRITE_CONFIG");
throw new MergeValidationException("validation unavailable");
@@ -231,7 +231,7 @@ public class MergeValidators {
}
}
} catch (ConfigInvalidException | IOException e) {
throw new MergeValidationException(INVALID_CONFIG);
throw new MergeValidationException(INVALID_CONFIG, e);
}
}
}

View File

@@ -132,7 +132,7 @@ public class RefOperationValidators {
try {
perm.check(GlobalPermission.ACCESS_DATABASE);
} catch (AuthException | PermissionBackendException e) {
throw new ValidationException("Not allowed to create user branch.");
throw new ValidationException("Not allowed to create user branch.", e);
}
if (Account.Id.fromRef(refEvent.command.getRefName()) == null) {
throw new ValidationException(
@@ -143,7 +143,7 @@ public class RefOperationValidators {
try {
perm.check(GlobalPermission.ACCESS_DATABASE);
} catch (AuthException | PermissionBackendException e) {
throw new ValidationException("Not allowed to delete user branch.");
throw new ValidationException("Not allowed to delete user branch.", e);
}
}
}

View File

@@ -296,7 +296,7 @@ public abstract class ChangeEmail extends NotificationEmail {
try {
ps = args.patchSetUtil.get(changeData.notes(), new PatchSet.Id(change.getId(), patchSetId));
} catch (StorageException e) {
throw new PatchListNotAvailableException("Failed to get patchSet");
throw new PatchListNotAvailableException("Failed to get patchSet", e);
}
}
return args.patchListCache.get(change, ps);

View File

@@ -912,7 +912,9 @@ class ChangeNotesParser {
try {
adr = Address.parse(line);
} catch (IllegalArgumentException e) {
throw invalidFooter(state.getByEmailFooterKey(), line);
ConfigInvalidException cie = invalidFooter(state.getByEmailFooterKey(), line);
cie.initCause(e);
throw cie;
}
if (!reviewersByEmail.containsRow(adr)) {
reviewersByEmail.put(adr, state, ts);

View File

@@ -199,7 +199,7 @@ public class PatchScriptFactory implements Callable<PatchScript> {
try {
permissionBackend.currentUser().change(notes).check(ChangePermission.READ);
} catch (AuthException e) {
throw new NoSuchChangeException(changeId);
throw new NoSuchChangeException(changeId, e);
}
}

View File

@@ -125,9 +125,10 @@ public class ProjectCreator {
+ nameKey.get()
+ " because the name is already occupied by another project."
+ " The other project has the same name, only spelled in a"
+ " different case.");
+ " different case.",
e);
} catch (RepositoryNotFoundException badName) {
throw new BadRequestException("invalid project name: " + nameKey);
throw new BadRequestException("invalid project name: " + nameKey, badName);
} catch (ConfigInvalidException e) {
String msg = "Cannot create " + nameKey;
logger.atSevere().withCause(e).log(msg);

View File

@@ -55,7 +55,7 @@ public class RefUtil {
"Cannot resolve \"%s\" in project \"%s\"", baseRevision, projectName.get());
throw new InvalidRevisionException(baseRevision);
} catch (RevisionSyntaxException err) {
throw new InvalidRevisionException(baseRevision);
throw new InvalidRevisionException(baseRevision, err);
}
}
@@ -66,7 +66,7 @@ public class RefUtil {
try {
rw.markStart(rw.parseCommit(revid));
} catch (IncorrectObjectTypeException err) {
throw new InvalidRevisionException(revid.name());
throw new InvalidRevisionException(revid.name(), err);
}
RefDatabase refDb = repo.getRefDatabase();
Iterable<Ref> refs =
@@ -86,7 +86,7 @@ public class RefUtil {
rw.checkConnectivity();
return rw;
} catch (IncorrectObjectTypeException | MissingObjectException err) {
throw new InvalidRevisionException(revid.name());
throw new InvalidRevisionException(revid.name(), err);
} catch (IOException err) {
logger.atSevere().withCause(err).log(
"Repository \"%s\" may be corrupt; suggest running git fsck", repo.getDirectory());
@@ -128,5 +128,9 @@ public class RefUtil {
InvalidRevisionException(@Nullable String invalidRevision) {
super(MESSAGE + ": " + invalidRevision);
}
InvalidRevisionException(@Nullable String invalidRevision, Throwable why) {
super(MESSAGE + ": " + invalidRevision, why);
}
}
}

View File

@@ -123,7 +123,9 @@ public class AccountQueryBuilder extends QueryBuilder<AccountState, AccountQuery
try {
args.permissionBackend.user(args.getUser()).change(changeNotes).check(ChangePermission.READ);
} catch (AuthException e) {
throw error(String.format("change %s not found", change));
String msg = String.format("change %s not found", change);
logger.atSevere().withCause(e).log(msg);
throw error(msg);
}
return AccountPredicates.cansee(args, changeNotes);

View File

@@ -75,7 +75,7 @@ public class ProjectQueryBuilder extends QueryBuilder<ProjectData, ProjectQueryB
try {
parsedState = ProjectState.valueOf(state.replace('-', '_').toUpperCase());
} catch (IllegalArgumentException e) {
throw error("state operator must be either 'active' or 'read-only'");
throw error("state operator must be either 'active' or 'read-only'", e);
}
if (parsedState == ProjectState.HIDDEN) {
throw error("state operator must be either 'active' or 'read-only'");

View File

@@ -75,7 +75,7 @@ public class Capabilities implements ChildCollection<AccountResource, AccountRes
permissionBackend.absentUser(target.getAccountId()).check(perm);
return new AccountResource.Capability(target, globalOrPluginPermissionName(perm));
} catch (AuthException e) {
throw new ResourceNotFoundException(id);
throw new ResourceNotFoundException(id, e);
}
}

View File

@@ -156,7 +156,7 @@ public class CreateAccount
try {
addGroupMember(groupUuid, accountId);
} catch (NoSuchGroupException e) {
throw new UnprocessableEntityException(String.format("Group %s not found", groupUuid));
throw new UnprocessableEntityException(String.format("Group %s not found", groupUuid), e);
}
}

View File

@@ -95,7 +95,7 @@ public class PutAgreement implements RestModifyView<AccountResource, AgreementIn
try {
addMembers.addMembers(uuid, ImmutableSet.of(accountState.getAccount().getId()));
} catch (NoSuchGroupException e) {
throw new ResourceConflictException("autoverify group not found");
throw new ResourceConflictException("autoverify group not found", e);
}
agreementSignup.fire(accountState, agreementName);

View File

@@ -115,7 +115,7 @@ public class PutUsername implements RestModifyView<AccountResource, UsernameInpu
}
// Otherwise, someone else has this identity.
throw new ResourceConflictException("username already used");
throw new ResourceConflictException("username already used", dupeErr);
}
sshKeyCache.evict(input.username);

View File

@@ -70,7 +70,7 @@ public class SshKeys implements ChildCollection<AccountResource, AccountResource
permissionBackend.currentUser().check(GlobalPermission.MODIFY_ACCOUNT);
} catch (AuthException e) {
// If lacking MODIFY_ACCOUNT claim the resource does not exist.
throw new ResourceNotFoundException();
throw new ResourceNotFoundException(id, e);
}
}
return parse(rsrc.getUser(), id);
@@ -86,7 +86,7 @@ public class SshKeys implements ChildCollection<AccountResource, AccountResource
}
return new AccountResource.SshKey(user, sshKey);
} catch (NumberFormatException e) {
throw new ResourceNotFoundException(id);
throw new ResourceNotFoundException(id, e);
}
}

View File

@@ -123,10 +123,10 @@ public class StarredChanges
try {
change = changes.parse(TopLevelResource.INSTANCE, id);
} catch (ResourceNotFoundException e) {
throw new UnprocessableEntityException(String.format("change %s not found", id.get()));
throw new UnprocessableEntityException(String.format("change %s not found", id.get()), e);
} catch (StorageException | PermissionBackendException | IOException e) {
logger.atSevere().withCause(e).log("cannot resolve change");
throw new UnprocessableEntityException("internal server error");
throw new UnprocessableEntityException("internal server error", e);
}
try {

View File

@@ -286,7 +286,8 @@ public class CherryPickChange {
try {
baseObjectId = ObjectId.fromString(base);
} catch (InvalidObjectIdException e) {
throw new BadRequestException(String.format("Base %s doesn't represent a valid SHA-1", base));
throw new BadRequestException(
String.format("Base %s doesn't represent a valid SHA-1", base), e);
}
RevCommit baseCommit;

View File

@@ -254,7 +254,7 @@ public class CreateChange
try {
permissionBackend.currentUser().project(project).ref(refName).check(RefPermission.READ);
} catch (AuthException e) {
throw new ResourceNotFoundException(String.format("ref %s not found", refName));
throw new ResourceNotFoundException(String.format("ref %s not found", refName), e);
}
permissionBackend
@@ -332,7 +332,7 @@ public class CreateChange
try {
permissionBackend.currentUser().change(change).check(ChangePermission.READ);
} catch (AuthException e) {
throw new UnprocessableEntityException("Read not permitted for " + baseChange);
throw new UnprocessableEntityException("Read not permitted for " + baseChange, e);
}
return change;
@@ -360,14 +360,15 @@ public class CreateChange
parentCommit = ObjectId.fromString(baseCommit);
} catch (InvalidObjectIdException e) {
throw new UnprocessableEntityException(
String.format("Base %s doesn't represent a valid SHA-1", baseCommit));
String.format("Base %s doesn't represent a valid SHA-1", baseCommit), e);
}
RevCommit parentRevCommit;
try {
parentRevCommit = revWalk.parseCommit(parentCommit);
} catch (MissingObjectException e) {
throw new UnprocessableEntityException(String.format("Base %s doesn't exist", baseCommit));
throw new UnprocessableEntityException(
String.format("Base %s doesn't exist", baseCommit), e);
}
if (destRef == null) {

View File

@@ -207,7 +207,7 @@ public class CreateMergePatchSet
try {
permissionBackend.currentUser().change(change).check(ChangePermission.READ);
} catch (AuthException e) {
throw new UnprocessableEntityException("Read not permitted for " + baseChange);
throw new UnprocessableEntityException("Read not permitted for " + baseChange, e);
}
return psUtil.current(change);
}

View File

@@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.common.data.PatchScript;
import com.google.gerrit.common.data.PatchScript.DisplayMethod;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
@@ -73,6 +74,8 @@ import org.kohsuke.args4j.spi.Parameters;
import org.kohsuke.args4j.spi.Setter;
public class GetDiff implements RestReadView<FileResource> {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final ImmutableMap<Patch.ChangeType, ChangeType> CHANGE_TYPE =
Maps.immutableEnumMap(
new ImmutableMap.Builder<Patch.ChangeType, ChangeType>()
@@ -433,6 +436,7 @@ public class GetDiff implements RestReadView<FileResource> {
throw new NumberFormatException();
}
} catch (NumberFormatException e) {
logger.atFine().withCause(e).log("invalid numeric value");
throw new CmdLineException(
owner,
localizable("\"%s\" is not a valid value for \"%s\""),

View File

@@ -469,7 +469,8 @@ public class PostReview
throw new AuthException(
String.format(
"not permitted to modify label \"%s\" on behalf of \"%s\"",
type.getName(), in.onBehalfOf));
type.getName(), in.onBehalfOf),
e);
}
}
}
@@ -483,7 +484,7 @@ public class PostReview
permissionBackend.user(reviewer).change(rev.getNotes()).check(ChangePermission.READ);
} catch (AuthException e) {
throw new UnprocessableEntityException(
String.format("on_behalf_of account %s cannot see change", reviewer.getAccountId()));
String.format("on_behalf_of account %s cannot see change", reviewer.getAccountId()), e);
}
return new RevisionResource(
@@ -526,7 +527,7 @@ public class PostReview
perm.check(new LabelPermission.WithValue(lt, val));
} catch (AuthException e) {
throw new AuthException(
String.format("Applying label \"%s\": %d is restricted", lt.getName(), val));
String.format("Applying label \"%s\": %d is restricted", lt.getName(), val), e);
}
}
}

View File

@@ -173,7 +173,7 @@ public class PreviewSubmit implements RestReadView<RevisionResource> {
archiveFormat.putEntry(aos, path, bos.toByteArray());
}
} catch (LimitExceededException e) {
throw new NotImplementedException("The bundle is too big to generate at the server");
throw new NotImplementedException("The bundle is too big to generate at the server", e);
} catch (NoSuchProjectException e) {
throw new IOException(e);
}

View File

@@ -89,7 +89,7 @@ public class PutAssignee extends RetryingRestModifyView<ChangeResource, Assignee
.change(rsrc.getNotes())
.check(ChangePermission.READ);
} catch (AuthException e) {
throw new AuthException("read not permitted for " + input.assignee);
throw new AuthException("read not permitted for " + input.assignee, e);
}
try (BatchUpdate bu =

View File

@@ -119,7 +119,7 @@ public class QueryChanges implements RestReadView<TopLevelResource>, DynamicOpti
try {
out = query();
} catch (QueryRequiresAuthException e) {
throw new AuthException("Must be signed-in to use this operator");
throw new AuthException("Must be signed-in to use this operator", e);
} catch (QueryParseException e) {
logger.atFine().withCause(e).log("Reject change query with 400 Bad Request: %s", queries);
throw new BadRequestException(e.getMessage(), e);

View File

@@ -214,7 +214,7 @@ public class Submit
try {
change = changeNotesFactory.createChecked(change.getProject(), change.getId()).getChange();
} catch (NoSuchChangeException e) {
throw new ResourceConflictException("change is deleted");
throw new ResourceConflictException("change is deleted", e);
}
if (change.isMerged()) {
@@ -448,7 +448,7 @@ public class Submit
permissionBackend.user(submitter).change(rsrc.getNotes()).check(ChangePermission.READ);
} catch (AuthException e) {
throw new UnprocessableEntityException(
String.format("on_behalf_of account %s cannot see change", submitter.getAccountId()));
String.format("on_behalf_of account %s cannot see change", submitter.getAccountId()), e);
}
return submitter;
}

View File

@@ -76,7 +76,7 @@ public class ConfirmEmail implements RestModifyView<ConfigResource, Input> {
}
throw new UnprocessableEntityException("invalid token");
} catch (EmailTokenVerifier.InvalidTokenException e) {
throw new UnprocessableEntityException("invalid token");
throw new UnprocessableEntityException("invalid token", e);
} catch (AccountException e) {
throw new UnprocessableEntityException(e.getMessage());
}

View File

@@ -81,7 +81,7 @@ public class TasksCollection implements ChildCollection<ConfigResource, TaskReso
try {
taskId = (int) Long.parseLong(id.get(), 16);
} catch (NumberFormatException e) {
throw new ResourceNotFoundException(id);
throw new ResourceNotFoundException(id, e);
}
Task<?> task = workQueue.getTask(taskId);

View File

@@ -137,7 +137,7 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
try {
addMembers(groupUuid, newMemberIds);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid));
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
}
return toAccountInfoList(newMemberIds);
}
@@ -233,7 +233,7 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
}
throw new IllegalStateException();
} catch (UnprocessableEntityException e) {
throw new ResourceNotFoundException(id);
throw new ResourceNotFoundException(id, e);
}
}
}

View File

@@ -116,7 +116,7 @@ public class AddSubgroups implements RestModifyView<GroupResource, Input> {
try {
addSubgroups(groupUuid, subgroupUuids);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid));
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
}
return result;
}
@@ -154,7 +154,7 @@ public class AddSubgroups implements RestModifyView<GroupResource, Input> {
}
throw new IllegalStateException();
} catch (UnprocessableEntityException e) {
throw new ResourceNotFoundException(id);
throw new ResourceNotFoundException(id, e);
}
}
}

View File

@@ -219,7 +219,7 @@ public class CreateGroup
return groupsUpdateProvider.get().createGroup(groupCreation, groupUpdateBuilder.build());
} catch (DuplicateKeyException e) {
throw new ResourceConflictException(
"group '" + createGroupArgs.getGroupName() + "' already exists");
"group '" + createGroupArgs.getGroupName() + "' already exists", e);
}
}
}

View File

@@ -74,7 +74,7 @@ public class DeleteMembers implements RestModifyView<GroupResource, Input> {
try {
removeGroupMembers(groupUuid, membersToRemove);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid));
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
}
return Response.none();

View File

@@ -77,7 +77,7 @@ public class DeleteSubgroups implements RestModifyView<GroupResource, Input> {
try {
removeSubgroups(groupUuid, subgroupsToRemove);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid));
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
}
return Response.none();

View File

@@ -46,7 +46,7 @@ public class GetOwner implements RestReadView<GroupResource> {
GroupControl c = controlFactory.validateFor(group.getOwnerGroupUUID());
return json.format(c.getGroup());
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException();
throw new ResourceNotFoundException(group.getOwnerGroupUUID().get(), e);
}
}
}

View File

@@ -66,7 +66,7 @@ public class PutDescription implements RestModifyView<GroupResource, Description
try {
groupsUpdateProvider.get().updateGroup(groupUuid, groupUpdate);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid));
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
}
}

View File

@@ -78,9 +78,9 @@ public class PutName implements RestModifyView<GroupResource, NameInput> {
try {
groupsUpdateProvider.get().updateGroup(groupUuid, groupUpdate);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid));
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
} catch (DuplicateKeyException e) {
throw new ResourceConflictException("group with name " + newName + " already exists");
throw new ResourceConflictException("group with name " + newName + " already exists", e);
}
}
}

View File

@@ -65,7 +65,7 @@ public class PutOptions implements RestModifyView<GroupResource, GroupOptionsInf
try {
groupsUpdateProvider.get().updateGroup(groupUuid, groupUpdate);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid));
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
}
}

View File

@@ -76,7 +76,7 @@ public class PutOwner implements RestModifyView<GroupResource, OwnerInput> {
try {
groupsUpdateProvider.get().updateGroup(groupUuid, groupUpdate);
} catch (NoSuchGroupException e) {
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid));
throw new ResourceNotFoundException(String.format("Group %s not found", groupUuid), e);
}
}
return json.format(owner);

View File

@@ -82,9 +82,9 @@ public class BranchesCollection implements ChildCollection<ProjectResource, Bran
.check(RefPermission.READ);
return new BranchResource(parent.getProjectState(), parent.getUser(), ref);
} catch (AuthException notAllowed) {
throw new ResourceNotFoundException(id);
throw new ResourceNotFoundException(id, notAllowed);
} catch (RepositoryNotFoundException noRepo) {
throw new ResourceNotFoundException();
throw new ResourceNotFoundException(id, noRepo);
}
}

View File

@@ -80,7 +80,7 @@ public class CommitsCollection implements ChildCollection<ProjectResource, Commi
try {
objectId = ObjectId.fromString(id.get());
} catch (IllegalArgumentException e) {
throw new ResourceNotFoundException(id);
throw new ResourceNotFoundException(id, e);
}
try (Repository repo = repoManager.openRepository(parent.getNameKey());
@@ -95,7 +95,7 @@ public class CommitsCollection implements ChildCollection<ProjectResource, Commi
}
return new CommitResource(parent, commit);
} catch (MissingObjectException | IncorrectObjectTypeException e) {
throw new ResourceNotFoundException(id);
throw new ResourceNotFoundException(id, e);
}
}

View File

@@ -102,7 +102,7 @@ public class CreateAccessChange implements RestModifyView<ProjectResource, Proje
try {
forProject.ref(RefNames.REFS_CONFIG).check(RefPermission.CREATE_CHANGE);
} catch (AuthException denied) {
throw new AuthException("cannot create change for " + RefNames.REFS_CONFIG);
throw new AuthException("cannot create change for " + RefNames.REFS_CONFIG, denied);
}
}
projectCache.checkedGet(rsrc.getNameKey()).checkStatePermitsWrite();

View File

@@ -125,7 +125,7 @@ public class CreateBranch
try {
object = rw.parseCommit(object);
} catch (IncorrectObjectTypeException notCommit) {
throw new BadRequestException("\"" + input.revision + "\" not a commit");
throw new BadRequestException("\"" + input.revision + "\" not a commit", notCommit);
}
}
@@ -198,7 +198,7 @@ public class CreateBranch
throw err;
}
} catch (RefUtil.InvalidRevisionException e) {
throw new BadRequestException("invalid revision \"" + input.revision + "\"");
throw new BadRequestException("invalid revision \"" + input.revision + "\"", e);
}
}
}

View File

@@ -147,7 +147,7 @@ public class CreateTag implements RestCollectionCreateView<ProjectResource, TagR
}
}
} catch (InvalidRevisionException e) {
throw new BadRequestException("Invalid base revision");
throw new BadRequestException("Invalid base revision", e);
} catch (GitAPIException e) {
logger.atSevere().withCause(e).log("Cannot create tag \"%s\"", ref);
throw new IOException(e);

View File

@@ -103,14 +103,14 @@ public class DashboardsCollection implements ChildCollection<ProjectResource, Da
try {
info = newDashboardInfo(id.get());
} catch (InvalidDashboardId e) {
throw new ResourceNotFoundException(id);
throw new ResourceNotFoundException(id, e);
}
for (ProjectState ps : parent.getProjectState().tree()) {
try {
return parse(ps, parent.getProjectState(), parent.getUser(), info);
} catch (AmbiguousObjectException | ConfigInvalidException | IncorrectObjectTypeException e) {
throw new ResourceNotFoundException(id);
throw new ResourceNotFoundException(id, e);
} catch (ResourceNotFoundException e) {
continue;
}
@@ -135,7 +135,7 @@ public class DashboardsCollection implements ChildCollection<ProjectResource, Da
permissionBackend.user(user).project(parent.getNameKey()).ref(ref).check(RefPermission.READ);
} catch (AuthException e) {
// Don't leak the project's existence
throw new ResourceNotFoundException(info.id);
throw new ResourceNotFoundException(info.id, e);
}
if (!Repository.isValidRefName(ref)) {
throw new ResourceNotFoundException(info.id);
@@ -151,7 +151,7 @@ public class DashboardsCollection implements ChildCollection<ProjectResource, Da
BlobBasedConfig cfg = new BlobBasedConfig(null, git, objId);
return new DashboardResource(current, user, ref, info.path, cfg, false);
} catch (RepositoryNotFoundException e) {
throw new ResourceNotFoundException(info.id);
throw new ResourceNotFoundException(info.id, e);
}
}

View File

@@ -166,7 +166,7 @@ public class GetAccess implements RestReadView<ProjectResource> {
} catch (ConfigInvalidException e) {
throw new ResourceConflictException(e.getMessage());
} catch (RepositoryNotFoundException e) {
throw new ResourceNotFoundException(rsrc.getName());
throw new ResourceNotFoundException(rsrc.getName(), e);
}
// The following implementation must match the ProjectAccessFactory JSON RPC endpoint.

View File

@@ -81,13 +81,13 @@ public class GetHead implements RestReadView<ProjectResource> {
.project(rsrc.getNameKey())
.check(ProjectPermission.WRITE_CONFIG);
} catch (AuthException ae) {
throw new AuthException("not allowed to see HEAD");
throw new AuthException("not allowed to see HEAD", ae);
}
}
}
throw new ResourceNotFoundException(Constants.HEAD);
} catch (RepositoryNotFoundException e) {
throw new ResourceNotFoundException(rsrc.getName());
throw new ResourceNotFoundException(rsrc.getName(), e);
}
}
}

View File

@@ -103,7 +103,7 @@ public class GetReflog implements RestReadView<BranchResource> {
} catch (UnsupportedOperationException e) {
String msg = "reflog not supported on repo " + rsrc.getNameKey().get();
logger.atSevere().log(msg);
throw new MethodNotAllowedException(msg);
throw new MethodNotAllowedException(msg, e);
}
if (r == null) {
throw new ResourceNotFoundException(rsrc.getRef());

View File

@@ -50,7 +50,7 @@ public class GetStatistics implements RestReadView<ProjectResource> {
} catch (GitAPIException | JGitInternalException e) {
throw new ResourceConflictException(e.getMessage());
} catch (IOException e) {
throw new ResourceNotFoundException(rsrc.getName());
throw new ResourceNotFoundException(rsrc.getName(), e);
}
}
}

View File

@@ -147,7 +147,7 @@ public class ListBranches implements RestReadView<ProjectResource> {
}
return toBranchInfo(rsrc, ImmutableList.of(r)).get(0);
} catch (RepositoryNotFoundException noRepo) {
throw new ResourceNotFoundException();
throw new ResourceNotFoundException(rsrc.getNameKey().get(), noRepo);
}
}
@@ -163,7 +163,7 @@ public class ListBranches implements RestReadView<ProjectResource> {
.exactRef(Constants.HEAD, RefNames.REFS_CONFIG, RefNames.REFS_USERS_DEFAULT)
.values());
} catch (RepositoryNotFoundException noGitRepository) {
throw new ResourceNotFoundException();
throw new ResourceNotFoundException(rsrc.getNameKey().get(), noGitRepository);
}
return toBranchInfo(rsrc, refs);
}

View File

@@ -119,7 +119,7 @@ public class ListDashboards implements RestReadView<ProjectResource> {
}
return all;
} catch (RepositoryNotFoundException e) {
throw new ResourceNotFoundException();
throw new ResourceNotFoundException(project, e);
}
}

View File

@@ -217,7 +217,7 @@ public class ListTags implements RestReadView<ProjectResource> {
try {
return repoManager.openRepository(project);
} catch (RepositoryNotFoundException noGitRepository) {
throw new ResourceNotFoundException();
throw new ResourceNotFoundException(project.get(), noGitRepository);
}
}

View File

@@ -178,7 +178,7 @@ public class PutConfig implements RestModifyView<ProjectResource, ConfigInput> {
uiActions,
views);
} catch (RepositoryNotFoundException notFound) {
throw new ResourceNotFoundException(projectName.get());
throw new ResourceNotFoundException(projectName.get(), notFound);
} catch (ConfigInvalidException err) {
throw new ResourceConflictException("Cannot read project " + projectName, err);
} catch (IOException err) {

View File

@@ -92,7 +92,7 @@ public class PutDescription implements RestModifyView<ProjectResource, Descripti
? Response.none()
: Response.ok(project.getDescription());
} catch (RepositoryNotFoundException notFound) {
throw new ResourceNotFoundException(resource.getName());
throw new ResourceNotFoundException(resource.getName(), notFound);
} catch (ConfigInvalidException e) {
throw new ResourceConflictException(
String.format("invalid project.config: %s", e.getMessage()));

View File

@@ -135,7 +135,7 @@ public class SetAccess implements RestModifyView<ProjectResource, ProjectAccessI
} catch (InvalidNameException e) {
throw new BadRequestException(e.toString());
} catch (ConfigInvalidException e) {
throw new ResourceConflictException(rsrc.getName());
throw new ResourceConflictException(rsrc.getName(), e);
}
return getAccess.apply(rsrc.getNameKey());

View File

@@ -89,7 +89,7 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, SetDashbo
new ProjectResource(rsrc.getProjectState(), rsrc.getUser()),
IdString.fromUrl(input.id));
} catch (ResourceNotFoundException e) {
throw new BadRequestException("dashboard " + input.id + " not found");
throw new BadRequestException("dashboard " + input.id + " not found", e);
} catch (ConfigInvalidException e) {
throw new ResourceConflictException(e.getMessage());
}
@@ -125,7 +125,7 @@ class SetDefaultDashboard implements RestModifyView<DashboardResource, SetDashbo
}
return Response.none();
} catch (RepositoryNotFoundException notFound) {
throw new ResourceNotFoundException(rsrc.getProjectState().getProject().getName());
throw new ResourceNotFoundException(rsrc.getProjectState().getProject().getName(), notFound);
} catch (ConfigInvalidException e) {
throw new ResourceConflictException(
String.format("invalid project.config: %s", e.getMessage()));

View File

@@ -111,7 +111,7 @@ public class SetHead implements RestModifyView<ProjectResource, HeadInput> {
}
return ref;
} catch (RepositoryNotFoundException e) {
throw new ResourceNotFoundException(rsrc.getName());
throw new ResourceNotFoundException(rsrc.getName(), e);
}
}

View File

@@ -120,7 +120,7 @@ public class SetParent
requireNonNull(parent);
return parent.get();
} catch (RepositoryNotFoundException notFound) {
throw new ResourceNotFoundException(rsrc.getName());
throw new ResourceNotFoundException(rsrc.getName(), notFound);
} catch (ConfigInvalidException e) {
throw new ResourceConflictException(
String.format("invalid project.config: %s", e.getMessage()));

View File

@@ -58,7 +58,8 @@ public final class StoredValues {
try {
return cd.change();
} catch (StorageException e) {
throw new SystemException("Cannot load change " + cd.getId());
throw new SystemException(
String.format("Cannot load change %s: %s", cd.getId(), e.getMessage()));
}
}
@@ -103,7 +104,7 @@ public final class StoredValues {
try {
patchList = plCache.get(plKey, project);
} catch (PatchListNotAvailableException e) {
throw new SystemException("Cannot create " + plKey);
throw new SystemException(String.format("Cannot create %s: %s", plKey, e.getMessage()));
}
return patchList;
}

View File

@@ -104,7 +104,7 @@ public class NoteDbSchemaUpdater {
try {
schemaCreator.ensureCreated();
} catch (IOException | ConfigInvalidException e) {
throw new StorageException("Cannot initialize Gerrit site");
throw new StorageException("Cannot initialize Gerrit site", e);
}
}

View File

@@ -161,7 +161,8 @@ public class RebaseSubmitStrategy extends SubmitStrategy {
} catch (MergeConflictException mce) {
// Unlike in Cherry-pick case, this should never happen.
toMerge.setStatusCode(CommitMergeStatus.REBASE_MERGE_CONFLICT);
throw new IllegalStateException("MergeConflictException on message edit must not happen");
throw new IllegalStateException(
"MergeConflictException on message edit must not happen", mce);
} catch (MergeIdenticalTreeException mie) {
// this should not happen
toMerge.setStatusCode(SKIPPED_IDENTICAL_TREE);

View File

@@ -549,7 +549,7 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
return args.submoduleOp.composeGitlinksCommit(args.destBranch, commit);
} catch (SubmoduleException | IOException e) {
throw new IntegrationException(
"cannot update gitlink for the commit at branch: " + args.destBranch);
"cannot update gitlink for the commit at branch: " + args.destBranch, e);
}
}
}

View File

@@ -96,7 +96,7 @@ public final class SocketUtil {
try {
port = Integer.parseInt(portStr);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("invalid port: " + desc);
throw new IllegalArgumentException("invalid port: " + desc, e);
}
} else {
port = defaultPort;

View File

@@ -385,6 +385,10 @@ public abstract class BaseCommand implements Command {
return new UnloggedFailure(1, "fatal: " + msg);
}
protected UnloggedFailure die(String msg, Throwable why) {
return new UnloggedFailure(1, "fatal: " + msg, why);
}
protected UnloggedFailure die(Throwable why) {
return new UnloggedFailure(1, "fatal: " + why.getMessage(), why);
}

View File

@@ -111,7 +111,7 @@ public class ChangeArgumentParser {
try {
changeResource = changesCollection.parse(cId);
} catch (RestApiException e) {
throw new UnloggedFailure(1, "\"" + id + "\" no such change");
throw new UnloggedFailure(1, "\"" + id + "\" no such change", e);
}
changes.put(cId, changeResource);
}

View File

@@ -34,11 +34,10 @@ public class SshKeyCreatorImpl implements SshKeyCreator {
SshUtil.parse(key);
return key;
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
throw new InvalidSshKeyException();
throw new InvalidSshKeyException(e);
} catch (NoSuchProviderException e) {
logger.atSevere().withCause(e).log("Cannot parse SSH key");
throw new InvalidSshKeyException();
throw new InvalidSshKeyException(e);
}
}
}

View File

@@ -126,9 +126,9 @@ public final class SuExec extends BaseCommand {
try {
permissionBackend.user(caller).check(GlobalPermission.RUN_AS);
} catch (AuthException e) {
throw die("suexec not permitted");
throw die("suexec not permitted", e);
} catch (PermissionBackendException e) {
throw die("suexec not available: " + e);
throw die("suexec not available", e);
}
}
}

View File

@@ -104,9 +104,9 @@ public class LsUserRefs extends SshCommand {
throw new Failure(1, "fatal: Error reading refs: '" + projectName, e);
}
} catch (RepositoryNotFoundException e) {
throw die("'" + projectName + "': not a git archive");
throw die("'" + projectName + "': not a git archive", e);
} catch (IOException e) {
throw die("Error opening: '" + projectName);
throw die("Error opening: '" + projectName, e);
}
}
}

View File

@@ -99,7 +99,7 @@ public class PatchSetParser {
try {
patchSetId = PatchSet.Id.parse(token);
} catch (IllegalArgumentException e) {
throw error("\"" + token + "\" is not a valid patch set");
throw error("\"" + token + "\" is not a valid patch set", e);
}
ChangeNotes notes = getNotes(projectState, patchSetId.getParentKey());
PatchSet patchSet = psUtil.get(notes, patchSetId);
@@ -130,7 +130,7 @@ public class PatchSetParser {
ChangeNotes notes = changeFinder.findOne(changeId);
return notesFactory.create(notes.getProjectName(), changeId);
} catch (NoSuchChangeException e) {
throw error("\"" + changeId + "\" no such change");
throw error("\"" + changeId + "\" no such change", e);
}
}
@@ -153,4 +153,8 @@ public class PatchSetParser {
public static UnloggedFailure error(String msg) {
return new UnloggedFailure(1, msg);
}
public static UnloggedFailure error(String msg, Throwable why) {
return new UnloggedFailure(1, msg, why);
}
}

View File

@@ -70,21 +70,21 @@ final class PluginInstallCommand extends PluginAdminSshCommand {
try {
data = Files.newInputStream(new File(source).toPath());
} catch (IOException e) {
throw die("cannot read " + source);
throw die("cannot read " + source, e);
}
} else {
try {
data = new URL(source).openStream();
} catch (MalformedURLException e) {
throw die("invalid url " + source);
throw die("invalid url " + source, e);
} catch (IOException e) {
throw die("cannot read " + source);
throw die("cannot read " + source, e);
}
}
try {
loader.installPluginFromStream(name, data);
} catch (IOException e) {
throw die("cannot install plugin");
throw die("cannot install plugin", e);
} catch (PluginInstallException e) {
e.printStackTrace(stderr);
String msg = String.format("Plugin failed to install. Cause: %s", e.getMessage());

View File

@@ -83,7 +83,7 @@ final class Receive extends AbstractGitCommand {
.project(project.getNameKey())
.check(ProjectPermission.RUN_RECEIVE_PACK);
} catch (AuthException e) {
throw new Failure(1, "fatal: receive-pack not permitted on this server");
throw new Failure(1, "fatal: receive-pack not permitted on this server", e);
} catch (PermissionBackendException e) {
throw new Failure(1, "fatal: unable to check permissions " + e);
}

View File

@@ -326,7 +326,7 @@ public class ReviewCommand extends SshCommand {
try {
allProjectsState = projectCache.checkedGet(allProjects);
} catch (IOException e) {
throw die("missing " + allProjects.get());
throw die("missing " + allProjects.get(), e);
}
for (LabelType type : allProjectsState.getLabelTypes().getLabelTypes()) {

View File

@@ -55,9 +55,9 @@ final class Upload extends AbstractGitCommand {
perm.check(ProjectPermission.RUN_UPLOAD_PACK);
} catch (AuthException e) {
throw new Failure(1, "fatal: upload-pack not permitted on this server");
throw new Failure(1, "fatal: upload-pack not permitted on this server", e);
} catch (PermissionBackendException e) {
throw new Failure(1, "fatal: unable to check permissions " + e);
throw new Failure(1, "fatal: unable to check permissions ", e);
}
final UploadPack up = new UploadPack(repo);

View File

@@ -100,7 +100,7 @@ public class StandardKeyEncoder extends Encoder {
}
}
} catch (ArrayIndexOutOfBoundsException err) {
throw new IllegalArgumentException("Bad encoding: " + e);
throw new IllegalArgumentException("Bad encoding" + e, err);
}
try {
return new String(b, 0, bPtr, "UTF-8");

View File

@@ -83,6 +83,7 @@ java_package_configuration(
"-Xep:TypeParameterUnusedInFormals:WARN",
"-Xep:URLEqualsHashCode:WARN",
"-Xep:UnsynchronizedOverridesSynchronized:WARN",
"-Xep:UnusedException:ERROR",
"-Xep:WaitNotInLoop:WARN",
],
packages = ["error_prone_packages"],