From 9d0ff7437726d8ae88e2a4e3af59695dbf4c6de8 Mon Sep 17 00:00:00 2001 From: Lai Jiang Date: Wed, 21 Feb 2024 15:04:07 -0500 Subject: [PATCH] Re-enable Java 17 features (#2333) --- .gitignore | 3 +++ .../google/registry/flows/EppController.java | 3 +-- .../google/registry/flows/FlowRunner.java | 3 +-- .../google/registry/rde/RdeMarshaller.java | 9 +++---- .../registry/request/UrlConnectionUtils.java | 3 +-- .../registry/tools/CommandUtilities.java | 5 +--- .../registry/tools/ListCursorsCommand.java | 3 +-- .../registry/tools/VerifyOteCommand.java | 5 ++-- .../tools/server/ListObjectsAction.java | 3 +-- .../flows/domain/DomainCheckFlowTest.java | 3 +-- .../flows/domain/DomainCreateFlowTest.java | 16 +++--------- .../flows/host/HostCreateFlowTest.java | 3 +-- .../flows/host/HostFlowUtilsTest.java | 4 +-- .../flows/host/HostUpdateFlowTest.java | 3 +-- .../HibernateLoggingSuppressionTest.java | 11 +++----- .../JpaTransactionManagerExtension.java | 3 +-- .../rde/GhostrydeGpgIntegrationTest.java | 6 +---- .../google/registry/rde/GhostrydeTest.java | 3 +-- .../registry/rde/RydeGpgIntegrationTest.java | 6 +---- .../registry/tmch/NordnUploadActionTest.java | 26 +++++++++---------- .../tools/GcpProjectConnectionTest.java | 3 +-- .../tools/ListDomainsCommandTest.java | 3 +-- .../server/registrar/WhoisSettingsTest.java | 3 +-- .../sql/flyway/FlywayDeadlockTest.java | 23 +++++----------- dependencies.gradle | 3 +-- java_common.gradle | 2 -- 26 files changed, 52 insertions(+), 106 deletions(-) diff --git a/.gitignore b/.gitignore index d37f397b0..d9920d6a7 100644 --- a/.gitignore +++ b/.gitignore @@ -117,3 +117,6 @@ core/**/registrar_dbg*.css # Appengine generated files core/WEB-INF/appengine-generated/*.bin core/WEB-INF/appengine-generated/*.xml + +# jEnv +.java-version diff --git a/core/src/main/java/google/registry/flows/EppController.java b/core/src/main/java/google/registry/flows/EppController.java index 51008c0f3..5e98f7e46 100644 --- a/core/src/main/java/google/registry/flows/EppController.java +++ b/core/src/main/java/google/registry/flows/EppController.java @@ -22,7 +22,6 @@ import static google.registry.flows.FlowUtils.unmarshalEpp; import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.common.flogger.FluentLogger; import google.registry.flows.FlowModule.EppExceptionInProviderException; @@ -45,7 +44,7 @@ import org.json.simple.JSONValue; public final class EppController { 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 EppMetric.Builder eppMetricBuilder; diff --git a/core/src/main/java/google/registry/flows/FlowRunner.java b/core/src/main/java/google/registry/flows/FlowRunner.java index 1872c384a..db3454e3d 100644 --- a/core/src/main/java/google/registry/flows/FlowRunner.java +++ b/core/src/main/java/google/registry/flows/FlowRunner.java @@ -17,7 +17,6 @@ package google.registry.flows; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.xml.XmlTransformer.prettyPrint; -import com.google.common.base.Strings; import com.google.common.flogger.FluentLogger; import google.registry.flows.FlowModule.DryRun; 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. */ 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(); diff --git a/core/src/main/java/google/registry/rde/RdeMarshaller.java b/core/src/main/java/google/registry/rde/RdeMarshaller.java index 6667f6ac8..5af07d807 100644 --- a/core/src/main/java/google/registry/rde/RdeMarshaller.java +++ b/core/src/main/java/google/registry/rde/RdeMarshaller.java @@ -38,8 +38,8 @@ import google.registry.xml.ValidationMode; import google.registry.xml.XmlException; import google.registry.xml.XmlFragmentMarshaller; import java.io.ByteArrayOutputStream; +import java.io.Serial; import java.io.Serializable; -import java.io.UnsupportedEncodingException; import java.util.Collection; import javax.annotation.concurrent.NotThreadSafe; import javax.xml.bind.JAXBElement; @@ -51,7 +51,7 @@ import org.joda.time.DateTime; public final class RdeMarshaller implements Serializable { 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 transient XmlFragmentMarshaller memoizedMarshaller; @@ -85,13 +85,12 @@ public final class RdeMarshaller implements Serializable { ByteArrayOutputStream os = new ByteArrayOutputStream(); try { 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 = "\n"; int startOfContents = rdeDocument.indexOf(marker); verify(startOfContents > 0, "Bad RDE document:\n%s", rdeDocument); return rdeDocument.substring(0, startOfContents + marker.length()); - } catch (XmlException | UnsupportedEncodingException e) { + } catch (XmlException e) { throw new RuntimeException(e); } diff --git a/core/src/main/java/google/registry/request/UrlConnectionUtils.java b/core/src/main/java/google/registry/request/UrlConnectionUtils.java index bd04a6391..a1118457b 100644 --- a/core/src/main/java/google/registry/request/UrlConnectionUtils.java +++ b/core/src/main/java/google/registry/request/UrlConnectionUtils.java @@ -22,7 +22,6 @@ import static com.google.common.net.HttpHeaders.CONTENT_LENGTH; import static com.google.common.net.HttpHeaders.CONTENT_TYPE; import static java.nio.charset.StandardCharsets.UTF_8; -import com.google.common.base.Strings; import com.google.common.io.ByteStreams; import com.google.common.net.MediaType; import java.io.ByteArrayInputStream; @@ -133,6 +132,6 @@ public final class UrlConnectionUtils { random.nextBytes(rand); // 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 - return Strings.repeat("-", 30) + base64().encode(rand); + return "-".repeat(30) + base64().encode(rand); } } diff --git a/core/src/main/java/google/registry/tools/CommandUtilities.java b/core/src/main/java/google/registry/tools/CommandUtilities.java index 6e1448d2b..084e306a4 100644 --- a/core/src/main/java/google/registry/tools/CommandUtilities.java +++ b/core/src/main/java/google/registry/tools/CommandUtilities.java @@ -17,7 +17,6 @@ package google.registry.tools; import static com.google.common.base.Preconditions.checkState; import com.google.common.base.Ascii; -import com.google.common.base.Strings; import google.registry.model.EppResource; import google.registry.model.ForeignKeyUtils; 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) { - 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. */ diff --git a/core/src/main/java/google/registry/tools/ListCursorsCommand.java b/core/src/main/java/google/registry/tools/ListCursorsCommand.java index a34e1c84a..e23d4f5d4 100644 --- a/core/src/main/java/google/registry/tools/ListCursorsCommand.java +++ b/core/src/main/java/google/registry/tools/ListCursorsCommand.java @@ -19,7 +19,6 @@ import static google.registry.persistence.transaction.TransactionManagerFactory. import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import google.registry.model.common.Cursor; import google.registry.model.common.Cursor.CursorType; @@ -64,7 +63,7 @@ final class ListCursorsCommand implements Command { tm().transact(() -> tm().loadByKeysIfPresent(cursorKeys.values())); if (!cursorKeys.isEmpty()) { 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() .map(e -> renderLine(e.getKey(), Optional.ofNullable(cursors.get(e.getValue())))) .sorted() diff --git a/core/src/main/java/google/registry/tools/VerifyOteCommand.java b/core/src/main/java/google/registry/tools/VerifyOteCommand.java index 605dd28e3..52d3f4da8 100644 --- a/core/src/main/java/google/registry/tools/VerifyOteCommand.java +++ b/core/src/main/java/google/registry/tools/VerifyOteCommand.java @@ -21,7 +21,6 @@ import static google.registry.util.PreconditionsUtils.checkArgumentPresent; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; @@ -94,14 +93,14 @@ final class VerifyOteCommand implements CommandWithConnection { ImmutableMap.of( "summarize", Boolean.toString(summarize), "registrars", new ArrayList<>(registrars))); - System.out.println(Strings.repeat("-", 80)); + System.out.println("-".repeat(80)); for (Entry registrar : response.entrySet()) { System.out.printf( summarize ? "%-20s - %s\n" : "\n=========== %s OT&E status ============\n%s\n", registrar.getKey(), registrar.getValue()); } - System.out.println(Strings.repeat("-", 80)); + System.out.println("-".repeat(80)); } /** diff --git a/core/src/main/java/google/registry/tools/server/ListObjectsAction.java b/core/src/main/java/google/registry/tools/server/ListObjectsAction.java index f03aeae97..3f2217e69 100644 --- a/core/src/main/java/google/registry/tools/server/ListObjectsAction.java +++ b/core/src/main/java/google/registry/tools/server/ListObjectsAction.java @@ -239,8 +239,7 @@ public abstract class ListObjectsAction implements Ru lines.add(rowFormatter.apply(headerRow)); // Add a row of separator lines (column names mapping to '-' * column width). - Map separatorRow = - Maps.transformValues(columnWidths, width -> Strings.repeat("-", width)); + Map separatorRow = Maps.transformValues(columnWidths, "-"::repeat); lines.add(rowFormatter.apply(separatorRow)); } diff --git a/core/src/test/java/google/registry/flows/domain/DomainCheckFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainCheckFlowTest.java index e494f7f74..f1fe0fd97 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainCheckFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainCheckFlowTest.java @@ -40,7 +40,6 @@ import static org.joda.money.CurrencyUnit.JPY; import static org.joda.money.CurrencyUnit.USD; 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.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -802,7 +801,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase { @Test void testFailure_longHostName() { - setEppHostCreateInputWithIps("a" + Strings.repeat(".labelpart", 25) + ".tld"); + setEppHostCreateInputWithIps("a" + ".labelpart".repeat(25) + ".tld"); EppException thrown = assertThrows(HostNameTooLongException.class, this::runFlow); assertAboutEppExceptions().that(thrown).marshalsToXml(); } diff --git a/core/src/test/java/google/registry/flows/host/HostFlowUtilsTest.java b/core/src/test/java/google/registry/flows/host/HostFlowUtilsTest.java index 45abacb9a..b2a178656 100644 --- a/core/src/test/java/google/registry/flows/host/HostFlowUtilsTest.java +++ b/core/src/test/java/google/registry/flows/host/HostFlowUtilsTest.java @@ -18,7 +18,6 @@ import static com.google.common.truth.Truth.assertThat; import static google.registry.flows.host.HostFlowUtils.validateHostName; 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.HostNameNotNormalizedException; import google.registry.flows.host.HostFlowUtils.HostNameNotPunyCodedException; @@ -61,8 +60,7 @@ class HostFlowUtilsTest { @Test void test_validateHostName_hostNameTooLong() { assertThrows( - HostNameTooLongException.class, - () -> validateHostName(Strings.repeat("na", 200) + ".wat.man")); + HostNameTooLongException.class, () -> validateHostName("na".repeat(200) + ".wat.man")); } @Test diff --git a/core/src/test/java/google/registry/flows/host/HostUpdateFlowTest.java b/core/src/test/java/google/registry/flows/host/HostUpdateFlowTest.java index 6a6bd34ec..ff2ab03c9 100644 --- a/core/src/test/java/google/registry/flows/host/HostUpdateFlowTest.java +++ b/core/src/test/java/google/registry/flows/host/HostUpdateFlowTest.java @@ -41,7 +41,6 @@ import static google.registry.util.DateTimeUtils.END_OF_TIME; import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.cloud.tasks.v2.HttpMethod; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.net.InetAddresses; @@ -1274,7 +1273,7 @@ class HostUpdateFlowTest extends ResourceFlowTestCase { void testFailure_renameToTooLong() throws Exception { // Host names can be max 253 chars. 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); } diff --git a/core/src/test/java/google/registry/persistence/transaction/HibernateLoggingSuppressionTest.java b/core/src/test/java/google/registry/persistence/transaction/HibernateLoggingSuppressionTest.java index 62f9a0c75..1c90d633a 100644 --- a/core/src/test/java/google/registry/persistence/transaction/HibernateLoggingSuppressionTest.java +++ b/core/src/test/java/google/registry/persistence/transaction/HibernateLoggingSuppressionTest.java @@ -14,6 +14,7 @@ package google.registry.persistence.transaction; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.truth.Truth.assertThat; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; 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.IOException; import java.util.logging.Level; +import java.util.logging.LogManager; import java.util.logging.Logger; import javax.persistence.Entity; import javax.persistence.Id; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -38,8 +39,6 @@ import org.junit.jupiter.api.extension.RegisterExtension; * *

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 { private static final String LOG_SUPPRESSION_TARGET = @@ -74,7 +73,6 @@ public class HibernateLoggingSuppressionTest { void suppressHibernateLogs() throws IOException { try (ByteArrayInputStream additionalProperties = new ByteArrayInputStream(LOGGING_PROPERTIES_LINE.getBytes(UTF_8))) { - /* LogManager.getLogManager() .updateConfiguration( additionalProperties, @@ -86,14 +84,12 @@ public class HibernateLoggingSuppressionTest { checkArgument(o == null, "Cannot override old value in this test"); return n; }); - */ } } void revertSuppressionOfHibernateLogs() throws IOException { try (ByteArrayInputStream additionalProperties = new ByteArrayInputStream(LOGGING_PROPERTIES_LINE.getBytes(UTF_8))) { - /* LogManager.getLogManager() .updateConfiguration( additionalProperties, @@ -104,7 +100,6 @@ public class HibernateLoggingSuppressionTest { } return null; }); - */ } } @@ -150,7 +145,7 @@ public class HibernateLoggingSuppressionTest { int value; // For Hibernate - TestEntity() {} + public TestEntity() {} TestEntity(long id, int value) { this.id = id; diff --git a/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerExtension.java b/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerExtension.java index e434dee03..40e41241f 100644 --- a/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerExtension.java +++ b/core/src/test/java/google/registry/persistence/transaction/JpaTransactionManagerExtension.java @@ -173,8 +173,7 @@ public abstract class JpaTransactionManagerExtension File tempSqlFile = File.createTempFile("tempSqlFile", ".sql"); tempSqlFile.deleteOnExit(); exporter.export(extraEntityClasses, tempSqlFile); - // TODO: Use Files.readString() once we upgrade to Java 17 runtime. - executeSql(new String(Files.readAllBytes(tempSqlFile.toPath()), UTF_8)); + executeSql(Files.readString(tempSqlFile.toPath(), UTF_8)); } assertReasonableNumDbConnections(); emf = createEntityManagerFactory(getJpaProperties()); diff --git a/core/src/test/java/google/registry/rde/GhostrydeGpgIntegrationTest.java b/core/src/test/java/google/registry/rde/GhostrydeGpgIntegrationTest.java index 59fcc2b16..dbfc3b655 100644 --- a/core/src/test/java/google/registry/rde/GhostrydeGpgIntegrationTest.java +++ b/core/src/test/java/google/registry/rde/GhostrydeGpgIntegrationTest.java @@ -21,7 +21,6 @@ import static google.registry.testing.SystemInfo.hasCommand; import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.jupiter.api.Assumptions.assumeTrue; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.io.CharStreams; import google.registry.keyring.api.Keyring; @@ -55,10 +54,7 @@ class GhostrydeGpgIntegrationTest { private static final ImmutableList CONTENTS = ImmutableList.of( - "(◕‿◕)", - Strings.repeat("Fanatics have their dreams, wherewith they weave\n", 1000), - "\0yolo", - ""); + "(◕‿◕)", "Fanatics have their dreams, wherewith they weave\n".repeat(1000), "\0yolo", ""); @SuppressWarnings("unused") static Stream provideTestCombinations() { diff --git a/core/src/test/java/google/registry/rde/GhostrydeTest.java b/core/src/test/java/google/registry/rde/GhostrydeTest.java index 42d6cfcd0..a2da69252 100644 --- a/core/src/test/java/google/registry/rde/GhostrydeTest.java +++ b/core/src/test/java/google/registry/rde/GhostrydeTest.java @@ -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.Assumptions.assumeTrue; -import com.google.common.base.Strings; import com.google.common.io.ByteStreams; import google.registry.keyring.api.Keyring; import google.registry.testing.BouncyCastleProviderExtension; @@ -54,7 +53,7 @@ public class GhostrydeTest { return Stream.of( "hi", "(◕‿◕)", - Strings.repeat("Fanatics have their dreams, wherewith they weave\n", 1000), + "Fanatics have their dreams, wherewith they weave\n".repeat(1000), "\0yolo", "") .map(Arguments::of); diff --git a/core/src/test/java/google/registry/rde/RydeGpgIntegrationTest.java b/core/src/test/java/google/registry/rde/RydeGpgIntegrationTest.java index d95a0c643..cb23dcf23 100644 --- a/core/src/test/java/google/registry/rde/RydeGpgIntegrationTest.java +++ b/core/src/test/java/google/registry/rde/RydeGpgIntegrationTest.java @@ -21,7 +21,6 @@ import static google.registry.testing.SystemInfo.hasCommand; import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.jupiter.api.Assumptions.assumeTrue; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.flogger.FluentLogger; import com.google.common.io.CharStreams; @@ -63,10 +62,7 @@ public class RydeGpgIntegrationTest { private static final ImmutableList CONTENTS = ImmutableList.of( - "(◕‿◕)", - Strings.repeat("Fanatics have their dreams, wherewith they weave\n", 1000), - "\0yolo", - ""); + "(◕‿◕)", "Fanatics have their dreams, wherewith they weave\n".repeat(1000), "\0yolo", ""); static Stream provideTestCombinations() { Stream.Builder stream = Stream.builder(); diff --git a/core/src/test/java/google/registry/tmch/NordnUploadActionTest.java b/core/src/test/java/google/registry/tmch/NordnUploadActionTest.java index f68ef4677..5d6aca758 100644 --- a/core/src/test/java/google/registry/tmch/NordnUploadActionTest.java +++ b/core/src/test/java/google/registry/tmch/NordnUploadActionTest.java @@ -71,19 +71,20 @@ import org.junit.jupiter.api.extension.RegisterExtension; class NordnUploadActionTest { 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," - + "application-datetime\n" - + "6-TLD,claims-landrush2.tld,landrush2tcn,88888,2010-05-03T10: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\n"; + """ + 1,2010-05-04T10:11:12.000Z,2 + 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,2010-05-03T08:11:12.000Z + 8-TLD,claims-landrush1.tld,landrush1tcn,99999,2010-05-04T10:11:12.000Z,2010-05-04T09:11:12.000Z + """; 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" - + "2-TLD,sunrise2.tld,new-smdid,88888,2010-05-01T10:11:12.000Z\n" - + "4-TLD,sunrise1.tld,my-smdid,99999,2010-05-02T10:11:12.000Z\n"; + """ + 1,2010-05-04T10:11:12.000Z,2 + roid,domain-name,SMD-id,registrar-id,registration-datetime,application-datetime + 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"; @@ -249,8 +250,7 @@ class NordnUploadActionTest { verify(httpUrlConnection).setRequestMethod("POST"); assertThat(httpUrlConnection.getURL()) .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(domain2); cloudTasksHelper.assertTasksEnqueued( diff --git a/core/src/test/java/google/registry/tools/GcpProjectConnectionTest.java b/core/src/test/java/google/registry/tools/GcpProjectConnectionTest.java index 942fe3eb4..d73130b0e 100644 --- a/core/src/test/java/google/registry/tools/GcpProjectConnectionTest.java +++ b/core/src/test/java/google/registry/tools/GcpProjectConnectionTest.java @@ -73,8 +73,7 @@ final class GcpProjectConnectionTest { ByteArrayOutputStream output = new ByteArrayOutputStream(); getStreamingContent().writeTo(output); output.close(); - // TODO: use toString(StandardCharsets.UTF_8) once we upgrade to Java 17. - return output.toString("UTF-8"); + return output.toString(UTF_8); } } diff --git a/core/src/test/java/google/registry/tools/ListDomainsCommandTest.java b/core/src/test/java/google/registry/tools/ListDomainsCommandTest.java index 73fa60134..f53436182 100644 --- a/core/src/test/java/google/registry/tools/ListDomainsCommandTest.java +++ b/core/src/test/java/google/registry/tools/ListDomainsCommandTest.java @@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; -import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.common.net.MediaType; import google.registry.model.tld.Tld.TldType; @@ -51,7 +50,7 @@ public class ListDomainsCommandTest extends ListObjectsCommandTestCase runCommand(tldsParam)); assertThat(thrown) diff --git a/core/src/test/java/google/registry/ui/server/registrar/WhoisSettingsTest.java b/core/src/test/java/google/registry/ui/server/registrar/WhoisSettingsTest.java index 48fed7e71..dfe85c2be 100644 --- a/core/src/test/java/google/registry/ui/server/registrar/WhoisSettingsTest.java +++ b/core/src/test/java/google/registry/ui/server/registrar/WhoisSettingsTest.java @@ -14,7 +14,6 @@ package google.registry.ui.server.registrar; -import static com.google.common.base.Strings.repeat; import static com.google.common.truth.Truth.assertThat; import static google.registry.testing.DatabaseHelper.loadRegistrar; @@ -98,7 +97,7 @@ class WhoisSettingsTest extends RegistrarSettingsActionTestCase { .setFaxNumber("+1.2125650001") .setLocalizedAddress( new RegistrarAddress.Builder() - .setStreet(ImmutableList.of("76 Ninth Avenue", repeat("lol", 200))) + .setStreet(ImmutableList.of("76 Ninth Avenue", "lol".repeat(200))) .setCity("New York") .setState("NY") .setZip("10009") diff --git a/db/src/test/java/google/registry/sql/flyway/FlywayDeadlockTest.java b/db/src/test/java/google/registry/sql/flyway/FlywayDeadlockTest.java index 11bc205dc..8387820ed 100644 --- a/db/src/test/java/google/registry/sql/flyway/FlywayDeadlockTest.java +++ b/db/src/test/java/google/registry/sql/flyway/FlywayDeadlockTest.java @@ -29,11 +29,9 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.flogger.FluentLogger; -import com.google.common.io.ByteStreams; import java.io.File; import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Map; import java.util.Optional; 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 unique index public.index_name on public.\"element_name\" ..."); - ddls.forEach( - ddl -> { - assertThat(getDdlLockedElementName(ddl)).hasValue("element_name"); - }); + ddls.forEach(ddl -> assertThat(getDdlLockedElementName(ddl)).hasValue("element_name")); } @Test @@ -160,10 +155,7 @@ public class FlywayDeadlockTest { "drop table element_name ...;", "drop sequence element_name ...;", "drop INDEX element_name ...;"); - ddls.forEach( - ddl -> { - assertThat(getDdlLockedElementName(ddl)).isEmpty(); - }); + ddls.forEach(ddl -> assertThat(getDdlLockedElementName(ddl)).isEmpty()); } static Optional getDdlLockedElementName(String ddl) { @@ -183,8 +175,7 @@ public class FlywayDeadlockTest { .splitToStream( readAllLines(path, UTF_8).stream() .map(line -> line.replaceAll("--.*", "")) - // TODO: Use line.isBlank() one we are on Java 17. - .filter(line -> !line.trim().isEmpty()) + .filter(line -> !line.isBlank()) .collect(joining(" "))) .map(FlywayDeadlockTest::getDdlLockedElementName) .filter(Optional::isPresent) @@ -214,8 +205,7 @@ public class FlywayDeadlockTest { .splitToList(executeShellCommand(changedScriptsCommand, Optional.of(rootDir))) .stream() .map(pathStr -> rootDir + File.separator + pathStr) - // TODO: Use Path::of once we are on Java 17. - .map(path -> Paths.get(path)) + .map(Path::of) .collect(toImmutableList()); if (changedPaths.isEmpty()) { 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])); workingDir.map(File::new).ifPresent(processBuilder::directory); Process process = processBuilder.start(); - // TODO:Use InputStream.readAllBytes() once we are on Java 17. - String output = new String(ByteStreams.toByteArray(process.getInputStream()), UTF_8); - String error = new String(ByteStreams.toByteArray(process.getErrorStream()), UTF_8); + String output = new String(process.getInputStream().readAllBytes(), UTF_8); + String error = new String(process.getErrorStream().readAllBytes(), UTF_8); try { process.waitFor(1, SECONDS); } catch (InterruptedException ie) { diff --git a/dependencies.gradle b/dependencies.gradle index 3ccbdb45e..a955fe341 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -194,8 +194,7 @@ ext { 'org.junit.jupiter:junit-jupiter-params:[5.6.2,)', 'org.junit.platform:junit-platform-runner:[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,2.0.0[', + 'org.junit-pioneer:junit-pioneer:[0.7.0,)', 'org.apache.avro:avro:[1.8.2,)', 'org.apache.beam:beam-runners-core-construction-java:[2.37.0,)', 'org.apache.beam:beam-runners-direct-java:[2.37.0,)', diff --git a/java_common.gradle b/java_common.gradle index 78de05033..76488abec 100644 --- a/java_common.gradle +++ b/java_common.gradle @@ -133,8 +133,6 @@ tasks.withType(JavaCompile).configureEach { options.errorprone.disable("LongDoubleConversion") // Allow import of commonly-used names such as "Type". options.errorprone.disable("BadImport") - // TODO: enable this once we are on Java 17 runtime. - options.errorprone.disable("InlineMeInliner") options.errorprone.disableWarningsInGeneratedCode = true options.errorprone.errorproneArgumentProviders.add([ asArguments: {