Fix various Error Prone errors that were found by the FOSS build

Most common:
- Unnecessary parentheses and operator precedence clarify (self-explanatory)
- Reference equality--there were a few instances of using == or != improperly
- Qualification of Builder (and similar) imports so that it's clear which type of Builder we're referring to
- Marking some immutable classes with @Immutable since EP desires that all enums be deeply immutable
- String.split() having "surprising behavior"

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=230971531
This commit is contained in:
gbrodman 2019-01-25 14:39:57 -08:00 committed by Ben McIlwain
parent 9cd37189c2
commit 3cf26ff9b6
52 changed files with 155 additions and 133 deletions

View file

@ -48,9 +48,10 @@ final class CanonicalizeLabelsCommand implements Command {
@Override
public void run() throws IOException {
Set<String> labels = new TreeSet<>();
for (String label : mainParameters.isEmpty()
? CharStreams.readLines(new InputStreamReader(stdin))
: Files.readLines(new File(mainParameters.get(0)), UTF_8)) {
for (String label :
mainParameters.isEmpty()
? CharStreams.readLines(new InputStreamReader(stdin, UTF_8))
: Files.readLines(new File(mainParameters.get(0)), UTF_8)) {
label = label.trim();
if (label.startsWith("-")) {
label = label.substring(1);

View file

@ -35,7 +35,7 @@ class CommandUtilities {
HOST(HostResource.class),
DOMAIN(DomainBase.class);
private Class<? extends EppResource> clazz;
private final Class<? extends EppResource> clazz;
ResourceType(Class<? extends EppResource> clazz) {
this.clazz = clazz;

View file

@ -15,6 +15,7 @@
package google.registry.tools;
import static google.registry.util.ResourceUtils.readResourceBytes;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
@ -67,7 +68,7 @@ final class LoggingParameters {
// Add an extra leading newline in case base properties file does not end in a newline.
String customProperties = "\n" + Joiner.on('\n').join(configLines);
ByteSource logConfig =
ByteSource.concat(baseConfig, ByteSource.wrap(customProperties.getBytes()));
ByteSource.concat(baseConfig, ByteSource.wrap(customProperties.getBytes(UTF_8)));
try (InputStream input = logConfig.openStream()) {
LogManager.getLogManager().readConfiguration(input);
}

View file

@ -32,7 +32,6 @@ import com.google.common.collect.ImmutableSet;
import google.registry.model.common.GaeUserIdConverter;
import google.registry.model.registrar.Registrar;
import google.registry.model.registrar.RegistrarContact;
import google.registry.model.registrar.RegistrarContact.Builder;
import google.registry.tools.params.OptionalPhoneNumberParameter;
import google.registry.tools.params.PathParameter;
import java.io.IOException;
@ -235,7 +234,7 @@ final class RegistrarContactCommand extends MutatingCommand {
private RegistrarContact createContact(Registrar registrar) {
checkArgument(!isNullOrEmpty(name), "--name is required when --mode=CREATE");
checkArgument(!isNullOrEmpty(email), "--email is required when --mode=CREATE");
Builder builder = new RegistrarContact.Builder();
RegistrarContact.Builder builder = new RegistrarContact.Builder();
builder.setParent(registrar);
builder.setName(name);
builder.setEmailAddress(email);
@ -267,7 +266,7 @@ final class RegistrarContactCommand extends MutatingCommand {
private RegistrarContact updateContact(RegistrarContact contact, Registrar registrar) {
checkNotNull(registrar);
checkNotNull(email, "--email is required when --mode=UPDATE");
Builder builder = contact.asBuilder();
RegistrarContact.Builder builder = contact.asBuilder();
builder.setParent(registrar);
if (!isNullOrEmpty(name)) {
builder.setName(name);

View file

@ -21,7 +21,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import com.beust.jcommander.Parameters;
import com.google.common.base.Strings;
import google.registry.model.registry.label.ReservedList;
import google.registry.model.registry.label.ReservedList.Builder;
import google.registry.util.SystemClock;
import java.nio.file.Files;
import java.util.Optional;
@ -36,10 +35,12 @@ final class UpdateReservedListCommand extends CreateOrUpdateReservedListCommand
Optional<ReservedList> existing = ReservedList.get(name);
checkArgument(
existing.isPresent(), "Could not update reserved list %s because it doesn't exist.", name);
Builder updated = existing.get()
.asBuilder()
.setReservedListMapFromLines(Files.readAllLines(input, UTF_8))
.setLastUpdateTime(new SystemClock().nowUtc());
ReservedList.Builder updated =
existing
.get()
.asBuilder()
.setReservedListMapFromLines(Files.readAllLines(input, UTF_8))
.setLastUpdateTime(new SystemClock().nowUtc());
if (shouldPublish != null) {
updated.setShouldPublish(shouldPublish);
}

View file

@ -15,12 +15,12 @@
package google.registry.tools;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.copyOf;
import static com.google.common.collect.Sets.difference;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Ordering;
import google.registry.keyring.api.Keyring;
import google.registry.rde.Ghostryde;
@ -40,7 +40,6 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
@ -141,17 +140,19 @@ final class ValidateEscrowDepositCommand implements Command {
}
System.out.println();
boolean good = true;
List<String> badHostnameRefs = copyOf(difference(hostnameRefs, hostnames));
ImmutableList<String> badHostnameRefs =
ImmutableList.copyOf(difference(hostnameRefs, hostnames));
if (!badHostnameRefs.isEmpty()) {
System.out.printf("Bad host refs: %s\n", Joiner.on(", ").join(badHostnameRefs));
good = false;
}
List<String> badContactRefs = copyOf(difference(contactRefs, contacts));
ImmutableList<String> badContactRefs = ImmutableList.copyOf(difference(contactRefs, contacts));
if (!badContactRefs.isEmpty()) {
System.out.printf("Bad contact refs: %s\n", Joiner.on(", ").join(badContactRefs));
good = false;
}
List<String> badRegistrarRefs = copyOf(difference(registrarRefs, registrars));
ImmutableList<String> badRegistrarRefs =
ImmutableList.copyOf(difference(registrarRefs, registrars));
if (!badRegistrarRefs.isEmpty()) {
System.out.printf("Bad registrar refs: %s\n", Joiner.on(", ").join(badRegistrarRefs));
good = false;

View file

@ -21,7 +21,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
import com.beust.jcommander.Parameters;
import com.google.common.collect.ImmutableList;
import google.registry.model.registrar.Registrar;
import google.registry.model.registrar.Registrar.Builder;
import google.registry.model.registrar.RegistrarAddress;
import google.registry.tools.MutatingCommand;
import java.util.Objects;
@ -40,7 +39,7 @@ public class PopulateNullRegistrarFieldsCommand extends MutatingCommand {
@Override
protected void init() {
for (Registrar registrar : ofy().load().type(Registrar.class).ancestor(getCrossTldKey())) {
Builder changeBuilder = registrar.asBuilder();
Registrar.Builder changeBuilder = registrar.asBuilder();
changeBuilder.setRegistrarName(
firstNonNull(registrar.getRegistrarName(), registrar.getClientId()));

View file

@ -101,6 +101,7 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA
@Inject @Config("gcsBufferSize") int gcsBufferSize;
@Inject @Config("commitLogDatastoreRetention") Duration datastoreRetention;
@Inject @Config("dnsDefaultATtl") Duration dnsDefaultATtl;
@SuppressWarnings("DurationVariableWithUnits") // false-positive Error Prone check
@Inject @Config("dnsDefaultNsTtl") Duration dnsDefaultNsTtl;
@Inject @Config("dnsDefaultDsTtl") Duration dnsDefaultDsTtl;
@Inject Clock clock;
@ -291,14 +292,15 @@ public class GenerateZoneFilesAction implements Runnable, JsonActionRunner.JsonA
loadAtPointInTime(nameserver, exportTime).now().getFullyQualifiedHostName()));
}
for (DelegationSignerData dsData : domain.getDsData()) {
result.append(String.format(
DS_FORMAT,
domainLabel,
dnsDefaultDsTtl.getStandardSeconds(),
dsData.getKeyTag(),
dsData.getAlgorithm(),
dsData.getDigestType(),
base16().encode((dsData.getDigest()))));
result.append(
String.format(
DS_FORMAT,
domainLabel,
dnsDefaultDsTtl.getStandardSeconds(),
dsData.getKeyTag(),
dsData.getAlgorithm(),
dsData.getDigestType(),
base16().encode(dsData.getDigest())));
}
return result.toString();
}