diff options
author | Eryk Szymanski <eryksz@gmail.com> | 2022-11-08 10:28:58 +0100 |
---|---|---|
committer | Eryk Szymanski <eryksz@gmail.com> | 2022-11-08 14:37:22 +0000 |
commit | 640b6ed91e2e6524569e00117a27598375942a85 (patch) | |
tree | 90a0d24a5fd4977cb228b2e9a6baa43c6b504bba | |
parent | 701b205b4c59b0c2356992968b5896558ec5007d (diff) |
Replace "UTF-8" String with StandardCharsets.UTF_8
Change-Id: I6e5f398b1f7c220d5ffe20fddb8855134d46eb66
Release-Notes: skip
Forward-Compatible: checked
4 files changed, 10 insertions, 16 deletions
diff --git a/e2e-tests/src/test/scala/com/google/gerrit/scenarios/GitSimulation.scala b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/GitSimulation.scala index 5d8dd6f253..53f942df0d 100644 --- a/e2e-tests/src/test/scala/com/google/gerrit/scenarios/GitSimulation.scala +++ b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/GitSimulation.scala @@ -14,6 +14,7 @@ package com.google.gerrit.scenarios +import static java.nio.charset.StandardCharsets.UTF_8 import java.io.{File, IOException} import java.net.URLEncoder @@ -31,7 +32,7 @@ class GitSimulation extends GerritSimulation { protected val gitProtocol: GitProtocol = GitProtocol() override def replaceOverride(in: String): String = { - var next = replaceKeyWith("_project", URLEncoder.encode(getFullProjectName(projectName), "UTF-8"), in) + var next = replaceKeyWith("_project", URLEncoder.encode(getFullProjectName(projectName), UTF_8), in) val authenticated = getProperty("authenticated", false).toBoolean val value = "CONTEXT_PATH" + (if (authenticated) "/a" else "") next = replaceKeyWith("context_path", value, next) diff --git a/e2e-tests/src/test/scala/com/google/gerrit/scenarios/ProjectSimulation.scala b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/ProjectSimulation.scala index 7d7bed7100..f0c6f68651 100644 --- a/e2e-tests/src/test/scala/com/google/gerrit/scenarios/ProjectSimulation.scala +++ b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/ProjectSimulation.scala @@ -14,12 +14,13 @@ package com.google.gerrit.scenarios +import static java.nio.charset.StandardCharsets.UTF_8 import java.net.URLEncoder class ProjectSimulation extends GerritSimulation { projectName = "defaultTestProject" override def replaceOverride(in: String): String = { - replaceProperty("project", URLEncoder.encode(getFullProjectName(projectName), "UTF-8"), in) + replaceProperty("project", URLEncoder.encode(getFullProjectName(projectName), UTF_8, in) } } diff --git a/java/com/google/gerrit/acceptance/AbstractDynamicOptionsTest.java b/java/com/google/gerrit/acceptance/AbstractDynamicOptionsTest.java index a4ed80a82b..4e8d20d6f7 100644 --- a/java/com/google/gerrit/acceptance/AbstractDynamicOptionsTest.java +++ b/java/com/google/gerrit/acceptance/AbstractDynamicOptionsTest.java @@ -15,6 +15,7 @@ package com.google.gerrit.acceptance; import static com.google.gerrit.sshd.CommandMetaData.Mode.MASTER_OR_SLAVE; +import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.collect.Lists; import com.google.gerrit.extensions.annotations.Exports; @@ -50,7 +51,7 @@ public class AbstractDynamicOptionsTest extends AbstractDaemonTest { public void display(OutputStream displayOutputStream) throws Exception { PrintWriter stdout = - new PrintWriter(new BufferedWriter(new OutputStreamWriter(displayOutputStream, "UTF-8"))); + new PrintWriter(new BufferedWriter(new OutputStreamWriter(displayOutputStream, UTF_8))); try { OutputFormat.JSON .newGson() diff --git a/java/com/google/gerrit/entities/KeyUtil.java b/java/com/google/gerrit/entities/KeyUtil.java index be28689e28..0f14cd920c 100644 --- a/java/com/google/gerrit/entities/KeyUtil.java +++ b/java/com/google/gerrit/entities/KeyUtil.java @@ -14,7 +14,8 @@ package com.google.gerrit.entities; -import java.io.UnsupportedEncodingException; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.util.Arrays; public class KeyUtil { @@ -49,13 +50,7 @@ public class KeyUtil { } public static String encode(final String key) { - final byte[] b; - try { - b = key.getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException("No UTF-8 support", e); - } - + final byte[] b = key.getBytes(UTF_8); final StringBuilder r = new StringBuilder(b.length); for (int i = 0; i < b.length; i++) { final int c = b[i] & 0xff; @@ -99,10 +94,6 @@ public class KeyUtil { } catch (ArrayIndexOutOfBoundsException err) { throw new IllegalArgumentException("Bad encoding" + key, err); } - try { - return new String(b, 0, bPtr, "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException("No UTF-8 support", e); - } + return new String(b, 0, bPtr, UTF_8); } } |