mirror of
https://github.com/google/nomulus.git
synced 2025-08-04 00:42:12 +02:00
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:
parent
9cd37189c2
commit
3cf26ff9b6
52 changed files with 155 additions and 133 deletions
|
@ -38,7 +38,7 @@ public class TestDomainPricingCustomLogic extends DomainPricingCustomLogic {
|
|||
|
||||
@Override
|
||||
public FeesAndCredits customizeRenewPrice(RenewPriceParameters priceParameters) {
|
||||
return (priceParameters.domainName().toString().startsWith("costly-renew"))
|
||||
return priceParameters.domainName().toString().startsWith("costly-renew")
|
||||
? addCustomFee(
|
||||
priceParameters.feesAndCredits(), Fee.create(ONE_HUNDRED_BUCKS, FeeType.RENEW))
|
||||
: priceParameters.feesAndCredits();
|
||||
|
@ -46,7 +46,7 @@ public class TestDomainPricingCustomLogic extends DomainPricingCustomLogic {
|
|||
|
||||
@Override
|
||||
public FeesAndCredits customizeTransferPrice(TransferPriceParameters priceParameters) {
|
||||
return (priceParameters.domainName().toString().startsWith("expensive"))
|
||||
return priceParameters.domainName().toString().startsWith("expensive")
|
||||
? addCustomFee(
|
||||
priceParameters.feesAndCredits(), Fee.create(ONE_HUNDRED_BUCKS, FeeType.TRANSFER))
|
||||
: priceParameters.feesAndCredits();
|
||||
|
@ -54,7 +54,7 @@ public class TestDomainPricingCustomLogic extends DomainPricingCustomLogic {
|
|||
|
||||
@Override
|
||||
public FeesAndCredits customizeUpdatePrice(UpdatePriceParameters priceParameters) {
|
||||
return (priceParameters.domainName().toString().startsWith("non-free-update"))
|
||||
return priceParameters.domainName().toString().startsWith("non-free-update")
|
||||
? addCustomFee(
|
||||
priceParameters.feesAndCredits(), Fee.create(ONE_HUNDRED_BUCKS, FeeType.UPDATE))
|
||||
: priceParameters.feesAndCredits();
|
||||
|
|
|
@ -21,7 +21,6 @@ import com.google.common.collect.ImmutableList;
|
|||
import google.registry.keyring.api.KeySerializer;
|
||||
import google.registry.model.server.KmsSecret;
|
||||
import google.registry.model.server.KmsSecretRevision;
|
||||
import google.registry.model.server.KmsSecretRevision.Builder;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.BouncyCastleProviderRule;
|
||||
import org.bouncycastle.openpgp.PGPKeyPair;
|
||||
|
@ -178,7 +177,7 @@ public class KmsKeyringTest {
|
|||
KmsConnection kmsConnection = new FakeKmsConnection();
|
||||
|
||||
KmsSecretRevision secretRevision =
|
||||
new Builder()
|
||||
new KmsSecretRevision.Builder()
|
||||
.setEncryptedValue(kmsConnection.encrypt(secretName, secretValue).ciphertext())
|
||||
.setKmsCryptoKeyVersionName(KmsTestHelper.DUMMY_CRYPTO_KEY_VERSION)
|
||||
.setParent(secretName)
|
||||
|
|
|
@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assert_;
|
|||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
|
@ -84,7 +85,7 @@ public class EntityTestCase {
|
|||
outer: for (String fieldPath : fieldPaths) {
|
||||
// Walk the field path and grab the value referred to on the object using reflection.
|
||||
Object fieldValue = obj;
|
||||
for (String fieldName : fieldPath.split("\\.")) {
|
||||
for (String fieldName : Splitter.on('.').split(fieldPath)) {
|
||||
if (fieldValue == null) {
|
||||
throw new RuntimeException(String.format("field '%s' not found on %s",
|
||||
fieldPath, obj.getClass().getSimpleName()));
|
||||
|
|
|
@ -95,7 +95,7 @@ public final class StaticResourceServlet extends HttpServlet {
|
|||
String prefix = config.getInitParameter("prefix");
|
||||
verify(prefix.startsWith("/"));
|
||||
boolean isDirectory = Files.isDirectory(root);
|
||||
verify(!isDirectory || isDirectory && prefix.endsWith("/"));
|
||||
verify(!isDirectory || (isDirectory && prefix.endsWith("/")));
|
||||
fileServer = Optional.of(new FileServer(root, prefix));
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,6 @@ import google.registry.model.registry.label.PremiumList.PremiumListRevision;
|
|||
import google.registry.model.registry.label.ReservedList;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.model.transfer.TransferData;
|
||||
import google.registry.model.transfer.TransferData.Builder;
|
||||
import google.registry.model.transfer.TransferStatus;
|
||||
import google.registry.tmch.LordnTaskUtils;
|
||||
import java.util.Arrays;
|
||||
|
@ -383,7 +382,8 @@ public class DatastoreHelper {
|
|||
registrar.asBuilder().setAllowedTlds(difference(registrar.getAllowedTlds(), tld)).build());
|
||||
}
|
||||
|
||||
private static Builder createTransferDataBuilder(DateTime requestTime, DateTime expirationTime) {
|
||||
private static TransferData.Builder createTransferDataBuilder(
|
||||
DateTime requestTime, DateTime expirationTime) {
|
||||
return new TransferData.Builder()
|
||||
.setTransferStatus(TransferStatus.PENDING)
|
||||
.setGainingClientId("NewRegistrar")
|
||||
|
@ -585,7 +585,8 @@ public class DatastoreHelper {
|
|||
} else {
|
||||
deleteResource(autorenewPollMessage);
|
||||
}
|
||||
Builder transferDataBuilder = createTransferDataBuilder(requestTime, expirationTime);
|
||||
TransferData.Builder transferDataBuilder =
|
||||
createTransferDataBuilder(requestTime, expirationTime);
|
||||
return persistResource(domain.asBuilder()
|
||||
.setPersistedCurrentSponsorClientId("TheRegistrar")
|
||||
.addStatusValue(StatusValue.PENDING_TRANSFER)
|
||||
|
|
|
@ -49,6 +49,11 @@ public final class FakeServletInputStream extends ServletInputStream {
|
|||
return input.read();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
return input.read(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
input.close();
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.google.appengine.tools.pipeline.impl.servlets.PipelineServlet;
|
|||
import com.google.appengine.tools.pipeline.impl.servlets.TaskHandler;
|
||||
import com.google.apphosting.api.ApiProxy;
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import google.registry.mapreduce.MapreduceRunner;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
|
@ -224,11 +225,11 @@ public abstract class MapreduceTestCase<T> extends ShardableTestCase {
|
|||
throws UnsupportedEncodingException {
|
||||
Map<String, String> result = new HashMap<>();
|
||||
|
||||
String[] params = requestBody.split("&");
|
||||
Iterable<String> params = Splitter.on('&').split(requestBody);
|
||||
for (String param : params) {
|
||||
String[] pair = param.split("=");
|
||||
String name = pair[0];
|
||||
String value = URLDecoder.decode(pair[1], "UTF-8");
|
||||
List<String> pair = Splitter.on('=').splitToList(param);
|
||||
String name = pair.get(0);
|
||||
String value = URLDecoder.decode(pair.get(1), "UTF-8");
|
||||
if (result.containsKey(name)) {
|
||||
throw new IllegalArgumentException("Duplicate parameter: " + requestBody);
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public abstract class CommandTestCase<C extends Command> {
|
|||
public TemporaryFolder tmpDir = new TemporaryFolder();
|
||||
|
||||
@Before
|
||||
public final void beforeCommandTestCase() {
|
||||
public final void beforeCommandTestCase() throws Exception {
|
||||
// Ensure the UNITTEST environment has been set before constructing a new command instance.
|
||||
RegistryToolEnvironment.UNITTEST.setup(systemPropertyRule);
|
||||
command = newCommandInstance();
|
||||
|
@ -212,9 +212,10 @@ public abstract class CommandTestCase<C extends Command> {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected C newCommandInstance() {
|
||||
protected C newCommandInstance() throws Exception {
|
||||
try {
|
||||
return (C) new TypeToken<C>(getClass()){}.getRawType().newInstance();
|
||||
return (C)
|
||||
new TypeToken<C>(getClass()) {}.getRawType().getDeclaredConstructor().newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
@ -298,7 +298,7 @@ public class WhoisReaderTest {
|
|||
|
||||
@Test
|
||||
public void testNameserverLookupByIpWhitespace() throws Exception {
|
||||
assertNsLookup((" \t\t NAMESERVER \t 43.34.12.213 \r\n"), "43.34.12.213");
|
||||
assertNsLookup(" \t\t NAMESERVER \t 43.34.12.213 \r\n", "43.34.12.213");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -51,14 +51,14 @@ public class DateAdapterTest {
|
|||
|
||||
@Test
|
||||
public void testUnmarshalEmpty() {
|
||||
assertThat((new DateAdapter()).unmarshal(null)).isNull();
|
||||
assertThat((new DateAdapter()).unmarshal("")).isNull();
|
||||
assertThat(new DateAdapter().unmarshal(null)).isNull();
|
||||
assertThat(new DateAdapter().unmarshal("")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalInvalid() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> assertThat((new DateAdapter()).unmarshal("oh my goth")).isNull());
|
||||
() -> assertThat(new DateAdapter().unmarshal("oh my goth")).isNull());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class UtcDateTimeAdapterTest {
|
|||
|
||||
@Test
|
||||
public void testMarshalEmpty() {
|
||||
assertThat((new UtcDateTimeAdapter()).marshal(null)).isEmpty();
|
||||
assertThat(new UtcDateTimeAdapter().marshal(null)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -60,14 +60,14 @@ public class UtcDateTimeAdapterTest {
|
|||
|
||||
@Test
|
||||
public void testUnmarshalEmpty() {
|
||||
assertThat((new UtcDateTimeAdapter()).unmarshal(null)).isNull();
|
||||
assertThat((new UtcDateTimeAdapter()).unmarshal("")).isNull();
|
||||
assertThat(new UtcDateTimeAdapter().unmarshal(null)).isNull();
|
||||
assertThat(new UtcDateTimeAdapter().unmarshal("")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalInvalid() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> assertThat((new UtcDateTimeAdapter()).unmarshal("oh my goth")).isNull());
|
||||
() -> assertThat(new UtcDateTimeAdapter().unmarshal("oh my goth")).isNull());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue