diff --git a/server/src/main/java/org/elasticsearch/common/logging/DeprecationLogger.java b/server/src/main/java/org/elasticsearch/common/logging/DeprecationLogger.java index 81d272923db..d5d682f807a 100644 --- a/server/src/main/java/org/elasticsearch/common/logging/DeprecationLogger.java +++ b/server/src/main/java/org/elasticsearch/common/logging/DeprecationLogger.java @@ -259,7 +259,11 @@ public class DeprecationLogger { * @return a warning value formatted according to RFC 7234 */ public static String formatWarning(final String s) { - return WARNING_PREFIX + " " + "\"" + escapeAndEncode(s) + "\""; + // Assume that the common scenario won't have a string to escape and encode. + int length = WARNING_PREFIX.length() + s.length() + 3; + final StringBuilder sb = new StringBuilder(length); + sb.append(WARNING_PREFIX).append(" \"").append(escapeAndEncode(s)).append("\""); + return sb.toString(); } /** diff --git a/server/src/main/java/org/elasticsearch/common/logging/LoggerMessageFormat.java b/server/src/main/java/org/elasticsearch/common/logging/LoggerMessageFormat.java index 3b85a42ce96..17553e91777 100644 --- a/server/src/main/java/org/elasticsearch/common/logging/LoggerMessageFormat.java +++ b/server/src/main/java/org/elasticsearch/common/logging/LoggerMessageFormat.java @@ -40,7 +40,7 @@ public class LoggerMessageFormat { if (messagePattern == null) { return null; } - if (argArray == null) { + if (argArray == null || argArray.length == 0) { if (prefix == null) { return messagePattern; } else {