You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2021/08/24 13:21:52 UTC

[GitHub] [logging-log4j2] garydgregory commented on a change in pull request #568: Prefer `string.getBytes(Charset)` over `string.getBytes(String)`

garydgregory commented on a change in pull request #568:
URL: https://github.com/apache/logging-log4j2/pull/568#discussion_r694843906



##########
File path: log4j-core/src/main/java/org/apache/logging/log4j/core/util/StringEncoder.java
##########
@@ -39,26 +37,21 @@ private StringEncoder() {
      */
     public static byte[] toBytes(final String str, final Charset charset) {
         if (str != null) {
-            if (StandardCharsets.ISO_8859_1.equals(charset)) {
-                return encodeSingleByteChars(str);
-            }
-            final Charset actual = charset != null ? charset : Charset.defaultCharset();
-            try { // LOG4J2-935: String.getBytes(String) gives better performance
-                return str.getBytes(actual.name());
-            } catch (final UnsupportedEncodingException e) {
-                return str.getBytes(actual);
-            }
+            return str.getBytes(charset != null ? charset : Charset.defaultCharset());
         }
         return null;
     }
 
     /**
+     * Prefer standard {@link String#getBytes(Charset)} which performs better in java 8 and beyond.

Review comment:
       "java" -> "Java".




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org