mirror of
https://github.com/google/nomulus
synced 2026-09-19 06:32:00 +00:00
Fix some low-hanging code quality issue fruits (#1047)
* Fix some low-hanging code quality issue fruits These include problems such as: use of raw types, unnecessary throw clauses, unused variables, and more.
This commit is contained in:
@@ -505,7 +505,7 @@ public class DatastoreV1 {
|
||||
}
|
||||
|
||||
@StartBundle
|
||||
public void startBundle(StartBundleContext c) throws Exception {
|
||||
public void startBundle(StartBundleContext c) {
|
||||
datastore =
|
||||
datastoreFactory.getDatastore(
|
||||
c.getPipelineOptions(), v1Options.getProjectId(), v1Options.getLocalhost());
|
||||
@@ -548,7 +548,7 @@ public class DatastoreV1 {
|
||||
}
|
||||
|
||||
@StartBundle
|
||||
public void startBundle(StartBundleContext c) throws Exception {
|
||||
public void startBundle(StartBundleContext c) {
|
||||
datastore =
|
||||
datastoreFactory.getDatastore(
|
||||
c.getPipelineOptions(), options.getProjectId(), options.getLocalhost());
|
||||
@@ -556,7 +556,7 @@ public class DatastoreV1 {
|
||||
}
|
||||
|
||||
@ProcessElement
|
||||
public void processElement(ProcessContext c) throws Exception {
|
||||
public void processElement(ProcessContext c) {
|
||||
Query query = c.element();
|
||||
|
||||
// If query has a user set limit, then do not split.
|
||||
@@ -626,7 +626,7 @@ public class DatastoreV1 {
|
||||
}
|
||||
|
||||
@StartBundle
|
||||
public void startBundle(StartBundleContext c) throws Exception {
|
||||
public void startBundle(StartBundleContext c) {
|
||||
datastore =
|
||||
datastoreFactory.getDatastore(
|
||||
c.getPipelineOptions(), options.getProjectId(), options.getLocalhost());
|
||||
|
||||
@@ -93,7 +93,7 @@ public final class BackupPaths {
|
||||
checkArgument(!isNullOrEmpty(exportDir), "Null or empty exportDir.");
|
||||
checkArgument(!isNullOrEmpty(kind), "Null or empty kind.");
|
||||
checkArgument(shard >= 0, "Negative shard %s not allowed.", shard);
|
||||
return String.format(EXPORT_PATTERN_TEMPLATE, exportDir, kind, Integer.toString(shard));
|
||||
return String.format(EXPORT_PATTERN_TEMPLATE, exportDir, kind, shard);
|
||||
}
|
||||
|
||||
/** Returns an {@link ImmutableList} of regex patterns that match all CommitLog files. */
|
||||
|
||||
@@ -337,7 +337,7 @@ public class DomainContent extends EppResource
|
||||
|
||||
@PostLoad
|
||||
@SuppressWarnings("UnusedMethod")
|
||||
private final void postLoad() {
|
||||
private void postLoad() {
|
||||
// Reconstitute the contact list.
|
||||
ImmutableSet.Builder<DesignatedContact> contactsBuilder = new ImmutableSet.Builder<>();
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class HibernateSchemaExporter {
|
||||
}
|
||||
|
||||
/** Exports DDL script to the {@code outputFile} for the given {@code entityClasses}. */
|
||||
public void export(ImmutableList<Class> entityClasses, File outputFile) {
|
||||
public void export(ImmutableList<Class<?>> entityClasses, File outputFile) {
|
||||
// Configure Hibernate settings.
|
||||
Map<String, String> settings = Maps.newHashMap();
|
||||
settings.put(Environment.DIALECT, NomulusPostgreSQLDialect.class.getName());
|
||||
@@ -85,7 +85,7 @@ public class HibernateSchemaExporter {
|
||||
}
|
||||
}
|
||||
|
||||
private ImmutableList<Class> findAllConverters() {
|
||||
private ImmutableList<Class<?>> findAllConverters() {
|
||||
return PersistenceXmlUtility.getManagedClasses().stream()
|
||||
.filter(AttributeConverter.class::isAssignableFrom)
|
||||
.collect(toImmutableList());
|
||||
|
||||
@@ -41,7 +41,7 @@ public class PersistenceXmlUtility {
|
||||
}
|
||||
|
||||
/** Returns all managed classes defined in persistence.xml. */
|
||||
public static ImmutableList<Class> getManagedClasses() {
|
||||
public static ImmutableList<Class<?>> getManagedClasses() {
|
||||
return getParsedPersistenceXmlDescriptor().getManagedClassNames().stream()
|
||||
.map(
|
||||
className -> {
|
||||
|
||||
@@ -35,7 +35,6 @@ public class DateTimeConverter implements AttributeConverter<DateTime, Timestamp
|
||||
@Override
|
||||
@Nullable
|
||||
public DateTime convertToEntityAttribute(@Nullable Timestamp dbData) {
|
||||
DateTime result = dbData == null ? null : new DateTime(dbData.getTime(), UTC);
|
||||
return result;
|
||||
return (dbData == null) ? null : new DateTime(dbData.getTime(), UTC);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ public interface JpaTransactionManager extends TransactionManager {
|
||||
void transactNoRetry(Runnable work);
|
||||
|
||||
/** Deletes the entity by its id, throws exception if the entity is not deleted. */
|
||||
public abstract <T> void assertDelete(VKey<T> key);
|
||||
<T> void assertDelete(VKey<T> key);
|
||||
|
||||
/**
|
||||
* Releases all resources and shuts down.
|
||||
|
||||
@@ -165,7 +165,7 @@ public class Transaction extends ImmutableObject implements Buildable {
|
||||
enum Type {
|
||||
UPDATE,
|
||||
DELETE
|
||||
};
|
||||
}
|
||||
|
||||
/** Write the changes in the mutation to the datastore. */
|
||||
public abstract void writeToDatastore();
|
||||
|
||||
@@ -54,7 +54,7 @@ public abstract class SqlUser {
|
||||
* Credential for RegistryTool. This is temporary, and will be removed when tool users are
|
||||
* assigned their personal credentials.
|
||||
*/
|
||||
TOOL;
|
||||
TOOL
|
||||
}
|
||||
|
||||
/** Information of a RobotUser for privilege management purposes. */
|
||||
|
||||
@@ -32,7 +32,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import javax.inject.Inject;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPKeyPair;
|
||||
import org.bouncycastle.openpgp.PGPPrivateKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
@@ -79,12 +78,12 @@ public final class BrdaCopyAction implements Runnable {
|
||||
public void run() {
|
||||
try {
|
||||
copyAsRyde();
|
||||
} catch (IOException | PGPException e) {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void copyAsRyde() throws IOException, PGPException {
|
||||
private void copyAsRyde() throws IOException {
|
||||
String prefix = RdeNamingUtils.makeRydeFilename(tld, watermark, THIN, 1, 0);
|
||||
GcsFilename xmlFilename = new GcsFilename(stagingBucket, prefix + ".xml.ghostryde");
|
||||
GcsFilename xmlLengthFilename = new GcsFilename(stagingBucket, prefix + ".xml.length");
|
||||
|
||||
@@ -37,7 +37,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import javax.annotation.Nullable;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPrivateKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.joda.time.DateTime;
|
||||
@@ -118,11 +117,8 @@ public final class Ghostryde {
|
||||
static final String INNER_FILENAME = "file.xml";
|
||||
static final DateTime INNER_MODIFICATION_TIME = DateTime.parse("2000-01-01TZ");
|
||||
|
||||
/**
|
||||
* Creates a ghostryde file from an in-memory byte array.
|
||||
*/
|
||||
public static byte[] encode(byte[] data, PGPPublicKey key)
|
||||
throws IOException, PGPException {
|
||||
/** Creates a ghostryde file from an in-memory byte array. */
|
||||
public static byte[] encode(byte[] data, PGPPublicKey key) throws IOException {
|
||||
checkNotNull(data, "data");
|
||||
checkArgument(key.isEncryptionKey(), "not an encryption key");
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
@@ -132,11 +128,8 @@ public final class Ghostryde {
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deciphers a ghostryde file from an in-memory byte array.
|
||||
*/
|
||||
public static byte[] decode(byte[] data, PGPPrivateKey key)
|
||||
throws IOException, PGPException {
|
||||
/** Deciphers a ghostryde file from an in-memory byte array. */
|
||||
public static byte[] decode(byte[] data, PGPPrivateKey key) throws IOException {
|
||||
checkNotNull(data, "data");
|
||||
ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
|
||||
@@ -42,7 +42,6 @@ import google.registry.request.auth.Auth;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import javax.inject.Inject;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPrivateKey;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
@@ -96,7 +95,7 @@ public final class RdeReportAction implements Runnable, EscrowTask {
|
||||
}
|
||||
|
||||
/** Reads and decrypts the XML file from cloud storage. */
|
||||
private byte[] readReportFromGcs(GcsFilename reportFilename) throws IOException, PGPException {
|
||||
private byte[] readReportFromGcs(GcsFilename reportFilename) throws IOException {
|
||||
try (InputStream gcsInput = gcsUtils.openInputStream(reportFilename);
|
||||
InputStream ghostrydeDecoder = Ghostryde.decoder(gcsInput, stagingDecryptionKey)) {
|
||||
return ByteStreams.toByteArray(ghostrydeDecoder);
|
||||
|
||||
@@ -74,9 +74,8 @@ public final class RydeEncoder extends FilterOutputStream {
|
||||
OutputStream kompressor = closer.register(openCompressor(encryptLayer));
|
||||
OutputStream fileLayer =
|
||||
closer.register(openPgpFileWriter(kompressor, filenamePrefix + ".tar", modified));
|
||||
OutputStream tarLayer =
|
||||
this.out =
|
||||
closer.register(openTarWriter(fileLayer, dataLength, filenamePrefix + ".xml", modified));
|
||||
this.out = tarLayer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -128,7 +128,7 @@ public final class ActivityReportingQueryBuilder implements QueryBuilder {
|
||||
return queriesBuilder.build();
|
||||
}
|
||||
|
||||
public void prepareForQuery(YearMonth yearMonth) throws Exception {
|
||||
public void prepareForQuery(YearMonth yearMonth) throws InterruptedException {
|
||||
dnsCountQueryCoordinator.prepareForQuery(yearMonth);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -35,5 +35,5 @@ public class BasicDnsCountQueryCoordinator implements DnsCountQueryCoordinator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareForQuery(YearMonth yearMonth) throws Exception {}
|
||||
public void prepareForQuery(YearMonth yearMonth) {}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public interface DnsCountQueryCoordinator {
|
||||
/**
|
||||
* Class to carry parameters for a new coordinator.
|
||||
*
|
||||
* If your report query requires any additional parameters, add them here.
|
||||
* <p>If your report query requires any additional parameters, add them here.
|
||||
*/
|
||||
class Params {
|
||||
public BigqueryConnection bigquery;
|
||||
@@ -49,6 +49,12 @@ public interface DnsCountQueryCoordinator {
|
||||
/** Creates the string used to query bigtable for DNS count information. */
|
||||
String createQuery(YearMonth yearMonth);
|
||||
|
||||
/** Do any necessry preparation for the DNS query. */
|
||||
void prepareForQuery(YearMonth yearMonth) throws Exception;
|
||||
/**
|
||||
* Do any necessary preparation for the DNS query.
|
||||
*
|
||||
* <p>This potentially throws {@link InterruptedException} because some implementations use
|
||||
* interruptible futures to prepare the query (and the correct thing to do with such exceptions is
|
||||
* to handle them correctly or propagate them as-is, no {@link RuntimeException} wrapping).
|
||||
*/
|
||||
void prepareForQuery(YearMonth yearMonth) throws InterruptedException;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ClaimsListParser {
|
||||
checkArgument(firstLine.size() == 2, String.format(
|
||||
"Line 1: Expected 2 elements, found %d", firstLine.size()));
|
||||
|
||||
Integer version = Integer.valueOf(firstLine.get(0));
|
||||
int version = Integer.parseInt(firstLine.get(0));
|
||||
DateTime creationTime = DateTime.parse(firstLine.get(1));
|
||||
checkArgument(version == 1, String.format(
|
||||
"Line 1: Expected version 1, found %d", version));
|
||||
|
||||
@@ -151,7 +151,7 @@ public final class Marksdb {
|
||||
*
|
||||
* <p>Note that the DNL is long, hence truncating it instead of logging the whole thing.
|
||||
*/
|
||||
private static void logFetchedBytes(String sourceUrl, byte[] bytes) throws IOException {
|
||||
private static void logFetchedBytes(String sourceUrl, byte[] bytes) {
|
||||
logger.atInfo().log(
|
||||
"Fetched contents of %s -- Size: %d bytes; first %d chars:\n\n%s%s",
|
||||
sourceUrl,
|
||||
|
||||
@@ -42,7 +42,7 @@ public final class SmdrlCsvParser {
|
||||
List<String> firstLine = Splitter.on(',').splitToList(lines.get(0));
|
||||
checkArgument(firstLine.size() == 2, String.format(
|
||||
"Line 1: Expected 2 elements, found %d", firstLine.size()));
|
||||
Integer version = Integer.valueOf(firstLine.get(0));
|
||||
int version = Integer.parseInt(firstLine.get(0));
|
||||
checkArgument(version == 1, String.format(
|
||||
"Line 1: Expected version 1, found %d", version));
|
||||
DateTime creationTime = DateTime.parse(firstLine.get(1)).withZone(UTC);
|
||||
|
||||
@@ -52,7 +52,7 @@ final class BigqueryParameters {
|
||||
private int bigqueryNumThreads = DEFAULT_NUM_THREADS;
|
||||
|
||||
/** Returns a new BigqueryConnection constructed according to the delegate's flag settings. */
|
||||
BigqueryConnection newConnection(BigqueryConnection.Builder connectionBuilder) throws Exception {
|
||||
BigqueryConnection newConnection(BigqueryConnection.Builder connectionBuilder) {
|
||||
return connectionBuilder
|
||||
.setExecutorService(Executors.newFixedThreadPool(bigqueryNumThreads))
|
||||
.setDatasetId(bigqueryDataset)
|
||||
|
||||
@@ -47,7 +47,7 @@ public abstract class ConfirmingCommand implements Command {
|
||||
}
|
||||
|
||||
/** Run any pre-execute command checks and return true if they all pass. */
|
||||
protected boolean checkExecutionState() throws Exception {
|
||||
protected boolean checkExecutionState() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class GetPremiumListCommand implements CommandWithRemoteApi {
|
||||
private List<String> mainParameters;
|
||||
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
public void run() {
|
||||
for (String premiumListName : mainParameters) {
|
||||
if (PremiumListDualDao.exists(premiumListName)) {
|
||||
System.out.printf(
|
||||
@@ -42,7 +42,7 @@ public class GetPremiumListCommand implements CommandWithRemoteApi {
|
||||
.map(PremiumListEntry::toString)
|
||||
.collect(Collectors.joining("\n")));
|
||||
} else {
|
||||
System.out.println(String.format("No list found with name %s.", premiumListName));
|
||||
System.out.printf("No list found with name %s.%n", premiumListName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,11 +66,9 @@ abstract class ReadEntityFromKeyPathCommand<T> extends MutatingCommand {
|
||||
Key<?> untypedKey = parseKeyPath(keyPath);
|
||||
Object entity = ofy().load().key(untypedKey).now();
|
||||
if (entity == null) {
|
||||
System.err.println(
|
||||
String.format(
|
||||
"Entity %s read from %s doesn't exist in Datastore! Skipping.",
|
||||
untypedKey,
|
||||
keyPathsFile == null ? "STDIN" : "File " + keyPathsFile.getAbsolutePath()));
|
||||
System.err.printf(
|
||||
"Entity %s read from %s doesn't exist in Datastore! Skipping.%n",
|
||||
untypedKey, keyPathsFile == null ? "STDIN" : "File " + keyPathsFile.getAbsolutePath());
|
||||
continue;
|
||||
}
|
||||
Class<T> clazz = new TypeInstantiator<T>(getClass()) {}.getExactType();
|
||||
|
||||
@@ -123,7 +123,7 @@ final class SetupOteCommand extends ConfirmingCommand implements CommandWithRemo
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute() throws Exception {
|
||||
public String execute() {
|
||||
ImmutableMap<String, String> clientIdToTld = oteAccountBuilder.buildAndPersist();
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
@@ -40,9 +40,7 @@ public abstract class ParameterConverterValidator<T>
|
||||
try {
|
||||
convert(value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
ParameterException pe =
|
||||
new ParameterException(String.format("%s=%s %s", name, value, messageForInvalid), e);
|
||||
throw pe;
|
||||
throw new ParameterException(String.format("%s=%s %s", name, value, messageForInvalid), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user