Re-enable Java 17 features (#2333)

This commit is contained in:
Lai Jiang 2024-02-21 15:04:07 -05:00 committed by GitHub
parent 7a301edab7
commit 9d0ff74377
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 52 additions and 106 deletions

3
.gitignore vendored
View file

@ -117,3 +117,6 @@ core/**/registrar_dbg*.css
# Appengine generated files # Appengine generated files
core/WEB-INF/appengine-generated/*.bin core/WEB-INF/appengine-generated/*.bin
core/WEB-INF/appengine-generated/*.xml core/WEB-INF/appengine-generated/*.xml
# jEnv
.java-version

View file

@ -22,7 +22,6 @@ import static google.registry.flows.FlowUtils.unmarshalEpp;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.flogger.FluentLogger; import com.google.common.flogger.FluentLogger;
import google.registry.flows.FlowModule.EppExceptionInProviderException; import google.registry.flows.FlowModule.EppExceptionInProviderException;
@ -45,7 +44,7 @@ import org.json.simple.JSONValue;
public final class EppController { public final class EppController {
private static final FluentLogger logger = FluentLogger.forEnclosingClass(); private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String LOG_SEPARATOR = Strings.repeat("=", 40); private static final String LOG_SEPARATOR = "=".repeat(40);
@Inject FlowComponent.Builder flowComponentBuilder; @Inject FlowComponent.Builder flowComponentBuilder;
@Inject EppMetric.Builder eppMetricBuilder; @Inject EppMetric.Builder eppMetricBuilder;

View file

@ -17,7 +17,6 @@ package google.registry.flows;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.xml.XmlTransformer.prettyPrint; import static google.registry.xml.XmlTransformer.prettyPrint;
import com.google.common.base.Strings;
import com.google.common.flogger.FluentLogger; import com.google.common.flogger.FluentLogger;
import google.registry.flows.FlowModule.DryRun; import google.registry.flows.FlowModule.DryRun;
import google.registry.flows.FlowModule.InputXml; import google.registry.flows.FlowModule.InputXml;
@ -36,7 +35,7 @@ import javax.inject.Provider;
/** Run a flow, either transactionally or not, with logging and retrying as needed. */ /** Run a flow, either transactionally or not, with logging and retrying as needed. */
public class FlowRunner { public class FlowRunner {
private static final String COMMAND_LOG_FORMAT = "EPP Command" + Strings.repeat("\n\t%s", 8); private static final String COMMAND_LOG_FORMAT = "EPP Command" + "\n\t%s".repeat(8);
private static final FluentLogger logger = FluentLogger.forEnclosingClass(); private static final FluentLogger logger = FluentLogger.forEnclosingClass();

View file

@ -38,8 +38,8 @@ import google.registry.xml.ValidationMode;
import google.registry.xml.XmlException; import google.registry.xml.XmlException;
import google.registry.xml.XmlFragmentMarshaller; import google.registry.xml.XmlFragmentMarshaller;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.Collection; import java.util.Collection;
import javax.annotation.concurrent.NotThreadSafe; import javax.annotation.concurrent.NotThreadSafe;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
@ -51,7 +51,7 @@ import org.joda.time.DateTime;
public final class RdeMarshaller implements Serializable { public final class RdeMarshaller implements Serializable {
private static final FluentLogger logger = FluentLogger.forEnclosingClass(); private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final long serialVersionUID = 202890386611768455L; @Serial private static final long serialVersionUID = 202890386611768455L;
private final ValidationMode validationMode; private final ValidationMode validationMode;
private transient XmlFragmentMarshaller memoizedMarshaller; private transient XmlFragmentMarshaller memoizedMarshaller;
@ -85,13 +85,12 @@ public final class RdeMarshaller implements Serializable {
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
try { try {
XjcXmlTransformer.marshal(deposit, os, UTF_8, validationMode); XjcXmlTransformer.marshal(deposit, os, UTF_8, validationMode);
// TODO: Call StandardCharset.UTF_8 instead once we are one Java 17 runtime. String rdeDocument = os.toString(UTF_8);
String rdeDocument = os.toString("UTF-8");
String marker = "<rde:contents>\n"; String marker = "<rde:contents>\n";
int startOfContents = rdeDocument.indexOf(marker); int startOfContents = rdeDocument.indexOf(marker);
verify(startOfContents > 0, "Bad RDE document:\n%s", rdeDocument); verify(startOfContents > 0, "Bad RDE document:\n%s", rdeDocument);
return rdeDocument.substring(0, startOfContents + marker.length()); return rdeDocument.substring(0, startOfContents + marker.length());
} catch (XmlException | UnsupportedEncodingException e) { } catch (XmlException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View file

@ -22,7 +22,6 @@ import static com.google.common.net.HttpHeaders.CONTENT_LENGTH;
import static com.google.common.net.HttpHeaders.CONTENT_TYPE; import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.base.Strings;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import com.google.common.net.MediaType; import com.google.common.net.MediaType;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -133,6 +132,6 @@ public final class UrlConnectionUtils {
random.nextBytes(rand); random.nextBytes(rand);
// Boundary strings can be up to 70 characters long, so use 30 hyphens plus 32 random digits. // Boundary strings can be up to 70 characters long, so use 30 hyphens plus 32 random digits.
// See https://tools.ietf.org/html/rfc2046#section-5.1.1 // See https://tools.ietf.org/html/rfc2046#section-5.1.1
return Strings.repeat("-", 30) + base64().encode(rand); return "-".repeat(30) + base64().encode(rand);
} }
} }

View file

@ -17,7 +17,6 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import com.google.common.base.Ascii; import com.google.common.base.Ascii;
import com.google.common.base.Strings;
import google.registry.model.EppResource; import google.registry.model.EppResource;
import google.registry.model.ForeignKeyUtils; import google.registry.model.ForeignKeyUtils;
import google.registry.model.contact.Contact; import google.registry.model.contact.Contact;
@ -46,10 +45,8 @@ class CommandUtilities {
} }
} }
// TODO: change Strings.repeat("-", n) to "-".repeat(n) once we are on Java 17 runtime.
@SuppressWarnings("InlineMeInliner")
static String addHeader(String header, String body) { static String addHeader(String header, String body) {
return String.format("%s:\n%s\n%s", header, Strings.repeat("-", header.length() + 1), body); return String.format("%s:\n%s\n%s", header, "-".repeat(header.length() + 1), body);
} }
/** Prompts for yes/no input using promptText, defaulting to no. */ /** Prompts for yes/no input using promptText, defaulting to no. */

View file

@ -19,7 +19,6 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import google.registry.model.common.Cursor; import google.registry.model.common.Cursor;
import google.registry.model.common.Cursor.CursorType; import google.registry.model.common.Cursor.CursorType;
@ -64,7 +63,7 @@ final class ListCursorsCommand implements Command {
tm().transact(() -> tm().loadByKeysIfPresent(cursorKeys.values())); tm().transact(() -> tm().loadByKeysIfPresent(cursorKeys.values()));
if (!cursorKeys.isEmpty()) { if (!cursorKeys.isEmpty()) {
String header = String.format(OUTPUT_FMT, "TLD", "Cursor Time", "Last Update Time"); String header = String.format(OUTPUT_FMT, "TLD", "Cursor Time", "Last Update Time");
System.out.printf("%s\n%s\n", header, Strings.repeat("-", header.length())); System.out.printf("%s\n%s\n", header, "-".repeat(header.length()));
cursorKeys.entrySet().stream() cursorKeys.entrySet().stream()
.map(e -> renderLine(e.getKey(), Optional.ofNullable(cursors.get(e.getValue())))) .map(e -> renderLine(e.getKey(), Optional.ofNullable(cursors.get(e.getValue()))))
.sorted() .sorted()

View file

@ -21,7 +21,6 @@ import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams; import com.google.common.collect.Streams;
@ -94,14 +93,14 @@ final class VerifyOteCommand implements CommandWithConnection {
ImmutableMap.of( ImmutableMap.of(
"summarize", Boolean.toString(summarize), "summarize", Boolean.toString(summarize),
"registrars", new ArrayList<>(registrars))); "registrars", new ArrayList<>(registrars)));
System.out.println(Strings.repeat("-", 80)); System.out.println("-".repeat(80));
for (Entry<String, Object> registrar : response.entrySet()) { for (Entry<String, Object> registrar : response.entrySet()) {
System.out.printf( System.out.printf(
summarize ? "%-20s - %s\n" : "\n=========== %s OT&E status ============\n%s\n", summarize ? "%-20s - %s\n" : "\n=========== %s OT&E status ============\n%s\n",
registrar.getKey(), registrar.getKey(),
registrar.getValue()); registrar.getValue());
} }
System.out.println(Strings.repeat("-", 80)); System.out.println("-".repeat(80));
} }
/** /**

View file

@ -239,8 +239,7 @@ public abstract class ListObjectsAction<T extends ImmutableObject> implements Ru
lines.add(rowFormatter.apply(headerRow)); lines.add(rowFormatter.apply(headerRow));
// Add a row of separator lines (column names mapping to '-' * column width). // Add a row of separator lines (column names mapping to '-' * column width).
Map<String, String> separatorRow = Map<String, String> separatorRow = Maps.transformValues(columnWidths, "-"::repeat);
Maps.transformValues(columnWidths, width -> Strings.repeat("-", width));
lines.add(rowFormatter.apply(separatorRow)); lines.add(rowFormatter.apply(separatorRow));
} }

View file

@ -40,7 +40,6 @@ import static org.joda.money.CurrencyUnit.JPY;
import static org.joda.money.CurrencyUnit.USD; import static org.joda.money.CurrencyUnit.USD;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -802,7 +801,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
@Test @Test
void testFailure_tooLong() { void testFailure_tooLong() {
doFailingBadLabelTest(Strings.repeat("a", 64) + ".tld", DomainLabelTooLongException.class); doFailingBadLabelTest("a".repeat(64) + ".tld", DomainLabelTooLongException.class);
} }
@Test @Test

View file

@ -65,7 +65,6 @@ import static org.joda.money.CurrencyUnit.JPY;
import static org.joda.money.CurrencyUnit.USD; import static org.joda.money.CurrencyUnit.USD;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -191,8 +190,6 @@ import google.registry.tmch.SmdrlCsvParser;
import google.registry.tmch.TmchData; import google.registry.tmch.TmchData;
import google.registry.tmch.TmchTestData; import google.registry.tmch.TmchTestData;
import google.registry.xml.ValidationMode; import google.registry.xml.ValidationMode;
import java.io.BufferedReader;
import java.io.StringReader;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
@ -2764,7 +2761,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
@Test @Test
void testFailure_tooLong() { void testFailure_tooLong() {
doFailingDomainNameTest(Strings.repeat("a", 64) + ".tld", DomainLabelTooLongException.class); doFailingDomainNameTest("a".repeat(64) + ".tld", DomainLabelTooLongException.class);
} }
@Test @Test
@ -2887,11 +2884,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
@Test @Test
void testFail_startDateSunriseRegistration_revokedSignedMark() throws Exception { void testFail_startDateSunriseRegistration_revokedSignedMark() throws Exception {
SmdrlCsvParser.parse( SmdrlCsvParser.parse(TmchTestData.loadFile("smd/smdrl.csv").lines().collect(toImmutableList()))
// TODO: Use String.lines() once we are on Java 17.
new BufferedReader(new StringReader(TmchTestData.loadFile("smd/smdrl.csv")))
.lines()
.collect(toImmutableList()))
.save(); .save();
createTld("tld", START_DATE_SUNRISE); createTld("tld", START_DATE_SUNRISE);
clock.setTo(SMD_VALID_TIME); clock.setTo(SMD_VALID_TIME);
@ -2917,11 +2910,8 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
if (labels.isEmpty()) { if (labels.isEmpty()) {
return; return;
} }
// TODO: Use String.lines() once we are on Java 17.
SmdrlCsvParser.parse( SmdrlCsvParser.parse(
new BufferedReader(new StringReader(TmchTestData.loadFile("idn/idn_smdrl.csv"))) TmchTestData.loadFile("idn/idn_smdrl.csv").lines().collect(toImmutableList()))
.lines()
.collect(toImmutableList()))
.save(); .save();
createTld("tld", START_DATE_SUNRISE); createTld("tld", START_DATE_SUNRISE);
clock.setTo(SMD_VALID_TIME); clock.setTo(SMD_VALID_TIME);

View file

@ -30,7 +30,6 @@ import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptio
import static google.registry.testing.HostSubject.assertAboutHosts; import static google.registry.testing.HostSubject.assertAboutHosts;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import google.registry.flows.EppException; import google.registry.flows.EppException;
@ -259,7 +258,7 @@ class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Host> {
@Test @Test
void testFailure_longHostName() { void testFailure_longHostName() {
setEppHostCreateInputWithIps("a" + Strings.repeat(".labelpart", 25) + ".tld"); setEppHostCreateInputWithIps("a" + ".labelpart".repeat(25) + ".tld");
EppException thrown = assertThrows(HostNameTooLongException.class, this::runFlow); EppException thrown = assertThrows(HostNameTooLongException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }

View file

@ -18,7 +18,6 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.flows.host.HostFlowUtils.validateHostName; import static google.registry.flows.host.HostFlowUtils.validateHostName;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.base.Strings;
import google.registry.flows.host.HostFlowUtils.HostNameNotLowerCaseException; import google.registry.flows.host.HostFlowUtils.HostNameNotLowerCaseException;
import google.registry.flows.host.HostFlowUtils.HostNameNotNormalizedException; import google.registry.flows.host.HostFlowUtils.HostNameNotNormalizedException;
import google.registry.flows.host.HostFlowUtils.HostNameNotPunyCodedException; import google.registry.flows.host.HostFlowUtils.HostNameNotPunyCodedException;
@ -61,8 +60,7 @@ class HostFlowUtilsTest {
@Test @Test
void test_validateHostName_hostNameTooLong() { void test_validateHostName_hostNameTooLong() {
assertThrows( assertThrows(
HostNameTooLongException.class, HostNameTooLongException.class, () -> validateHostName("na".repeat(200) + ".wat.man"));
() -> validateHostName(Strings.repeat("na", 200) + ".wat.man"));
} }
@Test @Test

View file

@ -41,7 +41,6 @@ import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.cloud.tasks.v2.HttpMethod; import com.google.cloud.tasks.v2.HttpMethod;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.InetAddresses; import com.google.common.net.InetAddresses;
@ -1274,7 +1273,7 @@ class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Host> {
void testFailure_renameToTooLong() throws Exception { void testFailure_renameToTooLong() throws Exception {
// Host names can be max 253 chars. // Host names can be max 253 chars.
String suffix = ".example.tld"; String suffix = ".example.tld";
String tooLong = Strings.repeat("a", 254 - suffix.length()) + suffix; String tooLong = "a".repeat(254 - suffix.length()) + suffix;
doFailingHostNameTest(tooLong, HostNameTooLongException.class); doFailingHostNameTest(tooLong, HostNameTooLongException.class);
} }

View file

@ -14,6 +14,7 @@
package google.registry.persistence.transaction; package google.registry.persistence.transaction;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
@ -24,12 +25,12 @@ import google.registry.persistence.transaction.JpaTestExtensions.JpaUnitTestExte
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.extension.RegisterExtension;
@ -38,8 +39,6 @@ import org.junit.jupiter.api.extension.RegisterExtension;
* *
* <p>Please refer to the class javadoc of {@link DatabaseException} for more information. * <p>Please refer to the class javadoc of {@link DatabaseException} for more information.
*/ */
@Disabled // TODO: re-enable test class after upgrading to Java 17.
// LogManager.updateConfiguration() is only supported in Java 9 and later.
public class HibernateLoggingSuppressionTest { public class HibernateLoggingSuppressionTest {
private static final String LOG_SUPPRESSION_TARGET = private static final String LOG_SUPPRESSION_TARGET =
@ -74,7 +73,6 @@ public class HibernateLoggingSuppressionTest {
void suppressHibernateLogs() throws IOException { void suppressHibernateLogs() throws IOException {
try (ByteArrayInputStream additionalProperties = try (ByteArrayInputStream additionalProperties =
new ByteArrayInputStream(LOGGING_PROPERTIES_LINE.getBytes(UTF_8))) { new ByteArrayInputStream(LOGGING_PROPERTIES_LINE.getBytes(UTF_8))) {
/*
LogManager.getLogManager() LogManager.getLogManager()
.updateConfiguration( .updateConfiguration(
additionalProperties, additionalProperties,
@ -86,14 +84,12 @@ public class HibernateLoggingSuppressionTest {
checkArgument(o == null, "Cannot override old value in this test"); checkArgument(o == null, "Cannot override old value in this test");
return n; return n;
}); });
*/
} }
} }
void revertSuppressionOfHibernateLogs() throws IOException { void revertSuppressionOfHibernateLogs() throws IOException {
try (ByteArrayInputStream additionalProperties = try (ByteArrayInputStream additionalProperties =
new ByteArrayInputStream(LOGGING_PROPERTIES_LINE.getBytes(UTF_8))) { new ByteArrayInputStream(LOGGING_PROPERTIES_LINE.getBytes(UTF_8))) {
/*
LogManager.getLogManager() LogManager.getLogManager()
.updateConfiguration( .updateConfiguration(
additionalProperties, additionalProperties,
@ -104,7 +100,6 @@ public class HibernateLoggingSuppressionTest {
} }
return null; return null;
}); });
*/
} }
} }
@ -150,7 +145,7 @@ public class HibernateLoggingSuppressionTest {
int value; int value;
// For Hibernate // For Hibernate
TestEntity() {} public TestEntity() {}
TestEntity(long id, int value) { TestEntity(long id, int value) {
this.id = id; this.id = id;

View file

@ -173,8 +173,7 @@ public abstract class JpaTransactionManagerExtension
File tempSqlFile = File.createTempFile("tempSqlFile", ".sql"); File tempSqlFile = File.createTempFile("tempSqlFile", ".sql");
tempSqlFile.deleteOnExit(); tempSqlFile.deleteOnExit();
exporter.export(extraEntityClasses, tempSqlFile); exporter.export(extraEntityClasses, tempSqlFile);
// TODO: Use Files.readString() once we upgrade to Java 17 runtime. executeSql(Files.readString(tempSqlFile.toPath(), UTF_8));
executeSql(new String(Files.readAllBytes(tempSqlFile.toPath()), UTF_8));
} }
assertReasonableNumDbConnections(); assertReasonableNumDbConnections();
emf = createEntityManagerFactory(getJpaProperties()); emf = createEntityManagerFactory(getJpaProperties());

View file

@ -21,7 +21,6 @@ import static google.registry.testing.SystemInfo.hasCommand;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.io.CharStreams; import com.google.common.io.CharStreams;
import google.registry.keyring.api.Keyring; import google.registry.keyring.api.Keyring;
@ -55,10 +54,7 @@ class GhostrydeGpgIntegrationTest {
private static final ImmutableList<String> CONTENTS = private static final ImmutableList<String> CONTENTS =
ImmutableList.of( ImmutableList.of(
"(◕‿◕)", "(◕‿◕)", "Fanatics have their dreams, wherewith they weave\n".repeat(1000), "\0yolo", "");
Strings.repeat("Fanatics have their dreams, wherewith they weave\n", 1000),
"\0yolo",
"");
@SuppressWarnings("unused") @SuppressWarnings("unused")
static Stream<Arguments> provideTestCombinations() { static Stream<Arguments> provideTestCombinations() {

View file

@ -20,7 +20,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue;
import com.google.common.base.Strings;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import google.registry.keyring.api.Keyring; import google.registry.keyring.api.Keyring;
import google.registry.testing.BouncyCastleProviderExtension; import google.registry.testing.BouncyCastleProviderExtension;
@ -54,7 +53,7 @@ public class GhostrydeTest {
return Stream.of( return Stream.of(
"hi", "hi",
"(◕‿◕)", "(◕‿◕)",
Strings.repeat("Fanatics have their dreams, wherewith they weave\n", 1000), "Fanatics have their dreams, wherewith they weave\n".repeat(1000),
"\0yolo", "\0yolo",
"") "")
.map(Arguments::of); .map(Arguments::of);

View file

@ -21,7 +21,6 @@ import static google.registry.testing.SystemInfo.hasCommand;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.flogger.FluentLogger; import com.google.common.flogger.FluentLogger;
import com.google.common.io.CharStreams; import com.google.common.io.CharStreams;
@ -63,10 +62,7 @@ public class RydeGpgIntegrationTest {
private static final ImmutableList<String> CONTENTS = private static final ImmutableList<String> CONTENTS =
ImmutableList.of( ImmutableList.of(
"(◕‿◕)", "(◕‿◕)", "Fanatics have their dreams, wherewith they weave\n".repeat(1000), "\0yolo", "");
Strings.repeat("Fanatics have their dreams, wherewith they weave\n", 1000),
"\0yolo",
"");
static Stream<Arguments> provideTestCombinations() { static Stream<Arguments> provideTestCombinations() {
Stream.Builder<Arguments> stream = Stream.builder(); Stream.Builder<Arguments> stream = Stream.builder();

View file

@ -71,19 +71,20 @@ import org.junit.jupiter.api.extension.RegisterExtension;
class NordnUploadActionTest { class NordnUploadActionTest {
private static final String CLAIMS_CSV = private static final String CLAIMS_CSV =
"1,2010-05-04T10:11:12.000Z,2\n" """
+ "roid,domain-name,notice-id,registrar-id,registration-datetime,ack-datetime," 1,2010-05-04T10:11:12.000Z,2
+ "application-datetime\n" roid,domain-name,notice-id,registrar-id,registration-datetime,ack-datetime,application-datetime
+ "6-TLD,claims-landrush2.tld,landrush2tcn,88888,2010-05-03T10:11:12.000Z," 6-TLD,claims-landrush2.tld,landrush2tcn,88888,2010-05-03T10:11:12.000Z,2010-05-03T08:11:12.000Z
+ "2010-05-03T08:11:12.000Z\n" 8-TLD,claims-landrush1.tld,landrush1tcn,99999,2010-05-04T10:11:12.000Z,2010-05-04T09:11:12.000Z
+ "8-TLD,claims-landrush1.tld,landrush1tcn,99999,2010-05-04T10:11:12.000Z," """;
+ "2010-05-04T09:11:12.000Z\n";
private static final String SUNRISE_CSV = private static final String SUNRISE_CSV =
"1,2010-05-04T10:11:12.000Z,2\n" """
+ "roid,domain-name,SMD-id,registrar-id,registration-datetime,application-datetime\n" 1,2010-05-04T10:11:12.000Z,2
+ "2-TLD,sunrise2.tld,new-smdid,88888,2010-05-01T10:11:12.000Z\n" roid,domain-name,SMD-id,registrar-id,registration-datetime,application-datetime
+ "4-TLD,sunrise1.tld,my-smdid,99999,2010-05-02T10:11:12.000Z\n"; 2-TLD,sunrise2.tld,new-smdid,88888,2010-05-01T10:11:12.000Z
4-TLD,sunrise1.tld,my-smdid,99999,2010-05-02T10:11:12.000Z
""";
private static final String LOCATION_URL = "http://trololol"; private static final String LOCATION_URL = "http://trololol";
@ -249,8 +250,7 @@ class NordnUploadActionTest {
verify(httpUrlConnection).setRequestMethod("POST"); verify(httpUrlConnection).setRequestMethod("POST");
assertThat(httpUrlConnection.getURL()) assertThat(httpUrlConnection.getURL())
.isEqualTo(new URL("http://127.0.0.1/LORDN/tld/" + phase)); .isEqualTo(new URL("http://127.0.0.1/LORDN/tld/" + phase));
// TODO: use toString(StandardCharsets.UTF_8) once we upgrade to Java 17. assertThat(connectionOutputStream.toString(UTF_8)).contains(csv);
assertThat(connectionOutputStream.toString("UTF-8")).contains(csv);
verifyColumnCleared(domain1); verifyColumnCleared(domain1);
verifyColumnCleared(domain2); verifyColumnCleared(domain2);
cloudTasksHelper.assertTasksEnqueued( cloudTasksHelper.assertTasksEnqueued(

View file

@ -73,8 +73,7 @@ final class GcpProjectConnectionTest {
ByteArrayOutputStream output = new ByteArrayOutputStream(); ByteArrayOutputStream output = new ByteArrayOutputStream();
getStreamingContent().writeTo(output); getStreamingContent().writeTo(output);
output.close(); output.close();
// TODO: use toString(StandardCharsets.UTF_8) once we upgrade to Java 17. return output.toString(UTF_8);
return output.toString("UTF-8");
} }
} }

View file

@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.net.MediaType; import com.google.common.net.MediaType;
import google.registry.model.tld.Tld.TldType; import google.registry.model.tld.Tld.TldType;
@ -51,7 +50,7 @@ public class ListDomainsCommandTest extends ListObjectsCommandTestCase<ListDomai
@Test @Test
@MockitoSettings(strictness = Strictness.LENIENT) @MockitoSettings(strictness = Strictness.LENIENT)
void test_tldsParamTooLong() { void test_tldsParamTooLong() {
String tldsParam = "--tlds=foo,bar" + Strings.repeat(",baz", 300); String tldsParam = "--tlds=foo,bar" + ",baz".repeat(300);
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> runCommand(tldsParam)); assertThrows(IllegalArgumentException.class, () -> runCommand(tldsParam));
assertThat(thrown) assertThat(thrown)

View file

@ -14,7 +14,6 @@
package google.registry.ui.server.registrar; package google.registry.ui.server.registrar;
import static com.google.common.base.Strings.repeat;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatabaseHelper.loadRegistrar; import static google.registry.testing.DatabaseHelper.loadRegistrar;
@ -98,7 +97,7 @@ class WhoisSettingsTest extends RegistrarSettingsActionTestCase {
.setFaxNumber("+1.2125650001") .setFaxNumber("+1.2125650001")
.setLocalizedAddress( .setLocalizedAddress(
new RegistrarAddress.Builder() new RegistrarAddress.Builder()
.setStreet(ImmutableList.of("76 Ninth Avenue", repeat("lol", 200))) .setStreet(ImmutableList.of("76 Ninth Avenue", "lol".repeat(200)))
.setCity("New York") .setCity("New York")
.setState("NY") .setState("NY")
.setZip("10009") .setZip("10009")

View file

@ -29,11 +29,9 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.flogger.FluentLogger; import com.google.common.flogger.FluentLogger;
import com.google.common.io.ByteStreams;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -143,10 +141,7 @@ public class FlywayDeadlockTest {
"create index if not exists index_name on public.element_name ...", "create index if not exists index_name on public.element_name ...",
"create index if not exists \"index_name\" on public.element_name ...", "create index if not exists \"index_name\" on public.element_name ...",
"create unique index public.index_name on public.\"element_name\" ..."); "create unique index public.index_name on public.\"element_name\" ...");
ddls.forEach( ddls.forEach(ddl -> assertThat(getDdlLockedElementName(ddl)).hasValue("element_name"));
ddl -> {
assertThat(getDdlLockedElementName(ddl)).hasValue("element_name");
});
} }
@Test @Test
@ -160,10 +155,7 @@ public class FlywayDeadlockTest {
"drop table element_name ...;", "drop table element_name ...;",
"drop sequence element_name ...;", "drop sequence element_name ...;",
"drop INDEX element_name ...;"); "drop INDEX element_name ...;");
ddls.forEach( ddls.forEach(ddl -> assertThat(getDdlLockedElementName(ddl)).isEmpty());
ddl -> {
assertThat(getDdlLockedElementName(ddl)).isEmpty();
});
} }
static Optional<String> getDdlLockedElementName(String ddl) { static Optional<String> getDdlLockedElementName(String ddl) {
@ -183,8 +175,7 @@ public class FlywayDeadlockTest {
.splitToStream( .splitToStream(
readAllLines(path, UTF_8).stream() readAllLines(path, UTF_8).stream()
.map(line -> line.replaceAll("--.*", "")) .map(line -> line.replaceAll("--.*", ""))
// TODO: Use line.isBlank() one we are on Java 17. .filter(line -> !line.isBlank())
.filter(line -> !line.trim().isEmpty())
.collect(joining(" "))) .collect(joining(" ")))
.map(FlywayDeadlockTest::getDdlLockedElementName) .map(FlywayDeadlockTest::getDdlLockedElementName)
.filter(Optional::isPresent) .filter(Optional::isPresent)
@ -214,8 +205,7 @@ public class FlywayDeadlockTest {
.splitToList(executeShellCommand(changedScriptsCommand, Optional.of(rootDir))) .splitToList(executeShellCommand(changedScriptsCommand, Optional.of(rootDir)))
.stream() .stream()
.map(pathStr -> rootDir + File.separator + pathStr) .map(pathStr -> rootDir + File.separator + pathStr)
// TODO: Use Path::of once we are on Java 17. .map(Path::of)
.map(path -> Paths.get(path))
.collect(toImmutableList()); .collect(toImmutableList());
if (changedPaths.isEmpty()) { if (changedPaths.isEmpty()) {
logger.atInfo().log("There are no schema changes."); logger.atInfo().log("There are no schema changes.");
@ -238,9 +228,8 @@ public class FlywayDeadlockTest {
new ProcessBuilder(SHELL_COMMAND_SPLITTER.splitToList(command).toArray(new String[0])); new ProcessBuilder(SHELL_COMMAND_SPLITTER.splitToList(command).toArray(new String[0]));
workingDir.map(File::new).ifPresent(processBuilder::directory); workingDir.map(File::new).ifPresent(processBuilder::directory);
Process process = processBuilder.start(); Process process = processBuilder.start();
// TODO:Use InputStream.readAllBytes() once we are on Java 17. String output = new String(process.getInputStream().readAllBytes(), UTF_8);
String output = new String(ByteStreams.toByteArray(process.getInputStream()), UTF_8); String error = new String(process.getErrorStream().readAllBytes(), UTF_8);
String error = new String(ByteStreams.toByteArray(process.getErrorStream()), UTF_8);
try { try {
process.waitFor(1, SECONDS); process.waitFor(1, SECONDS);
} catch (InterruptedException ie) { } catch (InterruptedException ie) {

View file

@ -194,8 +194,7 @@ ext {
'org.junit.jupiter:junit-jupiter-params:[5.6.2,)', 'org.junit.jupiter:junit-jupiter-params:[5.6.2,)',
'org.junit.platform:junit-platform-runner:[1.6.2,)', 'org.junit.platform:junit-platform-runner:[1.6.2,)',
'org.junit.platform:junit-platform-suite-api:[1.6.2,)', 'org.junit.platform:junit-platform-suite-api:[1.6.2,)',
// TODO: remove the exclusive upper bound once we are on Java 17 runtime. 'org.junit-pioneer:junit-pioneer:[0.7.0,)',
'org.junit-pioneer:junit-pioneer:[0.7.0,2.0.0[',
'org.apache.avro:avro:[1.8.2,)', 'org.apache.avro:avro:[1.8.2,)',
'org.apache.beam:beam-runners-core-construction-java:[2.37.0,)', 'org.apache.beam:beam-runners-core-construction-java:[2.37.0,)',
'org.apache.beam:beam-runners-direct-java:[2.37.0,)', 'org.apache.beam:beam-runners-direct-java:[2.37.0,)',

View file

@ -133,8 +133,6 @@ tasks.withType(JavaCompile).configureEach {
options.errorprone.disable("LongDoubleConversion") options.errorprone.disable("LongDoubleConversion")
// Allow import of commonly-used names such as "Type". // Allow import of commonly-used names such as "Type".
options.errorprone.disable("BadImport") options.errorprone.disable("BadImport")
// TODO: enable this once we are on Java 17 runtime.
options.errorprone.disable("InlineMeInliner")
options.errorprone.disableWarningsInGeneratedCode = true options.errorprone.disableWarningsInGeneratedCode = true
options.errorprone.errorproneArgumentProviders.add([ options.errorprone.errorproneArgumentProviders.add([
asArguments: { asArguments: {