Prefer requireNonNull from Java API over Guava's checkNotNull

Most replacements are a trivial one-to-one replacement of the call to
checkNotNull with requireNonNull, however there are some calls that
make use of checkNotNull's variable argument list and formatting
parameters. Replace these with String.format wrapped in a supplier.

Using the Java API rather than Guava means we can get rid of the
custom implementation, and Edwin's TODO, in AccessSection.

Change-Id: I1d4a6b342e3544abdbba4f05ac4308d223b6768b
This commit is contained in:
David Pursehouse 2018-10-16 11:17:28 +09:00
parent d01e5b2312
commit e1e0ae5157
142 changed files with 487 additions and 472 deletions

View File

@ -14,7 +14,7 @@
package com.google.gerrit.acceptance;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@ -144,7 +144,8 @@ public class AccountCreator {
}
public TestAccount get(String username) {
return checkNotNull(accounts.get(username), "No TestAccount created for %s", username);
return requireNonNull(
accounts.get(username), () -> String.format("No TestAccount created for %s ", username));
}
public void evict(Collection<Account.Id> ids) {

View File

@ -15,8 +15,8 @@
package com.google.gerrit.acceptance;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import static org.apache.log4j.Logger.getLogger;
import com.google.auto.value.AutoValue;
@ -411,7 +411,7 @@ public class GerritServer implements AutoCloseable {
CyclicBarrier serverStarted,
String[] additionalArgs)
throws Exception {
checkNotNull(site);
requireNonNull(site);
ExecutorService daemonService = Executors.newSingleThreadExecutor();
String[] args =
Stream.concat(
@ -535,10 +535,10 @@ public class GerritServer implements AutoCloseable {
Injector testInjector,
Daemon daemon,
@Nullable ExecutorService daemonService) {
this.desc = checkNotNull(desc);
this.desc = requireNonNull(desc);
this.sitePath = sitePath;
this.testInjector = checkNotNull(testInjector);
this.daemon = checkNotNull(daemon);
this.testInjector = requireNonNull(testInjector);
this.daemon = requireNonNull(daemon);
this.daemonService = daemonService;
Config cfg = testInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));

View File

@ -16,8 +16,8 @@ package com.google.gerrit.acceptance;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.io.InputStreamReader;
@ -72,13 +72,13 @@ public class HttpResponse {
}
public boolean hasContent() {
Preconditions.checkNotNull(response, "Response is not initialized.");
requireNonNull(response, "Response is not initialized.");
return response.getEntity() != null;
}
public String getEntityContent() throws IOException {
Preconditions.checkNotNull(response, "Response is not initialized.");
Preconditions.checkNotNull(response.getEntity(), "Response.Entity is not initialized.");
requireNonNull(response, "Response is not initialized.");
requireNonNull(response.getEntity(), "Response.Entity is not initialized.");
ByteBuffer buf = IO.readWholeStream(response.getEntity().getContent(), 1024);
return RawParseUtils.decode(buf.array(), buf.arrayOffset(), buf.limit()).trim();
}

View File

@ -15,8 +15,8 @@
package com.google.gerrit.acceptance;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Preconditions;
import com.google.common.net.HttpHeaders;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.restapi.RawInput;
@ -81,7 +81,7 @@ public class RestSession extends HttpSession {
}
public RestResponse putRaw(String endPoint, RawInput stream) throws IOException {
Preconditions.checkNotNull(stream);
requireNonNull(stream);
Request put = Request.Put(getUrl(endPoint));
put.addHeader(new BasicHeader("Content-Type", stream.getContentType()));
put.body(

View File

@ -15,6 +15,7 @@
package com.google.gerrit.common;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.base.Preconditions;
@ -31,7 +32,7 @@ public class RawInputUtil {
}
public static RawInput create(byte[] bytes, String contentType) {
Preconditions.checkNotNull(bytes);
requireNonNull(bytes);
Preconditions.checkArgument(bytes.length > 0);
return new RawInput() {
@Override

View File

@ -14,6 +14,8 @@
package com.google.gerrit.common.data;
import static java.util.Objects.requireNonNull;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.reviewdb.client.Project;
import java.util.ArrayList;
@ -43,7 +45,7 @@ public class AccessSection extends RefConfigSection implements Comparable<Access
}
public void setPermissions(List<Permission> list) {
checkNotNull(list);
requireNonNull(list);
Set<String> names = new HashSet<>();
for (Permission p : list) {
@ -62,7 +64,7 @@ public class AccessSection extends RefConfigSection implements Comparable<Access
@Nullable
public Permission getPermission(String name, boolean create) {
checkNotNull(name);
requireNonNull(name);
if (permissions != null) {
for (Permission p : permissions) {
@ -86,7 +88,7 @@ public class AccessSection extends RefConfigSection implements Comparable<Access
}
public void addPermission(Permission permission) {
checkNotNull(permission);
requireNonNull(permission);
if (permissions == null) {
permissions = new ArrayList<>();
@ -102,12 +104,12 @@ public class AccessSection extends RefConfigSection implements Comparable<Access
}
public void remove(Permission permission) {
checkNotNull(permission);
requireNonNull(permission);
removePermission(permission.getName());
}
public void removePermission(String name) {
checkNotNull(name);
requireNonNull(name);
if (permissions != null) {
permissions.removeIf(permission -> name.equalsIgnoreCase(permission.getName()));
@ -115,7 +117,7 @@ public class AccessSection extends RefConfigSection implements Comparable<Access
}
public void mergeFrom(AccessSection section) {
checkNotNull(section);
requireNonNull(section);
for (Permission src : section.getPermissions()) {
Permission dst = getPermission(src.getName());
@ -127,13 +129,6 @@ public class AccessSection extends RefConfigSection implements Comparable<Access
}
}
// TODO(ekempin): Once the GWT UI is gone use com.google.common.base.Preconditions.checkNotNull
private static void checkNotNull(Object reference) {
if (reference == null) {
throw new NullPointerException();
}
}
@Override
public int compareTo(AccessSection o) {
return comparePattern().compareTo(o.comparePattern());

View File

@ -14,13 +14,13 @@
package com.google.gerrit.elasticsearch;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.APPROVAL_CODEC;
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.CHANGE_CODEC;
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.PATCH_SET_CODEC;
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.CLOSED_STATUSES;
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.OPEN_STATUSES;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static org.apache.commons.codec.binary.Base64.decodeBase64;
import com.google.common.collect.FluentIterable;
@ -218,7 +218,7 @@ class ElasticChangeIndex extends AbstractElasticIndex<Change.Id, ChangeData>
if (c == null) {
int id = source.get(ChangeField.LEGACY_ID.getName()).getAsInt();
// IndexUtils#changeFields ensures either CHANGE or PROJECT is always present.
String projectName = checkNotNull(source.get(ChangeField.PROJECT.getName()).getAsString());
String projectName = requireNonNull(source.get(ChangeField.PROJECT.getName()).getAsString());
return changeDataFactory.create(
db.get(), new Project.NameKey(projectName), new Change.Id(id));
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.extensions.api.access;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import java.util.Objects;
@ -29,8 +29,8 @@ public class PluginPermission implements GlobalOrPluginPermission {
}
public PluginPermission(String pluginName, String capability, boolean fallBackToAdmin) {
this.pluginName = checkNotNull(pluginName, "pluginName");
this.capability = checkNotNull(capability, "capability");
this.pluginName = requireNonNull(pluginName, "pluginName");
this.capability = requireNonNull(capability, "capability");
this.fallBackToAdmin = fallBackToAdmin;
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.extensions.auth.oauth;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.base.MoreObjects;
import com.google.common.base.Strings;
@ -55,9 +55,9 @@ public class OAuthToken implements Serializable {
public OAuthToken(
String token, String secret, String raw, long expiresAt, @Nullable String providerId) {
this.token = checkNotNull(token, "token");
this.secret = checkNotNull(secret, "secret");
this.raw = checkNotNull(raw, "raw");
this.token = requireNonNull(token, "token");
this.secret = requireNonNull(secret, "secret");
this.raw = requireNonNull(raw, "raw");
this.expiresAt = expiresAt;
this.providerId = Strings.emptyToNull(providerId);
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.extensions.registration;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.gerrit.extensions.annotations.Export;
import com.google.inject.Key;
@ -33,7 +33,7 @@ public class PrivateInternals_DynamicMapImpl<T> extends DynamicMap<T> {
* @return handle to remove the item at a later point in time.
*/
public RegistrationHandle put(String pluginName, String exportName, Provider<T> item) {
checkNotNull(item);
requireNonNull(item);
final NamePair key = new NamePair(pluginName, exportName);
items.put(key, item);
return new RegistrationHandle() {
@ -56,7 +56,7 @@ public class PrivateInternals_DynamicMapImpl<T> extends DynamicMap<T> {
* the collection.
*/
public ReloadableRegistrationHandle<T> put(String pluginName, Key<T> key, Provider<T> item) {
checkNotNull(item);
requireNonNull(item);
String exportName = ((Export) key.getAnnotation()).value();
NamePair np = new NamePair(pluginName, exportName);
items.put(np, item);

View File

@ -14,12 +14,12 @@
package com.google.gerrit.httpd.raw;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.net.HttpHeaders.CONTENT_ENCODING;
import static com.google.common.net.HttpHeaders.ETAG;
import static com.google.common.net.HttpHeaders.IF_MODIFIED_SINCE;
import static com.google.common.net.HttpHeaders.IF_NONE_MATCH;
import static com.google.common.net.HttpHeaders.LAST_MODIFIED;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
@ -111,7 +111,7 @@ public abstract class ResourceServlet extends HttpServlet {
boolean refresh,
boolean cacheOnClient,
int cacheFileSizeLimitBytes) {
this.cache = checkNotNull(cache, "cache");
this.cache = requireNonNull(cache, "cache");
this.refresh = refresh;
this.cacheOnClient = cacheOnClient;
this.cacheFileSizeLimitBytes = cacheFileSizeLimitBytes;
@ -308,9 +308,9 @@ public abstract class ResourceServlet extends HttpServlet {
final byte[] raw;
Resource(FileTime lastModified, String contentType, byte[] raw) {
this.lastModified = checkNotNull(lastModified, "lastModified");
this.contentType = checkNotNull(contentType, "contentType");
this.raw = checkNotNull(raw, "raw");
this.lastModified = requireNonNull(lastModified, "lastModified");
this.contentType = requireNonNull(contentType, "contentType");
this.raw = requireNonNull(raw, "raw");
this.etag = Hashing.murmur3_128().hashBytes(raw).toString();
}

View File

@ -16,7 +16,6 @@
package com.google.gerrit.httpd.restapi;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.flogger.LazyArgs.lazy;
import static com.google.common.net.HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS;
@ -33,6 +32,7 @@ import static com.google.common.net.HttpHeaders.VARY;
import static java.math.RoundingMode.CEILING;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
import static javax.servlet.http.HttpServletResponse.SC_ACCEPTED;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
@ -268,7 +268,7 @@ public class RestApiServlet extends HttpServlet {
Provider<? extends RestCollection<? extends RestResource, ? extends RestResource>> members) {
@SuppressWarnings("unchecked")
Provider<RestCollection<RestResource, RestResource>> n =
(Provider<RestCollection<RestResource, RestResource>>) checkNotNull((Object) members);
(Provider<RestCollection<RestResource, RestResource>>) requireNonNull((Object) members);
this.globals = globals;
this.members = n;
}

View File

@ -14,8 +14,8 @@
package com.google.gerrit.httpd.rpc.project;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.common.ProjectAccessUtil.mergeSections;
import static java.util.Objects.requireNonNull;
import com.google.common.base.MoreObjects;
import com.google.gerrit.common.data.AccessSection;
@ -235,7 +235,7 @@ public abstract class ProjectAccessHandler<T> extends Handler<T> {
/** Provide a local cache for {@code ProjectPermission.WRITE_CONFIG} capability. */
private boolean canWriteConfig() throws PermissionBackendException {
checkNotNull(user);
requireNonNull(user);
if (canWriteConfig != null) {
return canWriteConfig;

View File

@ -15,7 +15,7 @@
package com.google.gerrit.index;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.base.CharMatcher;
import com.google.gwtorm.server.OrmException;
@ -69,8 +69,8 @@ public final class FieldDef<I, T> {
private boolean stored;
public Builder(FieldType<T> type, String name) {
this.type = checkNotNull(type);
this.name = checkNotNull(name);
this.type = requireNonNull(type);
this.name = requireNonNull(name);
}
public Builder<T> stored() {
@ -99,10 +99,10 @@ public final class FieldDef<I, T> {
!(repeatable && type == FieldType.INTEGER_RANGE),
"Range queries against repeated fields are unsupported");
this.name = checkName(name);
this.type = checkNotNull(type);
this.type = requireNonNull(type);
this.stored = stored;
this.repeatable = repeatable;
this.getter = checkNotNull(getter);
this.getter = requireNonNull(getter);
}
private static String checkName(String name) {

View File

@ -15,7 +15,7 @@
package com.google.gerrit.index;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Iterables;
@ -34,7 +34,7 @@ public abstract class SchemaDefinitions<V> {
private final ImmutableSortedMap<Integer, Schema<V>> schemas;
protected SchemaDefinitions(String name, Class<V> valueClass) {
this.name = checkNotNull(name);
this.name = requireNonNull(name);
this.schemas = SchemaUtil.schemasFromClass(getClass(), valueClass);
}

View File

@ -14,8 +14,8 @@
package com.google.gerrit.index;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Stopwatch;
import com.google.common.flogger.FluentLogger;
@ -73,11 +73,11 @@ public abstract class SiteIndexer<K, V, I extends Index<K, V>> {
}
public void setProgressOut(OutputStream out) {
progressOut = checkNotNull(out);
progressOut = requireNonNull(out);
}
public void setVerboseOut(OutputStream out) {
verboseWriter = newPrintWriter(checkNotNull(out));
verboseWriter = newPrintWriter(requireNonNull(out));
}
public abstract Result indexAll(I index);

View File

@ -14,7 +14,7 @@
package com.google.gerrit.index.project;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.gerrit.index.IndexRewriter;
import com.google.gerrit.index.QueryOptions;
@ -36,7 +36,7 @@ public class ProjectIndexRewriter implements IndexRewriter<ProjectData> {
public Predicate<ProjectData> rewrite(Predicate<ProjectData> in, QueryOptions opts)
throws QueryParseException {
ProjectIndex index = indexes.getSearchIndex();
checkNotNull(index, "no active search index configured for projects");
requireNonNull(index, "no active search index configured for projects");
return new IndexedProjectQuery(index, in, opts);
}
}

View File

@ -14,7 +14,6 @@
package com.google.gerrit.lucene;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.lucene.AbstractLuceneIndex.sortFieldName;
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.APPROVAL_CODEC;
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.CHANGE_CODEC;
@ -24,6 +23,7 @@ import static com.google.gerrit.server.index.change.ChangeField.LEGACY_ID;
import static com.google.gerrit.server.index.change.ChangeField.PROJECT;
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.CLOSED_STATUSES;
import static com.google.gerrit.server.index.change.ChangeIndexRewriter.OPEN_STATUSES;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
import com.google.common.base.Function;
@ -281,7 +281,7 @@ public class LuceneChangeIndex implements ChangeIndex {
throws QueryParseException {
this.indexes = indexes;
this.predicate = predicate;
this.query = checkNotNull(queryBuilder.toQuery(predicate), "null query from Lucene");
this.query = requireNonNull(queryBuilder.toQuery(predicate), "null query from Lucene");
this.opts = opts;
this.sort = sort;
this.rawDocumentMapper = rawDocumentMapper;

View File

@ -14,9 +14,9 @@
package com.google.gerrit.pgm;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.server.schema.DataSourceProvider.Context.MULTI_USER;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
@ -500,7 +500,7 @@ public class Daemon extends SiteProgram {
}
private boolean migrateToNoteDb() {
return migrateToNoteDb || NoteDbMigrator.getAutoMigrate(checkNotNull(config));
return migrateToNoteDb || NoteDbMigrator.getAutoMigrate(requireNonNull(config));
}
private Module createIndexModule() {

View File

@ -14,9 +14,9 @@
package com.google.gerrit.pgm;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.server.schema.DataSourceProvider.Context.SINGLE_USER;
import static java.util.Objects.requireNonNull;
import com.google.auto.value.AutoValue;
import com.google.common.collect.Iterables;
@ -101,11 +101,9 @@ public class ProtobufImport extends SiteProgram {
Map.Entry<Integer, UnknownFieldSet.Field> e =
Iterables.getOnlyElement(msg.asMap().entrySet());
Relation rel =
checkNotNull(
requireNonNull(
relations.get(e.getKey()),
"unknown relation ID %s in message: %s",
e.getKey(),
msg);
String.format("unknown relation ID %s in message: %s", e.getKey(), msg));
List<ByteString> values = e.getValue().getLengthDelimitedList();
checkState(values.size() == 1, "expected one string field in message: %s", msg);
upsert(rel, values.get(0));

View File

@ -14,8 +14,8 @@
package com.google.gerrit.pgm;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.server.schema.DataSourceProvider.Context.MULTI_USER;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toSet;
import com.google.common.collect.Sets;
@ -132,7 +132,7 @@ public class Reindex extends SiteProgram {
return;
}
checkNotNull(indexDefs, "Called this method before injectMembers?");
requireNonNull(indexDefs, "Called this method before injectMembers?");
Set<String> valid = indexDefs.stream().map(IndexDefinition::getName).sorted().collect(toSet());
Set<String> invalid = Sets.difference(Sets.newHashSet(indices), valid);
if (invalid.isEmpty()) {
@ -192,7 +192,8 @@ public class Reindex extends SiteProgram {
private <K, V, I extends Index<K, V>> boolean reindex(IndexDefinition<K, V, I> def)
throws IOException {
I index = def.getIndexCollection().getSearchIndex();
checkNotNull(index, "no active search index configured for %s", def.getName());
requireNonNull(
index, () -> String.format("no active search index configured for %s", def.getName()));
index.markReady(false);
index.deleteAll();

View File

@ -14,7 +14,7 @@
package com.google.gerrit.reviewdb.server;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
@ -49,7 +49,7 @@ public class ReviewDbWrapper implements ReviewDb {
private boolean inTransaction;
protected ReviewDbWrapper(ReviewDb delegate) {
this.delegate = checkNotNull(delegate);
this.delegate = requireNonNull(delegate);
}
public ReviewDb unsafeGetDelegate() {
@ -161,7 +161,7 @@ public class ReviewDbWrapper implements ReviewDb {
protected final ChangeAccess delegate;
protected ChangeAccessWrapper(ChangeAccess delegate) {
this.delegate = checkNotNull(delegate);
this.delegate = requireNonNull(delegate);
}
@Override
@ -687,7 +687,7 @@ public class ReviewDbWrapper implements ReviewDb {
protected final AccountGroupAccess delegate;
protected AccountGroupAccessWrapper(AccountGroupAccess delegate) {
this.delegate = checkNotNull(delegate);
this.delegate = requireNonNull(delegate);
}
@Override
@ -783,7 +783,7 @@ public class ReviewDbWrapper implements ReviewDb {
protected final AccountGroupNameAccess delegate;
protected AccountGroupNameAccessWrapper(AccountGroupNameAccess delegate) {
this.delegate = checkNotNull(delegate);
this.delegate = requireNonNull(delegate);
}
@Override
@ -875,7 +875,7 @@ public class ReviewDbWrapper implements ReviewDb {
protected final AccountGroupMemberAccess delegate;
protected AccountGroupMemberAccessWrapper(AccountGroupMemberAccess delegate) {
this.delegate = checkNotNull(delegate);
this.delegate = requireNonNull(delegate);
}
@Override
@ -973,7 +973,7 @@ public class ReviewDbWrapper implements ReviewDb {
protected final AccountGroupMemberAuditAccess delegate;
protected AccountGroupMemberAuditAccessWrapper(AccountGroupMemberAuditAccess delegate) {
this.delegate = checkNotNull(delegate);
this.delegate = requireNonNull(delegate);
}
@Override
@ -1073,7 +1073,7 @@ public class ReviewDbWrapper implements ReviewDb {
protected final AccountGroupByIdAccess delegate;
protected AccountGroupByIdAccessWrapper(AccountGroupByIdAccess delegate) {
this.delegate = checkNotNull(delegate);
this.delegate = requireNonNull(delegate);
}
@Override
@ -1175,7 +1175,7 @@ public class ReviewDbWrapper implements ReviewDb {
protected final AccountGroupByIdAudAccess delegate;
protected AccountGroupByIdAudAccessWrapper(AccountGroupByIdAudAccess delegate) {
this.delegate = checkNotNull(delegate);
this.delegate = requireNonNull(delegate);
}
@Override

View File

@ -15,7 +15,7 @@
package com.google.gerrit.server;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.ListMultimap;
@ -152,12 +152,12 @@ public class ApprovalCopier {
@Nullable Config repoConfig,
Iterable<PatchSetApproval> dontCopy)
throws OrmException {
checkNotNull(ps, "ps should not be null");
requireNonNull(ps, "ps should not be null");
ChangeData cd = changeDataFactory.create(db, notes);
try {
ProjectState project = projectCache.checkedGet(cd.change().getDest().getParentKey());
ListMultimap<PatchSet.Id, PatchSetApproval> all = cd.approvals();
checkNotNull(all, "all should not be null");
requireNonNull(all, "all should not be null");
Table<String, Account.Id, PatchSetApproval> wontCopy = HashBasedTable.create();
for (PatchSetApproval psa : dontCopy) {

View File

@ -14,9 +14,9 @@
package com.google.gerrit.server;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.reviewdb.server.ReviewDbUtil.unwrapDb;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.VisibleForTesting;
import com.google.gerrit.common.Nullable;
@ -82,7 +82,7 @@ public class ChangeMessagesUtil {
public static ChangeMessage newMessage(
PatchSet.Id psId, CurrentUser user, Timestamp when, String body, @Nullable String tag) {
checkNotNull(psId);
requireNonNull(psId);
Account.Id accountId = user.isInternalUser() ? null : user.getAccountId();
ChangeMessage m =
new ChangeMessage(

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
import com.google.common.collect.Sets;
@ -77,9 +77,11 @@ public class CreateGroupPermissionSyncer implements ChangeMergedListener {
*/
public void syncIfNeeded() throws IOException, ConfigInvalidException {
ProjectState allProjectsState = projectCache.checkedGet(allProjects);
checkNotNull(allProjectsState, "Can't obtain project state for " + allProjects);
requireNonNull(
allProjectsState, () -> String.format("Can't obtain project state for %s", allProjects));
ProjectState allUsersState = projectCache.checkedGet(allUsers);
checkNotNull(allUsersState, "Can't obtain project state for " + allUsers);
requireNonNull(
allUsersState, () -> String.format("Can't obtain project state for %s", allUsers));
Set<PermissionRule> createGroupsGlobal =
new HashSet<>(allProjectsState.getCapabilityCollection().createGroup);

View File

@ -15,10 +15,10 @@
package com.google.gerrit.server;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static com.google.gerrit.server.ChangeUtil.PS_ID_ORDER;
import static com.google.gerrit.server.notedb.PatchSetState.PUBLISHED;
import static java.util.Objects.requireNonNull;
import static java.util.function.Function.identity;
import com.google.common.collect.ImmutableCollection;
@ -130,7 +130,7 @@ public class PatchSetUtil {
String pushCertificate,
String description)
throws OrmException, IOException {
checkNotNull(groups, "groups may not be null");
requireNonNull(groups, "groups may not be null");
ensurePatchSetMatches(psId, update);
PatchSet ps = new PatchSet(psId);
@ -197,7 +197,8 @@ public class PatchSetUtil {
}
ProjectState projectState = projectCache.checkedGet(notes.getProjectName());
checkNotNull(projectState, "Failed to load project %s", notes.getProjectName());
requireNonNull(
projectState, () -> String.format("Failed to load project %s", notes.getProjectName()));
ApprovalsUtil approvalsUtil = approvalsUtilProvider.get();
for (PatchSetApproval ap :

View File

@ -14,8 +14,8 @@
package com.google.gerrit.server;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toSet;
@ -117,7 +117,7 @@ public class StarredChangesUtil {
private static StarRef create(Ref ref, Iterable<String> labels) {
return new AutoValue_StarredChangesUtil_StarRef(
checkNotNull(ref), ImmutableSortedSet.copyOf(labels));
requireNonNull(ref), ImmutableSortedSet.copyOf(labels));
}
@Nullable

View File

@ -14,8 +14,8 @@
package com.google.gerrit.server.account;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
@ -90,9 +90,9 @@ public class AccountConfig extends VersionedMetaData implements ValidationError.
private List<ValidationError> validationErrors;
public AccountConfig(Account.Id accountId, AllUsersName allUsersName, Repository allUsersRepo) {
this.accountId = checkNotNull(accountId, "accountId");
this.allUsersName = checkNotNull(allUsersName, "allUsersName");
this.repo = checkNotNull(allUsersRepo, "allUsersRepo");
this.accountId = requireNonNull(accountId, "accountId");
this.allUsersName = requireNonNull(allUsersName, "allUsersName");
this.repo = requireNonNull(allUsersRepo, "allUsersRepo");
this.ref = RefNames.refsUsers(accountId);
}

View File

@ -14,8 +14,8 @@
package com.google.gerrit.server.account;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toSet;
import com.google.common.annotations.VisibleForTesting;
@ -230,19 +230,19 @@ public class AccountsUpdate {
PersonIdent authorIdent,
Runnable afterReadRevision,
Runnable beforeCommit) {
this.repoManager = checkNotNull(repoManager, "repoManager");
this.gitRefUpdated = checkNotNull(gitRefUpdated, "gitRefUpdated");
this.repoManager = requireNonNull(repoManager, "repoManager");
this.gitRefUpdated = requireNonNull(gitRefUpdated, "gitRefUpdated");
this.currentUser = currentUser;
this.allUsersName = checkNotNull(allUsersName, "allUsersName");
this.externalIds = checkNotNull(externalIds, "externalIds");
this.allUsersName = requireNonNull(allUsersName, "allUsersName");
this.externalIds = requireNonNull(externalIds, "externalIds");
this.metaDataUpdateInternalFactory =
checkNotNull(metaDataUpdateInternalFactory, "metaDataUpdateInternalFactory");
this.retryHelper = checkNotNull(retryHelper, "retryHelper");
this.extIdNotesLoader = checkNotNull(extIdNotesLoader, "extIdNotesLoader");
this.committerIdent = checkNotNull(committerIdent, "committerIdent");
this.authorIdent = checkNotNull(authorIdent, "authorIdent");
this.afterReadRevision = checkNotNull(afterReadRevision, "afterReadRevision");
this.beforeCommit = checkNotNull(beforeCommit, "beforeCommit");
requireNonNull(metaDataUpdateInternalFactory, "metaDataUpdateInternalFactory");
this.retryHelper = requireNonNull(retryHelper, "retryHelper");
this.extIdNotesLoader = requireNonNull(extIdNotesLoader, "extIdNotesLoader");
this.committerIdent = requireNonNull(committerIdent, "committerIdent");
this.authorIdent = requireNonNull(authorIdent, "authorIdent");
this.afterReadRevision = requireNonNull(afterReadRevision, "afterReadRevision");
this.beforeCommit = requireNonNull(beforeCommit, "beforeCommit");
}
private static PersonIdent createPersonIdent(
@ -551,11 +551,11 @@ public class AccountsUpdate {
AccountConfig accountConfig,
ExternalIdNotes extIdNotes) {
checkState(!Strings.isNullOrEmpty(message), "message for account update must be set");
this.allUsersName = checkNotNull(allUsersName);
this.externalIds = checkNotNull(externalIds);
this.message = checkNotNull(message);
this.accountConfig = checkNotNull(accountConfig);
this.extIdNotes = checkNotNull(extIdNotes);
this.allUsersName = requireNonNull(allUsersName);
this.externalIds = requireNonNull(externalIds);
this.message = requireNonNull(message);
this.accountConfig = requireNonNull(accountConfig);
this.extIdNotes = requireNonNull(extIdNotes);
}
public String getMessage() {

View File

@ -14,7 +14,6 @@
package com.google.gerrit.server.account;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.server.config.ConfigUtil.loadSection;
import static com.google.gerrit.server.config.ConfigUtil.skipField;
@ -27,6 +26,7 @@ import static com.google.gerrit.server.git.UserConfigSections.KEY_TARGET;
import static com.google.gerrit.server.git.UserConfigSections.KEY_TOKEN;
import static com.google.gerrit.server.git.UserConfigSections.KEY_URL;
import static com.google.gerrit.server.git.UserConfigSections.URL_ALIAS;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
@ -104,10 +104,10 @@ public class Preferences {
Config cfg,
Config defaultCfg,
ValidationError.Sink validationErrorSink) {
this.accountId = checkNotNull(accountId, "accountId");
this.cfg = checkNotNull(cfg, "cfg");
this.defaultCfg = checkNotNull(defaultCfg, "defaultCfg");
this.validationErrorSink = checkNotNull(validationErrorSink, "validationErrorSink");
this.accountId = requireNonNull(accountId, "accountId");
this.cfg = requireNonNull(cfg, "cfg");
this.defaultCfg = requireNonNull(defaultCfg, "defaultCfg");
this.validationErrorSink = requireNonNull(validationErrorSink, "validationErrorSink");
}
public GeneralPreferencesInfo getGeneralPreferences() {

View File

@ -15,7 +15,7 @@
package com.google.gerrit.server.account;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
@ -112,9 +112,9 @@ public class ProjectWatches {
private ImmutableMap<ProjectWatchKey, ImmutableSet<NotifyType>> projectWatches;
ProjectWatches(Account.Id accountId, Config cfg, ValidationError.Sink validationErrorSink) {
this.accountId = checkNotNull(accountId, "accountId");
this.cfg = checkNotNull(cfg, "cfg");
this.validationErrorSink = checkNotNull(validationErrorSink, "validationErrorSink");
this.accountId = requireNonNull(accountId, "accountId");
this.cfg = requireNonNull(cfg, "cfg");
this.validationErrorSink = requireNonNull(validationErrorSink, "validationErrorSink");
}
public ImmutableMap<ProjectWatchKey, ImmutableSet<NotifyType>> getProjectWatches() {

View File

@ -14,10 +14,10 @@
package com.google.gerrit.server.account.externalids;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
@ -284,7 +284,7 @@ public abstract class ExternalId implements Serializable {
}
public static ExternalId createEmail(Account.Id accountId, String email) {
return createWithEmail(SCHEME_MAILTO, email, accountId, checkNotNull(email));
return createWithEmail(SCHEME_MAILTO, email, accountId, requireNonNull(email));
}
static ExternalId create(ExternalId extId, @Nullable ObjectId blobId) {
@ -331,7 +331,7 @@ public abstract class ExternalId implements Serializable {
public static ExternalId parse(String noteId, Config externalIdConfig, ObjectId blobId)
throws ConfigInvalidException {
checkNotNull(blobId);
requireNonNull(blobId);
Set<String> externalIdKeys = externalIdConfig.getSubsections(EXTERNAL_ID_SECTION);
if (externalIdKeys.size() != 1) {

View File

@ -14,9 +14,9 @@
package com.google.gerrit.server.account.externalids;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toSet;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
@ -284,15 +284,15 @@ public class ExternalIdNotes extends VersionedMetaData {
MetricMaker metricMaker,
AllUsersName allUsersName,
Repository allUsersRepo) {
this.externalIdCache = checkNotNull(externalIdCache, "externalIdCache");
this.externalIdCache = requireNonNull(externalIdCache, "externalIdCache");
this.accountCache = accountCache;
this.accountIndexer = accountIndexer;
this.updateCount =
metricMaker.newCounter(
"notedb/external_id_update_count",
new Description("Total number of external ID updates.").setRate().setUnit("updates"));
this.allUsersName = checkNotNull(allUsersName, "allUsersRepo");
this.repo = checkNotNull(allUsersRepo, "allUsersRepo");
this.allUsersName = requireNonNull(allUsersName, "allUsersRepo");
this.repo = requireNonNull(allUsersRepo, "allUsersRepo");
}
public ExternalIdNotes setAfterReadRevision(Runnable afterReadRevision) {

View File

@ -14,8 +14,8 @@
package com.google.gerrit.server.api.accounts;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import static java.util.Objects.requireNonNull;
import com.google.gerrit.extensions.api.accounts.AccountApi;
import com.google.gerrit.extensions.api.accounts.AccountInput;
@ -95,7 +95,7 @@ public class AccountsImpl implements Accounts {
@Override
public AccountApi create(AccountInput in) throws RestApiException {
if (checkNotNull(in, "AccountInput").username == null) {
if (requireNonNull(in, "AccountInput").username == null) {
throw new BadRequestException("AccountInput must specify username");
}
try {

View File

@ -14,9 +14,9 @@
package com.google.gerrit.server.api.changes;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
@ -128,7 +128,7 @@ class ChangesImpl implements Changes {
// Check type safety of result; the extension API should be safer than the
// REST API in this case, since it's intended to be used in Java.
Object first = checkNotNull(result.iterator().next());
Object first = requireNonNull(result.iterator().next());
checkState(first instanceof ChangeInfo);
@SuppressWarnings("unchecked")
List<ChangeInfo> infos = (List<ChangeInfo>) result;

View File

@ -14,8 +14,8 @@
package com.google.gerrit.server.api.groups;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import static java.util.Objects.requireNonNull;
import com.google.gerrit.extensions.api.groups.GroupApi;
import com.google.gerrit.extensions.api.groups.GroupInput;
@ -90,7 +90,7 @@ class GroupsImpl implements Groups {
@Override
public GroupApi create(GroupInput in) throws RestApiException {
if (checkNotNull(in, "GroupInput").name == null) {
if (requireNonNull(in, "GroupInput").name == null) {
throw new BadRequestException("GroupInput must specify name");
}
try {

View File

@ -14,9 +14,10 @@
package com.google.gerrit.server.audit;
import static java.util.Objects.requireNonNull;
import com.google.auto.value.AutoValue;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.gerrit.server.CurrentUser;
@ -64,7 +65,7 @@ public class AuditEvent {
long when,
ListMultimap<String, ?> params,
Object result) {
Preconditions.checkNotNull(what, "what is a mandatory not null param !");
requireNonNull(what, "what is a mandatory not null param !");
this.sessionId = MoreObjects.firstNonNull(sessionId, UNKNOWN_SESSION_ID);
this.who = who;

View File

@ -14,7 +14,8 @@
package com.google.gerrit.server.audit;
import com.google.common.base.Preconditions;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ListMultimap;
import com.google.gerrit.extensions.restapi.RestResource;
import com.google.gerrit.extensions.restapi.RestView;
@ -62,7 +63,7 @@ public class ExtendedHttpAuditEvent extends HttpAuditEvent {
input,
status,
result);
this.httpRequest = Preconditions.checkNotNull(httpRequest);
this.httpRequest = requireNonNull(httpRequest);
this.resource = resource;
this.view = view;
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.auth;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.auto.value.AutoValue;
import com.google.gerrit.common.Nullable;
@ -48,7 +48,7 @@ public class AuthUser {
* @param username the name of the authenticated user.
*/
public AuthUser(UUID uuid, @Nullable String username) {
this.uuid = checkNotNull(uuid);
this.uuid = requireNonNull(uuid);
this.username = username;
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.auth;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.inject.Inject;
@ -38,7 +38,7 @@ public final class UniversalAuthBackend implements AuthBackend {
List<AuthException> authExs = new ArrayList<>();
for (AuthBackend backend : authBackends) {
try {
authUsers.add(checkNotNull(backend.authenticate(request)));
authUsers.add(requireNonNull(backend.authenticate(request)));
} catch (MissingCredentialsException ex) {
// Not handled by this backend.
} catch (AuthException ex) {

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.auth.oauth;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
@ -103,7 +103,7 @@ public class OAuthTokenCache {
}
public void put(Account.Id id, OAuthToken accessToken) {
cache.put(id, encrypt(checkNotNull(accessToken)));
cache.put(id, encrypt(requireNonNull(accessToken)));
}
public void remove(Account.Id id) {

View File

@ -14,8 +14,8 @@
package com.google.gerrit.server.cache;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Strings;
import com.google.common.cache.Cache;
@ -99,7 +99,7 @@ class CacheProvider<K, V> implements Provider<Cache<K, V>>, CacheBinding<K, V>,
@Override
public CacheBinding<K, V> configKey(String name) {
checkNotFrozen();
configKey = checkNotNull(name);
configKey = requireNonNull(name);
return this;
}

View File

@ -14,8 +14,8 @@
package com.google.gerrit.server.cache.serialize;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import com.google.protobuf.TextFormat;
import java.util.Arrays;
@ -28,7 +28,7 @@ public enum BooleanCacheSerializer implements CacheSerializer<Boolean> {
@Override
public byte[] serialize(Boolean object) {
byte[] bytes = checkNotNull(object) ? TRUE : FALSE;
byte[] bytes = requireNonNull(object) ? TRUE : FALSE;
return Arrays.copyOf(bytes, bytes.length);
}

View File

@ -14,8 +14,8 @@
package com.google.gerrit.server.cache.serialize;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Converter;
import com.google.common.base.Enums;
@ -29,11 +29,11 @@ public class EnumCacheSerializer<E extends Enum<E>> implements CacheSerializer<E
@Override
public byte[] serialize(E object) {
return converter.reverse().convert(checkNotNull(object)).getBytes(UTF_8);
return converter.reverse().convert(requireNonNull(object)).getBytes(UTF_8);
}
@Override
public E deserialize(byte[] in) {
return converter.convert(new String(checkNotNull(in), UTF_8));
return converter.convert(new String(requireNonNull(in), UTF_8));
}
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.cache.serialize;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.gwtorm.client.IntKey;
import java.util.function.Function;
@ -23,7 +23,7 @@ public class IntKeyCacheSerializer<K extends IntKey<?>> implements CacheSerializ
private final Function<Integer, K> factory;
public IntKeyCacheSerializer(Function<Integer, K> factory) {
this.factory = checkNotNull(factory);
this.factory = requireNonNull(factory);
}
@Override

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.cache.serialize;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
@ -34,7 +34,7 @@ public enum IntegerCacheSerializer implements CacheSerializer<Integer> {
byte[] buf = new byte[MAX_VARINT_SIZE];
CodedOutputStream cout = CodedOutputStream.newInstance(buf);
try {
cout.writeInt32NoTag(checkNotNull(object));
cout.writeInt32NoTag(requireNonNull(object));
cout.flush();
} catch (IOException e) {
throw new IllegalStateException("Failed to serialize int");
@ -45,7 +45,7 @@ public enum IntegerCacheSerializer implements CacheSerializer<Integer> {
@Override
public Integer deserialize(byte[] in) {
CodedInputStream cin = CodedInputStream.newInstance(checkNotNull(in));
CodedInputStream cin = CodedInputStream.newInstance(requireNonNull(in));
int ret;
try {
ret = cin.readRawVarint32();

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.change;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
@ -77,7 +77,7 @@ public class ActionJson {
List<ActionVisitor> visitors = visitors();
if (!visitors.isEmpty()) {
changeInfo = changeJson().format(rsrc);
revisionInfo = checkNotNull(Iterables.getOnlyElement(changeInfo.revisions.values()));
revisionInfo = requireNonNull(Iterables.getOnlyElement(changeInfo.revisions.values()));
changeInfo.revisions = null;
}
return toActionMap(rsrc, visitors, changeInfo, revisionInfo);

View File

@ -15,11 +15,11 @@
package com.google.gerrit.server.change;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.gerrit.extensions.client.ReviewerState.CC;
import static com.google.gerrit.extensions.client.ReviewerState.REVIEWER;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
import com.google.auto.value.AutoValue;
@ -165,7 +165,7 @@ public class AddReviewersOp implements BatchUpdateOp {
}
void setPatchSet(PatchSet patchSet) {
this.patchSet = checkNotNull(patchSet);
this.patchSet = requireNonNull(patchSet);
}
@Override
@ -213,7 +213,7 @@ public class AddReviewersOp implements BatchUpdateOp {
checkAdded();
if (patchSet == null) {
patchSet = checkNotNull(psUtil.current(ctx.getDb(), ctx.getNotes()));
patchSet = requireNonNull(psUtil.current(ctx.getDb(), ctx.getNotes()));
}
return true;
}

View File

@ -14,13 +14,13 @@
package com.google.gerrit.server.change;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.gerrit.reviewdb.client.Change.INITIAL_PATCH_SET_ID;
import static com.google.gerrit.server.change.ReviewerAdder.newAddReviewerInputFromCommitIdentity;
import static com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER;
import static java.util.Objects.requireNonNull;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
@ -263,7 +263,7 @@ public class ChangeInserter implements InsertChangeOp {
public ChangeInserter setAccountsToNotify(
ListMultimap<RecipientType, Account.Id> accountsToNotify) {
this.accountsToNotify = checkNotNull(accountsToNotify);
this.accountsToNotify = requireNonNull(accountsToNotify);
return this;
}
@ -304,7 +304,7 @@ public class ChangeInserter implements InsertChangeOp {
}
public ChangeInserter setGroups(List<String> groups) {
checkNotNull(groups, "groups may not be empty");
requireNonNull(groups, "groups may not be empty");
checkState(patchSet == null, "setGroups(Iterable<String>) only valid before creating change");
this.groups = groups;
return this;

View File

@ -15,10 +15,10 @@
package com.google.gerrit.server.change;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.reviewdb.client.RefNames.REFS_CHANGES;
import static com.google.gerrit.reviewdb.server.ReviewDbUtil.intKeyOrdering;
import static com.google.gerrit.server.ChangeUtil.PS_ID_ORDER;
import static java.util.Objects.requireNonNull;
import com.google.auto.value.AutoValue;
import com.google.common.collect.Collections2;
@ -171,7 +171,7 @@ public class ConsistencyChecker {
}
public Result check(ChangeNotes notes, @Nullable FixInput f) {
checkNotNull(notes);
requireNonNull(notes);
try {
return retryHelper.execute(
buf -> {
@ -530,7 +530,7 @@ public class ConsistencyChecker {
if (!reuseOldPsId) {
bu.addOp(
notes.getChangeId(),
new DeletePatchSetFromDbOp(checkNotNull(deleteOldPatchSetProblem), psIdToDelete));
new DeletePatchSetFromDbOp(requireNonNull(deleteOldPatchSetProblem), psIdToDelete));
}
}
@ -759,7 +759,7 @@ public class ConsistencyChecker {
private ProblemInfo problem(String msg) {
ProblemInfo p = new ProblemInfo();
p.message = checkNotNull(msg);
p.message = requireNonNull(msg);
problems.add(p);
return p;
}

View File

@ -15,7 +15,7 @@
package com.google.gerrit.server.change;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Converter;
import com.google.common.base.Enums;
@ -85,10 +85,10 @@ public class MergeabilityCacheImpl implements MergeabilityCache {
"Cannot cache %s.%s",
SubmitType.class.getSimpleName(),
submitType);
this.commit = checkNotNull(commit, "commit");
this.into = checkNotNull(into, "into");
this.submitType = checkNotNull(submitType, "submitType");
this.mergeStrategy = checkNotNull(mergeStrategy, "mergeStrategy");
this.commit = requireNonNull(commit, "commit");
this.into = requireNonNull(into, "into");
this.submitType = requireNonNull(submitType, "submitType");
this.mergeStrategy = requireNonNull(mergeStrategy, "mergeStrategy");
}
public ObjectId getCommit() {

View File

@ -14,12 +14,11 @@
package com.google.gerrit.server.change;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.server.notedb.ReviewerStateInternal.CC;
import static com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.flogger.FluentLogger;
@ -167,7 +166,7 @@ public class PatchSetInserter implements BatchUpdateOp {
}
public PatchSetInserter setGroups(List<String> groups) {
checkNotNull(groups, "groups may not be null");
requireNonNull(groups, "groups may not be null");
this.groups = groups;
return this;
}
@ -178,13 +177,13 @@ public class PatchSetInserter implements BatchUpdateOp {
}
public PatchSetInserter setNotify(NotifyHandling notify) {
this.notify = Preconditions.checkNotNull(notify);
this.notify = requireNonNull(notify);
return this;
}
public PatchSetInserter setAccountsToNotify(
ListMultimap<RecipientType, Account.Id> accountsToNotify) {
this.accountsToNotify = checkNotNull(accountsToNotify);
this.accountsToNotify = requireNonNull(accountsToNotify);
return this;
}

View File

@ -15,13 +15,13 @@
package com.google.gerrit.server.change;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.gerrit.extensions.client.ReviewerState.CC;
import static com.google.gerrit.extensions.client.ReviewerState.REVIEWER;
import static java.util.Comparator.comparing;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableListMultimap;
@ -206,7 +206,7 @@ public class ReviewerAdder {
public ReviewerAddition prepare(
ReviewDb db, ChangeNotes notes, CurrentUser user, AddReviewerInput input, boolean allowGroup)
throws OrmException, IOException, PermissionBackendException, ConfigInvalidException {
checkNotNull(input.reviewer);
requireNonNull(input.reviewer);
ListMultimap<RecipientType, Account.Id> accountsToNotify;
try {
accountsToNotify = notifyUtil.resolveAccounts(input.notifyDetails);
@ -468,7 +468,7 @@ public class ReviewerAdder {
private ReviewerAddition(AddReviewerInput input, FailureType failureType) {
this.input = input;
this.failureType = checkNotNull(failureType);
this.failureType = requireNonNull(failureType);
result = new AddReviewerResult(input.reviewer);
op = null;
reviewers = ImmutableSet.of();

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.change;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
@ -70,7 +70,7 @@ public class SetAssigneeOp implements BatchUpdateOp {
this.setAssigneeSenderFactory = setAssigneeSenderFactory;
this.user = user;
this.userFactory = userFactory;
this.newAssignee = checkNotNull(newAssignee, "assignee");
this.newAssignee = requireNonNull(newAssignee, "assignee");
}
@Override

View File

@ -14,7 +14,8 @@
package com.google.gerrit.server.config;
import com.google.common.base.Preconditions;
import static java.util.Objects.requireNonNull;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
@ -289,7 +290,7 @@ public class ConfigUtil {
Object c = f.get(s);
Object d = f.get(defaults);
if (!isString(t) && !isCollectionOrMap(t)) {
Preconditions.checkNotNull(d, "Default cannot be null for: " + n);
requireNonNull(d, "Default cannot be null for: " + n);
}
if (c == null || c.equals(d)) {
cfg.unset(section, sub, n);
@ -347,7 +348,7 @@ public class ConfigUtil {
f.setAccessible(true);
Object d = f.get(defaults);
if (!isString(t) && !isCollectionOrMap(t)) {
Preconditions.checkNotNull(d, "Default cannot be null for: " + n);
requireNonNull(d, "Default cannot be null for: " + n);
}
if (isString(t)) {
String v = cfg.getString(section, sub, n);

View File

@ -14,8 +14,8 @@
package com.google.gerrit.server.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.time.ZoneId.systemDefault;
import static java.util.Objects.requireNonNull;
import com.google.auto.value.AutoValue;
import com.google.auto.value.extension.memoized.Memoized;
@ -239,7 +239,7 @@ public abstract class ScheduleConfig {
}
private static long computeInitialDelay(long interval, String start, ZonedDateTime now) {
checkNotNull(start);
requireNonNull(start);
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("[E ]HH:mm").withLocale(Locale.US);

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.edit;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
@ -35,10 +35,10 @@ public class ChangeEdit {
public ChangeEdit(
Change change, String editRefName, RevCommit editCommit, PatchSet basePatchSet) {
this.change = checkNotNull(change);
this.editRefName = checkNotNull(editRefName);
this.editCommit = checkNotNull(editCommit);
this.basePatchSet = checkNotNull(basePatchSet);
this.change = requireNonNull(change);
this.editRefName = requireNonNull(editRefName);
this.editCommit = requireNonNull(editCommit);
this.basePatchSet = requireNonNull(basePatchSet);
}
public Change getChange() {

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.edit.tree;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import com.google.common.annotations.VisibleForTesting;
@ -43,7 +43,7 @@ public class ChangeFileContentModification implements TreeModification {
public ChangeFileContentModification(String filePath, RawInput newContent) {
this.filePath = filePath;
this.newContent = checkNotNull(newContent, "new content required");
this.newContent = requireNonNull(newContent, "new content required");
}
@Override

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.edit.tree;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import java.io.IOException;
import java.util.ArrayList;
@ -39,7 +39,7 @@ public class TreeCreator {
private final List<TreeModification> treeModifications = new ArrayList<>();
public TreeCreator(RevCommit baseCommit) {
this.baseCommit = checkNotNull(baseCommit, "baseCommit is required");
this.baseCommit = requireNonNull(baseCommit, "baseCommit is required");
}
/**
@ -49,7 +49,7 @@ public class TreeCreator {
* @param treeModifications modifications which should be applied to the base tree
*/
public void addTreeModifications(List<TreeModification> treeModifications) {
checkNotNull(treeModifications, "treeModifications must not be null");
requireNonNull(treeModifications, "treeModifications must not be null");
this.treeModifications.addAll(treeModifications);
}

View File

@ -14,8 +14,8 @@
package com.google.gerrit.server.events;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Comparator.comparing;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
@ -322,7 +322,7 @@ public class EventFactory {
if (!ps.getRevision().get().equals(p)) {
continue;
}
ca.dependsOn.add(newDependsOn(checkNotNull(cd.change()), ps));
ca.dependsOn.add(newDependsOn(requireNonNull(cd.change()), ps));
}
}
}
@ -357,7 +357,7 @@ public class EventFactory {
if (!p.name().equals(rev)) {
continue;
}
ca.neededBy.add(newNeededBy(checkNotNull(cd.change()), ps));
ca.neededBy.add(newNeededBy(requireNonNull(cd.change()), ps));
continue PATCH_SETS;
}
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.fixes;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.groupingBy;
import com.google.gerrit.common.RawInputUtil;
@ -70,7 +70,7 @@ public class FixReplacementInterpreter {
ObjectId patchSetCommitId,
List<FixReplacement> fixReplacements)
throws ResourceNotFoundException, IOException, ResourceConflictException {
checkNotNull(fixReplacements, "Fix replacements must not be null");
requireNonNull(fixReplacements, "Fix replacements must not be null");
Map<String, List<FixReplacement>> fixReplacementsPerFilePath =
fixReplacements.stream().collect(groupingBy(fixReplacement -> fixReplacement.path));

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.fixes;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -36,7 +36,7 @@ class LineIdentifier {
private int currentLineEndIndex;
LineIdentifier(String string) {
checkNotNull(string);
requireNonNull(string);
lineSeparatorMatcher = LINE_SEPARATOR_PATTERN.matcher(string);
reset();
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.fixes;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
/**
* A modifier of a string. It allows to replace multiple parts of a string by indicating those parts
@ -29,7 +29,7 @@ class StringModifier {
private int previousEndOffset = Integer.MIN_VALUE;
StringModifier(String string) {
checkNotNull(string, "string must not be null");
requireNonNull(string, "string must not be null");
stringBuilder = new StringBuilder(string);
}
@ -45,7 +45,7 @@ class StringModifier {
* previous call of this method
*/
public void replace(int startIndex, int endIndex, String replacement) {
checkNotNull(replacement, "replacement string must not be null");
requireNonNull(replacement, "replacement string must not be null");
if (previousEndOffset > startIndex) {
throw new StringIndexOutOfBoundsException(
String.format(

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.git;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
@ -40,7 +40,7 @@ public class InMemoryInserter extends ObjectInserter {
private final boolean closeReader;
public InMemoryInserter(ObjectReader reader) {
this.reader = checkNotNull(reader);
this.reader = requireNonNull(reader);
closeReader = false;
}

View File

@ -15,7 +15,7 @@
package com.google.gerrit.server.git;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.gerrit.common.Nullable;
import java.util.Collection;
@ -40,7 +40,7 @@ public class MergeTip {
* @param toMerge list of commits to be merged in merge operation; may not be null or empty.
*/
public MergeTip(@Nullable CodeReviewCommit initialTip, Collection<CodeReviewCommit> toMerge) {
checkNotNull(toMerge, "toMerge may not be null");
requireNonNull(toMerge, "toMerge may not be null");
checkArgument(!toMerge.isEmpty(), "toMerge may not be empty");
this.initialTip = initialTip;
this.branchTip = initialTip;

View File

@ -15,10 +15,10 @@
package com.google.gerrit.server.git;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
@ -129,16 +129,18 @@ public class MergeUtil {
public String generate(
RevCommit original, RevCommit mergeTip, Branch.NameKey dest, String current) {
checkNotNull(original.getRawBuffer());
requireNonNull(original.getRawBuffer());
if (mergeTip != null) {
checkNotNull(mergeTip.getRawBuffer());
requireNonNull(mergeTip.getRawBuffer());
}
for (ChangeMessageModifier changeMessageModifier : changeMessageModifiers) {
current = changeMessageModifier.onSubmit(current, original, mergeTip, dest);
checkNotNull(
requireNonNull(
current,
changeMessageModifier.getClass().getName()
+ ".OnSubmit returned null instead of new commit message");
() ->
String.format(
"%s.OnSubmit returned null instead of new commit message",
changeMessageModifier.getClass().getName()));
}
return current;
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.git;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.reviewdb.client.Change;
@ -101,7 +101,7 @@ public class MergedByPushOp implements BatchUpdateOp {
}
public MergedByPushOp setPatchSetProvider(Provider<PatchSet> patchSetProvider) {
this.patchSetProvider = checkNotNull(patchSetProvider);
this.patchSetProvider = requireNonNull(patchSetProvider);
return this;
}
@ -119,8 +119,9 @@ public class MergedByPushOp implements BatchUpdateOp {
patchSet = patchSetProvider.get();
} else {
patchSet =
checkNotNull(
psUtil.get(ctx.getDb(), ctx.getNotes(), psId), "patch set %s not found", psId);
requireNonNull(
psUtil.get(ctx.getDb(), ctx.getNotes(), psId),
() -> String.format("patch set %s not found", psId));
}
info = getPatchSetInfo(ctx);
@ -198,7 +199,7 @@ public class MergedByPushOp implements BatchUpdateOp {
private PatchSetInfo getPatchSetInfo(ChangeContext ctx) throws IOException, OrmException {
RevWalk rw = ctx.getRevWalk();
RevCommit commit =
rw.parseCommit(ObjectId.fromString(checkNotNull(patchSet).getRevision().get()));
rw.parseCommit(ObjectId.fromString(requireNonNull(patchSet).getRevision().get()));
return patchSetInfoFactory.get(rw, commit, psId);
}
}

View File

@ -16,7 +16,6 @@ package com.google.gerrit.server.git.receive;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.gerrit.common.FooterConstants.CHANGE_ID;
@ -32,6 +31,7 @@ import static com.google.gerrit.server.git.validators.CommitValidators.NEW_PATCH
import static com.google.gerrit.server.mail.MailUtil.getRecipientsFromFooters;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Comparator.comparingInt;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
@ -2428,7 +2428,7 @@ class ReceiveCommits {
final PatchSet.Id psId = ins.setGroups(groups).getPatchSetId();
Account.Id me = user.getAccountId();
List<FooterLine> footerLines = commit.getFooterLines();
checkNotNull(magicBranch);
requireNonNull(magicBranch);
// TODO(dborowitz): Support reviewers by email from footers? Maybe not: kernel developers
// with AOSP accounts already complain about these notifications, and that would make it
@ -2496,15 +2496,20 @@ class ReceiveCommits {
PermissionBackendException {
Map<ObjectId, Change> bySha = Maps.newHashMapWithExpectedSize(create.size() + replace.size());
for (CreateRequest r : create) {
checkNotNull(r.change, "cannot submit new change %s; op may not have run", r.changeId);
requireNonNull(
r.change,
() -> String.format("cannot submit new change %s; op may not have run", r.changeId));
bySha.put(r.commit, r.change);
}
for (ReplaceRequest r : replace) {
bySha.put(r.newCommitId, r.notes.getChange());
}
Change tipChange = bySha.get(magicBranch.cmd.getNewId());
checkNotNull(
tipChange, "tip of push does not correspond to a change; found these changes: %s", bySha);
requireNonNull(
tipChange,
() ->
String.format(
"tip of push does not correspond to a change; found these changes: %s", bySha));
logger.atFine().log(
"Processing submit with tip change %s (%s)", tipChange.getId(), magicBranch.cmd.getNewId());
try (MergeOp op = mergeOpProvider.get()) {
@ -2573,7 +2578,7 @@ class ReceiveCommits {
Change.Id toChange, RevCommit newCommit, ReceiveCommand cmd, boolean checkMergedInto) {
this.ontoChange = toChange;
this.newCommitId = newCommit.copy();
this.inputCommand = checkNotNull(cmd);
this.inputCommand = requireNonNull(cmd);
this.checkMergedInto = checkMergedInto;
revisions = HashBiMap.create();
@ -2853,7 +2858,7 @@ class ReceiveCommits {
List<String> groups = ImmutableList.of();
UpdateGroupsRequest(Ref ref, RevCommit commit) {
this.psId = checkNotNull(PatchSet.Id.fromRef(ref.getName()));
this.psId = requireNonNull(PatchSet.Id.fromRef(ref.getName()));
this.commit = commit;
}
@ -2887,7 +2892,7 @@ class ReceiveCommits {
final ReceiveCommand cmd;
private UpdateOneRefOp(ReceiveCommand cmd) {
this.cmd = checkNotNull(cmd);
this.cmd = requireNonNull(cmd);
}
@Override

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.git.validators;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableMap;
import com.google.gerrit.extensions.annotations.ExtensionPoint;
@ -52,9 +52,9 @@ public interface OnSubmitValidationListener {
* @param commands commands to be executed.
*/
Arguments(Project.NameKey project, RevWalk rw, ChainedReceiveCommands commands) {
this.project = checkNotNull(project);
this.rw = checkNotNull(rw);
this.refs = checkNotNull(commands);
this.project = requireNonNull(project);
this.rw = requireNonNull(rw);
this.refs = requireNonNull(commands);
this.commands = ImmutableMap.copyOf(commands.getCommands());
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.group;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableSet;
import com.google.gerrit.common.Nullable;
@ -29,7 +29,7 @@ public class InternalGroupDescription implements GroupDescription.Internal {
private final InternalGroup internalGroup;
public InternalGroupDescription(InternalGroup internalGroup) {
this.internalGroup = checkNotNull(internalGroup);
this.internalGroup = requireNonNull(internalGroup);
}
@Override

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.group;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toSet;
import com.google.common.annotations.VisibleForTesting;
@ -117,7 +117,7 @@ public class SystemGroupBackend extends AbstractGroupBackend {
}
public GroupReference getGroup(AccountGroup.UUID uuid) {
return checkNotNull(uuids.get(uuid), "group %s not found", uuid.get());
return requireNonNull(uuids.get(uuid), () -> String.format("group %s not found", uuid.get()));
}
public Set<String> getNames() {

View File

@ -14,8 +14,8 @@
package com.google.gerrit.server.group.db;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableSet;
import com.google.gerrit.common.Nullable;
@ -90,16 +90,16 @@ public class AuditLogFormatter {
Function<Account.Id, Optional<Account>> accountRetriever,
Function<AccountGroup.UUID, Optional<GroupDescription.Basic>> groupRetriever,
String serverId) {
this.accountRetriever = checkNotNull(accountRetriever);
this.groupRetriever = checkNotNull(groupRetriever);
this.serverId = checkNotNull(serverId);
this.accountRetriever = requireNonNull(accountRetriever);
this.groupRetriever = requireNonNull(groupRetriever);
this.serverId = requireNonNull(serverId);
}
private AuditLogFormatter(
Function<Account.Id, Optional<Account>> accountRetriever,
Function<AccountGroup.UUID, Optional<GroupDescription.Basic>> groupRetriever) {
this.accountRetriever = checkNotNull(accountRetriever);
this.groupRetriever = checkNotNull(groupRetriever);
this.accountRetriever = requireNonNull(accountRetriever);
this.groupRetriever = requireNonNull(groupRetriever);
serverId = null;
}

View File

@ -14,9 +14,9 @@
package com.google.gerrit.server.group.db;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
import com.google.common.annotations.VisibleForTesting;
@ -187,7 +187,7 @@ public class GroupConfig extends VersionedMetaData {
private boolean allowSaveEmptyName;
private GroupConfig(AccountGroup.UUID groupUuid) {
this.groupUuid = checkNotNull(groupUuid);
this.groupUuid = requireNonNull(groupUuid);
ref = RefNames.refsGroups(groupUuid);
}

View File

@ -14,9 +14,9 @@
package com.google.gerrit.server.group.db;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableBiMap.toImmutableBiMap;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import com.google.common.annotations.VisibleForTesting;
@ -123,8 +123,8 @@ public class GroupNameNotes extends VersionedMetaData {
AccountGroup.NameKey oldName,
AccountGroup.NameKey newName)
throws IOException, ConfigInvalidException, OrmDuplicateKeyException {
checkNotNull(oldName);
checkNotNull(newName);
requireNonNull(oldName);
requireNonNull(newName);
GroupNameNotes groupNameNotes = new GroupNameNotes(groupUuid, oldName, newName);
groupNameNotes.load(projectName, repository);
@ -154,7 +154,7 @@ public class GroupNameNotes extends VersionedMetaData {
AccountGroup.UUID groupUuid,
AccountGroup.NameKey groupName)
throws IOException, ConfigInvalidException, OrmDuplicateKeyException {
checkNotNull(groupName);
requireNonNull(groupName);
GroupNameNotes groupNameNotes = new GroupNameNotes(groupUuid, null, groupName);
groupNameNotes.load(projectName, repository);
@ -313,7 +313,7 @@ public class GroupNameNotes extends VersionedMetaData {
AccountGroup.UUID groupUuid,
@Nullable AccountGroup.NameKey oldGroupName,
@Nullable AccountGroup.NameKey newGroupName) {
this.groupUuid = checkNotNull(groupUuid);
this.groupUuid = requireNonNull(groupUuid);
if (Objects.equals(oldGroupName, newGroupName)) {
this.oldGroupName = Optional.empty();

View File

@ -14,8 +14,8 @@
package com.google.gerrit.server.group.testing;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableList;
import com.google.gerrit.common.data.GroupDescription;
@ -42,7 +42,7 @@ public class TestGroupBackend implements GroupBackend {
* @return the created group
*/
public GroupDescription.Basic create(String name) {
checkNotNull(name);
requireNonNull(name);
return create(new AccountGroup.UUID(name.startsWith(PREFIX) ? name : PREFIX + name));
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.index;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.Lists;
import com.google.common.flogger.FluentLogger;
@ -98,11 +98,9 @@ public class OnlineReindexer<K, V, I extends Index<K, V>> {
listener.onStart(name, oldVersion, newVersion);
}
index =
checkNotNull(
requireNonNull(
indexes.getWriteIndex(newVersion),
"not an active write schema version: %s %s",
name,
newVersion);
() -> String.format("not an active write schema version: %s %s", name, newVersion));
logger.atInfo().log(
"Starting online reindex of %s from schema version %s to %s",
name, version(indexes.getSearchIndex()), version(index));

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.index.account;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.gerrit.index.IndexRewriter;
import com.google.gerrit.index.QueryOptions;
@ -38,7 +38,7 @@ public class AccountIndexRewriter implements IndexRewriter<AccountState> {
public Predicate<AccountState> rewrite(Predicate<AccountState> in, QueryOptions opts)
throws QueryParseException {
AccountIndex index = indexes.getSearchIndex();
checkNotNull(index, "no active search index configured for accounts");
requireNonNull(index, "no active search index configured for accounts");
return new IndexedAccountQuery(index, in, opts);
}
}

View File

@ -14,9 +14,9 @@
package com.google.gerrit.server.index.account;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
@ -140,7 +140,7 @@ public class StalenessChecker {
}
for (byte[] b : extIdStates) {
checkNotNull(b, "invalid external ID state");
requireNonNull(b, "invalid external ID state");
String s = new String(b, UTF_8);
List<String> parts = Splitter.on(':').splitToList(s);
checkState(parts.size() == 2, "invalid external ID state: %s", s);

View File

@ -15,8 +15,8 @@
package com.google.gerrit.server.index.change;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
import com.google.auto.value.AutoValue;
@ -136,7 +136,7 @@ public class StalenessChecker {
@VisibleForTesting
static boolean reviewDbChangeIsStale(Change indexChange, @Nullable Change reviewDbChange) {
checkNotNull(indexChange);
requireNonNull(indexChange);
PrimaryStorage storageFromIndex = PrimaryStorage.of(indexChange);
PrimaryStorage storageFromReviewDb = PrimaryStorage.of(reviewDbChange);
if (reviewDbChange == null) {

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.index.group;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.gerrit.index.IndexRewriter;
import com.google.gerrit.index.QueryOptions;
@ -37,7 +37,7 @@ public class GroupIndexRewriter implements IndexRewriter<InternalGroup> {
public Predicate<InternalGroup> rewrite(Predicate<InternalGroup> in, QueryOptions opts)
throws QueryParseException {
GroupIndex index = indexes.getSearchIndex();
checkNotNull(index, "no active search index configured for groups");
requireNonNull(index, "no active search index configured for groups");
return new IndexedGroupQuery(index, in, opts);
}
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.ioutil;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.Lists;
import com.google.common.primitives.Chars;
@ -41,7 +41,7 @@ public final class RegexListSearcher<T> {
private final boolean prefixOnly;
public RegexListSearcher(String re, Function<T, String> toStringFunc) {
this.toStringFunc = checkNotNull(toStringFunc);
this.toStringFunc = requireNonNull(toStringFunc);
if (re.startsWith("^")) {
re = re.substring(1);
@ -68,7 +68,7 @@ public final class RegexListSearcher<T> {
}
public Stream<T> search(List<T> list) {
checkNotNull(list);
requireNonNull(list);
int begin;
int end;

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.logging;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.MultimapBuilder;
@ -39,8 +39,8 @@ public class MutableTags {
* already exists
*/
public boolean add(String name, String value) {
checkNotNull(name, "tag name is required");
checkNotNull(value, "tag value is required");
requireNonNull(name, "tag name is required");
requireNonNull(value, "tag value is required");
boolean ret = tagMap.put(name, value);
if (ret) {
buildTags();
@ -55,8 +55,8 @@ public class MutableTags {
* @param value the value of the tag
*/
public void remove(String name, String value) {
checkNotNull(name, "tag name is required");
checkNotNull(value, "tag value is required");
requireNonNull(name, "tag name is required");
requireNonNull(value, "tag value is required");
if (tagMap.remove(name, value)) {
buildTags();
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.logging;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.base.Stopwatch;
import com.google.common.base.Strings;
@ -252,12 +252,12 @@ public class TraceContext implements AutoCloseable {
private TraceContext() {}
public TraceContext addTag(RequestId.Type requestId, Object tagValue) {
return addTag(checkNotNull(requestId, "request ID is required").name(), tagValue);
return addTag(requireNonNull(requestId, "request ID is required").name(), tagValue);
}
public TraceContext addTag(String tagName, Object tagValue) {
String name = checkNotNull(tagName, "tag name is required");
String value = checkNotNull(tagValue, "tag value is required").toString();
String name = requireNonNull(tagName, "tag name is required");
String value = requireNonNull(tagValue, "tag value is required").toString();
tags.put(name, value, LoggingContext.getInstance().addTag(name, value));
return this;
}

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.mail.send;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.extensions.api.changes.RecipientType;
@ -47,9 +47,9 @@ public class InboundEmailRejectionSender extends OutgoingEmail {
public InboundEmailRejectionSender(
EmailArguments ea, @Assisted Address to, @Assisted String threadId, @Assisted Error reason) {
super(ea, "error");
this.to = checkNotNull(to);
this.threadId = checkNotNull(threadId);
this.reason = checkNotNull(reason);
this.to = requireNonNull(to);
this.threadId = requireNonNull(threadId);
this.reason = requireNonNull(reason);
}
@Override

View File

@ -14,9 +14,9 @@
package com.google.gerrit.server.mail.send;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.extensions.client.GeneralPreferencesInfo.EmailStrategy.CC_ON_OWN_COMMENTS;
import static com.google.gerrit.extensions.client.GeneralPreferencesInfo.EmailStrategy.DISABLED;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ListMultimap;
@ -84,11 +84,11 @@ public abstract class OutgoingEmail {
}
public void setNotify(NotifyHandling notify) {
this.notify = checkNotNull(notify);
this.notify = requireNonNull(notify);
}
public void setAccountsToNotify(ListMultimap<RecipientType, Account.Id> accountsToNotify) {
this.accountsToNotify = checkNotNull(accountsToNotify);
this.accountsToNotify = requireNonNull(accountsToNotify);
}
/**

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.mail.send;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import com.google.gerrit.common.errors.EmailException;
import com.google.gerrit.extensions.api.changes.RecipientType;
@ -64,7 +64,7 @@ public class RegisterNewEmailSender extends OutgoingEmail {
public String getEmailRegistrationToken() {
if (emailToken == null) {
emailToken = checkNotNull(tokenVerifier.encode(user.getAccountId(), addr), "token");
emailToken = requireNonNull(tokenVerifier.encode(user.getAccountId(), addr), "token");
}
return emailToken;
}

View File

@ -14,8 +14,8 @@
package com.google.gerrit.server.notedb;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.server.notedb.NoteDbTable.CHANGES;
import static java.util.Objects.requireNonNull;
import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
@ -92,7 +92,7 @@ public abstract class AbstractChangeNotes<T> {
} else if (id != null) {
id = id.copy();
}
return new AutoValue_AbstractChangeNotes_LoadHandle(checkNotNull(walk), id);
return new AutoValue_AbstractChangeNotes_LoadHandle(requireNonNull(walk), id);
}
public static LoadHandle missing() {
@ -123,8 +123,8 @@ public abstract class AbstractChangeNotes<T> {
AbstractChangeNotes(
Args args, Change.Id changeId, @Nullable PrimaryStorage primaryStorage, boolean autoRebuild) {
this.args = checkNotNull(args);
this.changeId = checkNotNull(changeId);
this.args = requireNonNull(args);
this.changeId = requireNonNull(changeId);
this.primaryStorage = primaryStorage;
this.autoRebuild =
primaryStorage == PrimaryStorage.REVIEW_DB

View File

@ -16,7 +16,6 @@ package com.google.gerrit.server.notedb;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableSortedMap.toImmutableSortedMap;
import static com.google.gerrit.reviewdb.server.ReviewDbUtil.checkColumns;
@ -27,6 +26,7 @@ import static com.google.gerrit.server.util.time.TimeUtil.truncateToSecond;
import static java.util.Comparator.comparing;
import static java.util.Comparator.naturalOrder;
import static java.util.Comparator.nullsFirst;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
import com.google.auto.value.AutoValue;
@ -203,13 +203,13 @@ public class ChangeBundle {
Iterable<PatchLineComment> patchLineComments,
ReviewerSet reviewers,
Source source) {
this.change = checkNotNull(change);
this.change = requireNonNull(change);
this.changeMessages = changeMessageList(changeMessages);
this.patchSets = ImmutableSortedMap.copyOfSorted(patchSetMap(patchSets));
this.patchSetApprovals = ImmutableMap.copyOf(patchSetApprovalMap(patchSetApprovals));
this.patchLineComments = ImmutableMap.copyOf(patchLineCommentMap(patchLineComments));
this.reviewers = checkNotNull(reviewers);
this.source = checkNotNull(source);
this.reviewers = requireNonNull(reviewers);
this.source = requireNonNull(source);
for (ChangeMessage m : this.changeMessages) {
checkArgument(m.getKey().getParentKey().equals(change.getId()));
@ -706,8 +706,8 @@ public class ChangeBundle {
// purposes, ignore the postSubmit bit in NoteDb in this case.
Timestamp ta = a.getGranted();
Timestamp tb = b.getGranted();
PatchSet psa = checkNotNull(bundleA.patchSets.get(a.getPatchSetId()));
PatchSet psb = checkNotNull(bundleB.patchSets.get(b.getPatchSetId()));
PatchSet psa = requireNonNull(bundleA.patchSets.get(a.getPatchSetId()));
PatchSet psb = requireNonNull(bundleB.patchSets.get(b.getPatchSetId()));
boolean excludeGranted = false;
boolean excludePostSubmit = false;
List<String> exclude = new ArrayList<>(1);

View File

@ -15,11 +15,11 @@
package com.google.gerrit.server.notedb;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.reviewdb.client.RefNames.changeMetaRef;
import static com.google.gerrit.server.notedb.NoteDbTable.CHANGES;
import static java.util.Comparator.comparing;
import static java.util.Objects.requireNonNull;
import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
@ -655,7 +655,8 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
public PatchSet getCurrentPatchSet() {
PatchSet.Id psId = change.currentPatchSetId();
return checkNotNull(getPatchSets().get(psId), "missing current patch set %s", psId.get());
return requireNonNull(
getPatchSets().get(psId), () -> String.format("missing current patch set %s", psId.get()));
}
@VisibleForTesting
@ -761,10 +762,10 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
// to the caller instead of throwing.
logger.atFine().log("Rebuilding change %s failed: %s", getChangeId(), e.getMessage());
args.metrics.autoRebuildFailureCount.increment(CHANGES);
rebuildResult = checkNotNull(r);
checkNotNull(r.newState());
checkNotNull(r.staged());
checkNotNull(r.staged().changeObjects());
rebuildResult = requireNonNull(r);
requireNonNull(r.newState());
requireNonNull(r.staged());
requireNonNull(r.staged().changeObjects());
return LoadHandle.create(
ChangeNotesCommit.newStagedRevWalk(repo, r.staged().changeObjects()),
r.newState().getChangeMetaId());

View File

@ -15,7 +15,6 @@
package com.google.gerrit.server.notedb;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap;
@ -24,6 +23,7 @@ import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.APPROVAL_CODEC;
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.MESSAGE_CODEC;
import static com.google.gerrit.reviewdb.server.ReviewDbCodecs.PATCH_SET_CODEC;
import static com.google.gerrit.server.cache.serialize.ProtoCacheSerializers.toByteString;
import static java.util.Objects.requireNonNull;
import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
@ -123,11 +123,14 @@ public abstract class ChangeNotesState {
boolean workInProgress,
boolean reviewStarted,
@Nullable Change.Id revertOf) {
checkNotNull(
requireNonNull(
metaId,
"metaId is required when passing arguments to create(...). To create an empty %s without"
+ " NoteDb data, use empty(...) instead",
ChangeNotesState.class.getSimpleName());
() ->
String.format(
"metaId is required when passing arguments to create(...)."
+ " To create an empty %s without"
+ " NoteDb data, use empty(...) instead",
ChangeNotesState.class.getSimpleName()));
return builder()
.metaId(metaId)
.changeId(changeId)
@ -303,7 +306,7 @@ public abstract class ChangeNotesState {
abstract Timestamp readOnlyUntil();
Change newChange(Project.NameKey project) {
ChangeColumns c = checkNotNull(columns(), "columns are required");
ChangeColumns c = requireNonNull(columns(), "columns are required");
Change change =
new Change(
c.changeKey(),
@ -351,7 +354,7 @@ public abstract class ChangeNotesState {
}
private void copyNonConstructorColumnsTo(Change change) {
ChangeColumns c = checkNotNull(columns(), "columns are required");
ChangeColumns c = requireNonNull(columns(), "columns are required");
if (c.status() != null) {
change.setStatus(c.status());
}

View File

@ -16,7 +16,6 @@ package com.google.gerrit.server.notedb;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.reviewdb.client.RefNames.changeMetaRef;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_ASSIGNEE;
@ -42,6 +41,7 @@ import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_TOPIC;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_WORK_IN_PROGRESS;
import static com.google.gerrit.server.notedb.NoteDbUtil.sanitizeFooter;
import static java.util.Comparator.comparing;
import static java.util.Objects.requireNonNull;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import com.google.common.annotations.VisibleForTesting;
@ -501,7 +501,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
}
public void setGroups(List<String> groups) {
checkNotNull(groups, "groups may not be null");
requireNonNull(groups, "groups may not be null");
this.groups = groups;
}

View File

@ -15,9 +15,9 @@
package com.google.gerrit.server.notedb;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.reviewdb.client.RefNames.refsDraftComments;
import static com.google.gerrit.server.notedb.NoteDbTable.CHANGES;
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableListMultimap;
@ -184,7 +184,7 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
@Override
protected LoadHandle openHandle(Repository repo) throws NoSuchChangeException, IOException {
if (rebuildResult != null) {
StagedResult sr = checkNotNull(rebuildResult.staged());
StagedResult sr = requireNonNull(rebuildResult.staged());
return LoadHandle.create(
ChangeNotesCommit.newStagedRevWalk(repo, sr.allUsersObjects()),
findNewId(sr.allUsersCommands(), getRefName()));
@ -229,7 +229,7 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
logger.atFine().log(
"Rebuilding change %s via drafts failed: %s", getChangeId(), e.getMessage());
args.metrics.autoRebuildFailureCount.increment(CHANGES);
checkNotNull(r.staged());
requireNonNull(r.staged());
return LoadHandle.create(
ChangeNotesCommit.newStagedRevWalk(repo, r.staged().allUsersObjects()), draftsId(r));
}
@ -249,8 +249,8 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
}
private ObjectId draftsId(NoteDbUpdateManager.Result r) {
checkNotNull(r);
checkNotNull(r.newState());
requireNonNull(r);
requireNonNull(r.newState());
return r.newState().getDraftIds().get(author);
}

View File

@ -15,12 +15,12 @@
package com.google.gerrit.server.notedb;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.reviewdb.client.RefNames.changeMetaRef;
import static com.google.gerrit.reviewdb.client.RefNames.refsDraftComments;
import static com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage.NOTE_DB;
import static com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage.REVIEW_DB;
import static java.util.Objects.requireNonNull;
import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting;
@ -339,10 +339,10 @@ public class NoteDbChangeState {
PrimaryStorage primaryStorage,
Optional<RefState> refState,
Optional<Timestamp> readOnlyUntil) {
this.changeId = checkNotNull(changeId);
this.primaryStorage = checkNotNull(primaryStorage);
this.refState = checkNotNull(refState);
this.readOnlyUntil = checkNotNull(readOnlyUntil);
this.changeId = requireNonNull(changeId);
this.primaryStorage = requireNonNull(primaryStorage);
this.refState = requireNonNull(refState);
this.readOnlyUntil = requireNonNull(readOnlyUntil);
switch (primaryStorage) {
case REVIEW_DB:

View File

@ -16,10 +16,10 @@ package com.google.gerrit.server.notedb;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.reviewdb.client.RefNames.REFS_DRAFT_COMMENTS;
import static com.google.gerrit.server.notedb.NoteDbTable.CHANGES;
import static java.util.Objects.requireNonNull;
import com.google.auto.value.AutoValue;
import com.google.common.collect.HashBasedTable;
@ -186,7 +186,7 @@ public class NoteDbUpdateManager implements AutoCloseable {
"expected reader to be created from %s, but was %s",
ins,
reader.getCreatedFromInserter());
this.repo = checkNotNull(repo);
this.repo = requireNonNull(repo);
if (saveObjects) {
this.inMemIns = new InMemoryInserter(rw.getObjectReader());
@ -199,7 +199,7 @@ public class NoteDbUpdateManager implements AutoCloseable {
this.rw = new RevWalk(tempIns.newReader());
this.finalIns = ins;
this.cmds = checkNotNull(cmds);
this.cmds = requireNonNull(cmds);
this.close = close;
this.saveObjects = saveObjects;
}

View File

@ -15,10 +15,10 @@
package com.google.gerrit.server.notedb;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.reviewdb.client.RefNames.REFS;
import static com.google.gerrit.reviewdb.client.RefNames.REFS_SEQUENCES;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import com.github.rholder.retry.RetryException;
@ -167,9 +167,9 @@ public class RepoSequence {
Runnable afterReadRef,
Retryer<RefUpdate.Result> retryer,
int floor) {
this.repoManager = checkNotNull(repoManager, "repoManager");
this.gitRefUpdated = checkNotNull(gitRefUpdated, "gitRefUpdated");
this.projectName = checkNotNull(projectName, "projectName");
this.repoManager = requireNonNull(repoManager, "repoManager");
this.gitRefUpdated = requireNonNull(gitRefUpdated, "gitRefUpdated");
this.projectName = requireNonNull(projectName, "projectName");
checkArgument(
name != null
@ -179,13 +179,13 @@ public class RepoSequence {
name);
this.refName = RefNames.REFS_SEQUENCES + name;
this.seed = checkNotNull(seed, "seed");
this.seed = requireNonNull(seed, "seed");
this.floor = floor;
checkArgument(batchSize > 0, "expected batchSize > 0, got: %s", batchSize);
this.batchSize = batchSize;
this.afterReadRef = checkNotNull(afterReadRef, "afterReadRef");
this.retryer = checkNotNull(retryer, "retryer");
this.afterReadRef = requireNonNull(afterReadRef, "afterReadRef");
this.retryer = requireNonNull(retryer, "retryer");
counterLock = new ReentrantLock(true);
}

View File

@ -15,11 +15,11 @@
package com.google.gerrit.server.notedb.rebuild;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.reviewdb.client.RefNames.changeMetaRef;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_HASHTAGS;
import static com.google.gerrit.server.notedb.ChangeNoteUtil.FOOTER_PATCH_SET;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.stream.Collectors.toList;
@ -235,7 +235,7 @@ public class ChangeRebuilderImpl extends ChangeRebuilder {
changeId, bundleReader.fromReviewDb(db, changeId)));
}
NoteDbChangeState newNoteDbState =
checkNotNull(NoteDbChangeState.parse(changeId, newNoteDbStateStr));
requireNonNull(NoteDbChangeState.parse(changeId, newNoteDbStateStr));
try {
db.changes()
.atomicUpdate(

View File

@ -15,8 +15,8 @@
package com.google.gerrit.server.notedb.rebuild;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.Lists;
import com.google.gerrit.reviewdb.client.Account;
@ -103,7 +103,7 @@ class EventList<E extends Event> implements Iterable<E> {
}
PatchSet.Id getPatchSetId() {
PatchSet.Id id = checkNotNull(get(0).psId);
PatchSet.Id id = requireNonNull(get(0).psId);
for (int i = 1; i < size(); i++) {
checkState(
get(i).psId.equals(id), "mismatched patch sets in EventList: %s != %s", id, get(i).psId);

View File

@ -14,7 +14,7 @@
package com.google.gerrit.server.notedb.rebuild;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_GC_SECTION;
import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_AUTO;
@ -59,7 +59,7 @@ public class GcAllUsers {
public void run(PrintWriter writer) {
// Print both log messages and progress to given writer.
run(checkNotNull(writer)::println, writer);
run(requireNonNull(writer)::println, writer);
}
private void run(Consumer<String> logOneLine, @Nullable PrintWriter progressWriter) {

View File

@ -15,7 +15,6 @@
package com.google.gerrit.server.notedb.rebuild;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.gerrit.reviewdb.server.ReviewDbUtil.unwrapDb;
import static com.google.gerrit.server.notedb.NotesMigration.SECTION_NOTE_DB;
@ -26,6 +25,7 @@ import static com.google.gerrit.server.notedb.NotesMigrationState.READ_WRITE_WIT
import static com.google.gerrit.server.notedb.NotesMigrationState.WRITE;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Comparator.comparing;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
@ -259,7 +259,7 @@ public class NoteDbMigrator implements AutoCloseable {
* @return this.
*/
public Builder setProgressOut(OutputStream progressOut) {
this.progressOut = checkNotNull(progressOut);
this.progressOut = requireNonNull(progressOut);
return this;
}

View File

@ -14,9 +14,9 @@
package com.google.gerrit.server.patch;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.gerrit.server.ioutil.BasicSerialization.readVarInt32;
import static com.google.gerrit.server.ioutil.BasicSerialization.writeVarInt32;
import static java.util.Objects.requireNonNull;
import java.io.IOException;
import java.io.InputStream;
@ -59,7 +59,7 @@ public class ComparisonType {
}
public int getParentNum() {
checkNotNull(parentNum);
requireNonNull(parentNum);
return parentNum;
}

Some files were not shown because too many files have changed in this diff Show More