mirror of
https://github.com/google/nomulus.git
synced 2025-05-21 11:49:37 +02:00
Fix some issues caught by IntelliJ static code analysis
The most common issues were: * Arrays.asList() shouldn't be called with a single parameter. * Broken Javadoc @links. * Unnecessary casts and type declarations. * Unnecessary unused variable initializations. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=230994311
This commit is contained in:
parent
3cf26ff9b6
commit
c6e58d3bff
39 changed files with 132 additions and 165 deletions
|
@ -29,7 +29,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
|
|||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static google.registry.util.DateTimeUtils.isAtOrAfter;
|
||||
import static java.nio.channels.Channels.newOutputStream;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Comparator.comparingLong;
|
||||
|
||||
import com.google.appengine.tools.cloudstorage.GcsFileOptions;
|
||||
|
@ -208,7 +207,7 @@ public final class ExportCommitLogDiffAction implements Runnable {
|
|||
ImmutableList.Builder<Iterable<? extends ImmutableObject>> entities =
|
||||
new ImmutableList.Builder<>();
|
||||
for (CommitLogManifest manifest : chunk) {
|
||||
entities.add(asList(manifest));
|
||||
entities.add(ImmutableList.of(manifest));
|
||||
entities.add(ofy().load().type(CommitLogMutation.class).ancestor(manifest));
|
||||
}
|
||||
for (ImmutableObject entity : concat(entities.build())) {
|
||||
|
|
|
@ -19,13 +19,13 @@ import static com.google.common.collect.ImmutableList.toImmutableList;
|
|||
import static com.google.common.collect.Iterators.peekingIterator;
|
||||
import static google.registry.backup.BackupUtils.createDeserializingIterator;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import com.google.appengine.api.datastore.DatastoreService;
|
||||
import com.google.appengine.api.datastore.Entity;
|
||||
import com.google.appengine.api.datastore.EntityTranslator;
|
||||
import com.google.appengine.tools.cloudstorage.GcsFileMetadata;
|
||||
import com.google.appengine.tools.cloudstorage.GcsService;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.PeekingIterator;
|
||||
import com.google.common.collect.Streams;
|
||||
|
@ -106,7 +106,7 @@ public class RestoreCommitLogsAction implements Runnable {
|
|||
PeekingIterator<ImmutableObject> commitLogs =
|
||||
peekingIterator(createDeserializingIterator(input));
|
||||
lastCheckpoint = (CommitLogCheckpoint) commitLogs.next();
|
||||
saveOfy(asList(lastCheckpoint)); // Save the checkpoint itself.
|
||||
saveOfy(ImmutableList.of(lastCheckpoint)); // Save the checkpoint itself.
|
||||
while (commitLogs.hasNext()) {
|
||||
CommitLogManifest manifest = restoreOneTransaction(commitLogs);
|
||||
bucketTimestamps.put(manifest.getBucketId(), manifest.getCommitTime());
|
||||
|
|
|
@ -61,7 +61,7 @@ import org.joda.time.Duration;
|
|||
* {@link ReadDnsQueueAction}, which is run as a cron job with running time shorter than the cron
|
||||
* repeat time - meaning there should never be two instances running at once.
|
||||
*
|
||||
* @see google.registry.config.RegistryConfig#provideReadDnsQueueRuntime
|
||||
* @see google.registry.config.RegistryConfig.ConfigModule#provideReadDnsQueueRuntime
|
||||
*/
|
||||
public class DnsQueue {
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ public class CheckBackupAction implements Runnable {
|
|||
throw e;
|
||||
} catch (Throwable e) {
|
||||
throw new InternalServerErrorException(
|
||||
String.format("Exception occurred while checking datastore exports."), e);
|
||||
"Exception occurred while checking datastore exports.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@ public final class ComparatorKeyring extends ComparingInvocationHandler<Keyring>
|
|||
return "null";
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder("");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (byte b : a.getFingerprint()) {
|
||||
builder.append(String.format("%02x:", b));
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ public final class KmsUpdater {
|
|||
* Encrypts updated secrets using KMS. If the configured {@code KeyRing} or {@code CryptoKey}
|
||||
* associated with a secret doesn't exist, they will first be created.
|
||||
*
|
||||
* @see google.registry.config.RegistryConfigSettings#kms
|
||||
* @see google.registry.config.RegistryConfigSettings.Kms
|
||||
*/
|
||||
private ImmutableMap<String, EncryptResponse> encryptValues(Map<String, byte[]> keyValues) {
|
||||
ImmutableMap.Builder<String, EncryptResponse> encryptedValues = new ImmutableMap.Builder<>();
|
||||
|
|
|
@ -369,15 +369,8 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable {
|
|||
Streams.stream(keys).map(key -> (Key<EppResource>) key).collect(toImmutableList());
|
||||
|
||||
// Typing shenanigans are required to return the map with the correct required generic type.
|
||||
return ofy()
|
||||
.load()
|
||||
.keys(typedKeys)
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(
|
||||
ImmutableMap
|
||||
.<Map.Entry<Key<EppResource>, EppResource>, Key<? extends EppResource>, EppResource>
|
||||
toImmutableMap(Entry::getKey, Entry::getValue));
|
||||
return ofy().load().keys(typedKeys).entrySet().stream()
|
||||
.collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -33,11 +33,10 @@ public final class SchemaVersion {
|
|||
*/
|
||||
private static SortedSet<Class<?>> getAllPersistedTypes() {
|
||||
SortedSet<Class<?>> persistedTypes = new TreeSet<>(Ordering.usingToString());
|
||||
Queue<Class<?>> queue = new ArrayDeque<>();
|
||||
// Do a breadth-first search for persisted types, starting with @Entity types and expanding each
|
||||
// ImmutableObject by querying it for all its persisted field types.
|
||||
persistedTypes.addAll(EntityClasses.ALL_CLASSES);
|
||||
queue.addAll(persistedTypes);
|
||||
Queue<Class<?>> queue = new ArrayDeque<>(persistedTypes);
|
||||
while (!queue.isEmpty()) {
|
||||
Class<?> clazz = queue.remove();
|
||||
if (ImmutableObject.class.isAssignableFrom(clazz)) {
|
||||
|
|
|
@ -60,7 +60,7 @@ abstract class AugmentedDeleter implements Deleter {
|
|||
|
||||
@Override
|
||||
public Result<Void> key(Key<?> key) {
|
||||
handleDeletion(Arrays.asList(key));
|
||||
handleDeletion(ImmutableList.of(key));
|
||||
return delegate.keys(key);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ import javax.xml.bind.annotation.XmlNsForm;
|
|||
import javax.xml.bind.annotation.XmlSchema;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
/**
|
||||
/*
|
||||
* This package defines all entities which are managed via EPP XML and persisted to the Datastore
|
||||
* via Objectify.
|
||||
*
|
||||
|
|
|
@ -126,7 +126,7 @@ public class TmchXmlSignature {
|
|||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Signature failed core validation\n");
|
||||
boolean sv = signature.getSignatureValue().validate(context);
|
||||
builder.append("Signature validation status: " + sv + "\n");
|
||||
builder.append(String.format("Signature validation status: %s\n", sv));
|
||||
for (Reference ref : references) {
|
||||
builder.append("references[");
|
||||
builder.append(ref.getURI());
|
||||
|
|
|
@ -12,12 +12,12 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.tools;
|
||||
|
||||
/**
|
||||
* Marker interface for commands that use the remote api.
|
||||
*
|
||||
* <p>Just implementing this is sufficient to use the remote api; {@link RegistryTool} will
|
||||
* install it as needed.
|
||||
* <p>Just implementing this is sufficient to use the remote api; {@link RegistryTool} will install
|
||||
* it as needed.
|
||||
*/
|
||||
package google.registry.tools;
|
||||
|
||||
interface CommandWithRemoteApi extends Command {}
|
||||
|
|
|
@ -43,10 +43,12 @@ final class GetResourceByKeyCommand implements CommandWithRemoteApi {
|
|||
public void run() {
|
||||
for (String keyString : mainParameters) {
|
||||
System.out.println("\n");
|
||||
Key<EppResource> resourceKey = checkNotNull(
|
||||
Key.<EppResource>create(keyString), "Could not parse key string: " + keyString);
|
||||
EppResource resource = checkNotNull(
|
||||
ofy().load().key(resourceKey).now(), "Could not load resource for key: " + resourceKey);
|
||||
Key<EppResource> resourceKey =
|
||||
checkNotNull(Key.create(keyString), "Could not parse key string: " + keyString);
|
||||
EppResource resource =
|
||||
checkNotNull(
|
||||
ofy().load().key(resourceKey).now(),
|
||||
"Could not load resource for key: " + resourceKey);
|
||||
System.out.println(expand ? resource.toHydratedString() : resource.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ final class ValidateEscrowDepositCommand implements Command {
|
|||
}
|
||||
}
|
||||
System.out.println();
|
||||
System.out.printf("Contents:\n");
|
||||
System.out.println("Contents:");
|
||||
for (Map.Entry<String, Long> count : counts.entrySet()) {
|
||||
System.out.printf(" - %s: %,d %s\n",
|
||||
count.getKey(),
|
||||
|
@ -158,9 +158,9 @@ final class ValidateEscrowDepositCommand implements Command {
|
|||
good = false;
|
||||
}
|
||||
if (good) {
|
||||
System.out.printf("RDE deposit is XML schema valid\n");
|
||||
System.out.println("RDE deposit is XML schema valid");
|
||||
} else {
|
||||
System.out.printf("RDE deposit is XML schema valid but has bad references\n");
|
||||
System.out.println("RDE deposit is XML schema valid but has bad references");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -83,13 +83,13 @@ public class CreateGroupsAction implements Runnable {
|
|||
// that type.
|
||||
groupsConnection.createGroup(groupKey);
|
||||
groupsConnection.addMemberToGroup(parentGroup, groupKey, Role.MEMBER);
|
||||
return Optional.<Exception>empty();
|
||||
return Optional.empty();
|
||||
} catch (Exception e) {
|
||||
return Optional.of(e);
|
||||
}
|
||||
});
|
||||
// Return the correct server response based on the results of the group creations.
|
||||
if (results.stream().filter(Optional::isPresent).count() > 0) {
|
||||
if (results.stream().anyMatch(Optional::isPresent)) {
|
||||
StringWriter responseString = new StringWriter();
|
||||
PrintWriter responseWriter = new PrintWriter(responseString);
|
||||
for (int i = 0; i < results.size(); i++) {
|
||||
|
|
|
@ -31,8 +31,8 @@ import javax.annotation.concurrent.NotThreadSafe;
|
|||
/**
|
||||
* Exception thrown when a form field contains a bad value.
|
||||
*
|
||||
* <p>You can safely throw {@code FormFieldException} from within your validator functions, and
|
||||
* the field name will automatically be propagated into the exception object for you.
|
||||
* <p>You can safely throw {@code FormFieldException} from within your validator functions, and the
|
||||
* field name will automatically be propagated into the exception object for you.
|
||||
*
|
||||
* <p>The way that field names work is a bit complicated, because we need to support complex nested
|
||||
* field names like {@code foo[3].bar}. So what happens is the original exception will be thrown by
|
||||
|
@ -41,9 +41,9 @@ import javax.annotation.concurrent.NotThreadSafe;
|
|||
* name of that component. Then when the exception reaches the user, the {@link #getFieldName()}
|
||||
* method will produce the fully-qualified field name.
|
||||
*
|
||||
* <p>This propagation mechanism is also very important when writing
|
||||
* {@link FormField.Builder#transform(com.google.common.base.Function) transform} functions, which
|
||||
* oftentimes will not know the name of the field they're validating.
|
||||
* <p>This propagation mechanism is also very important when writing {@link
|
||||
* FormField.Builder#transform} functions, which oftentimes will not know the name of the field
|
||||
* they're validating.
|
||||
*/
|
||||
@NotThreadSafe
|
||||
@SuppressWarnings("OverrideThrowableToString")
|
||||
|
|
|
@ -50,27 +50,27 @@ public class CollectionUtils {
|
|||
|
||||
/** Turns a null set into an empty set. JAXB leaves lots of null sets lying around. */
|
||||
public static <T> Set<T> nullToEmpty(@Nullable Set<T> potentiallyNull) {
|
||||
return firstNonNull(potentiallyNull, ImmutableSet.<T>of());
|
||||
return firstNonNull(potentiallyNull, ImmutableSet.of());
|
||||
}
|
||||
|
||||
/** Turns a null list into an empty list. */
|
||||
public static <T> List<T> nullToEmpty(@Nullable List<T> potentiallyNull) {
|
||||
return firstNonNull(potentiallyNull, ImmutableList.<T>of());
|
||||
return firstNonNull(potentiallyNull, ImmutableList.of());
|
||||
}
|
||||
|
||||
/** Turns a null map into an empty map. */
|
||||
public static <T, U> Map<T, U> nullToEmpty(@Nullable Map<T, U> potentiallyNull) {
|
||||
return firstNonNull(potentiallyNull, ImmutableMap.<T, U>of());
|
||||
return firstNonNull(potentiallyNull, ImmutableMap.of());
|
||||
}
|
||||
|
||||
/** Turns a null multimap into an empty multimap. */
|
||||
public static <T, U> Multimap<T, U> nullToEmpty(@Nullable Multimap<T, U> potentiallyNull) {
|
||||
return firstNonNull(potentiallyNull, ImmutableMultimap.<T, U>of());
|
||||
return firstNonNull(potentiallyNull, ImmutableMultimap.of());
|
||||
}
|
||||
|
||||
/** Turns a null sorted map into an empty sorted map.. */
|
||||
public static <T, U> SortedMap<T, U> nullToEmpty(@Nullable SortedMap<T, U> potentiallyNull) {
|
||||
return firstNonNull(potentiallyNull, ImmutableSortedMap.<T, U>of());
|
||||
return firstNonNull(potentiallyNull, ImmutableSortedMap.of());
|
||||
}
|
||||
|
||||
/** Defensive copy helper for {@link Set}. */
|
||||
|
|
|
@ -14,13 +14,12 @@
|
|||
|
||||
package google.registry.util;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import com.google.appengine.api.taskqueue.Queue;
|
||||
import com.google.appengine.api.taskqueue.TaskHandle;
|
||||
import com.google.appengine.api.taskqueue.TaskOptions;
|
||||
import com.google.appengine.api.taskqueue.TransientFailureException;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import java.io.Serializable;
|
||||
|
@ -65,7 +64,7 @@ public class TaskQueueUtils implements Serializable {
|
|||
* @return successfully enqueued task
|
||||
*/
|
||||
public TaskHandle enqueue(Queue queue, TaskOptions task) {
|
||||
return enqueue(queue, asList(task)).get(0);
|
||||
return enqueue(queue, ImmutableList.of(task)).get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue