From cf5b501254e937178d53e3bc50e44b825e1fcffa Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Tue, 27 Feb 2018 11:09:47 +1100 Subject: [PATCH 1/2] Resolved default charset warning in jetty-util for #2206 Ignored warning in B64Code US-ASCII in UnixCrypt Signed-off-by: Lachlan Roberts --- jetty-util/src/main/java/org/eclipse/jetty/util/B64Code.java | 2 ++ .../main/java/org/eclipse/jetty/util/security/UnixCrypt.java | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/B64Code.java b/jetty-util/src/main/java/org/eclipse/jetty/util/B64Code.java index 1fe4006b7cb..078b8f8e4f5 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/B64Code.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/B64Code.java @@ -261,6 +261,7 @@ public class B64Code * @throws IllegalArgumentException if the input is not a valid * B64 encoding. */ + @SuppressWarnings("DefaultCharset") public static String decode(String encoded,String charEncoding) { byte[] decoded=decode(encoded); @@ -279,6 +280,7 @@ public class B64Code * @throws IllegalArgumentException if the input is not a valid * B64 encoding. */ + @SuppressWarnings("DefaultCharset") public static String decode(String encoded, Charset charEncoding) { byte[] decoded=decode(encoded); diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/security/UnixCrypt.java b/jetty-util/src/main/java/org/eclipse/jetty/util/security/UnixCrypt.java index e3f98e807f6..8e7e78c108d 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/security/UnixCrypt.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/security/UnixCrypt.java @@ -23,6 +23,7 @@ package org.eclipse.jetty.util.security; +import java.nio.charset.StandardCharsets; /* ------------------------------------------------------------ */ /** @@ -444,7 +445,7 @@ public class UnixCrypt rsltblock >>= 6; } - return new String(cryptresult, 0, 13); + return new String(cryptresult, 0, 13, StandardCharsets.US_ASCII); } public static void main(String[] arg) From 67d12a0839933162657d7c0ae43e436ea6895102 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Tue, 27 Feb 2018 12:12:40 +1100 Subject: [PATCH 2/2] Updates from review Signed-off-by: Lachlan Roberts --- .../src/main/java/org/eclipse/jetty/util/B64Code.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/B64Code.java b/jetty-util/src/main/java/org/eclipse/jetty/util/B64Code.java index 078b8f8e4f5..6e9d7d8599b 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/B64Code.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/B64Code.java @@ -255,13 +255,14 @@ public class B64Code *

Unlike {@link #decode(char[])}, extra whitespace is ignored. * @param encoded String to decode. * @param charEncoding String representing the character encoding - * used to map the decoded bytes into a String. + * used to map the decoded bytes into a String. If null + * the platforms default charset is used. * @return String decoded byte array. * @throws UnsupportedCharsetException if the encoding is not supported * @throws IllegalArgumentException if the input is not a valid * B64 encoding. */ - @SuppressWarnings("DefaultCharset") + @SuppressWarnings("DefaultCharset") public static String decode(String encoded,String charEncoding) { byte[] decoded=decode(encoded); @@ -275,12 +276,13 @@ public class B64Code *

Unlike {@link #decode(char[])}, extra whitespace is ignored. * @param encoded String to decode. * @param charEncoding Character encoding - * used to map the decoded bytes into a String. + * used to map the decoded bytes into a String. If null + * the platforms default charset is used. * @return String decoded byte array. * @throws IllegalArgumentException if the input is not a valid * B64 encoding. */ - @SuppressWarnings("DefaultCharset") + @SuppressWarnings("DefaultCharset") public static String decode(String encoded, Charset charEncoding) { byte[] decoded=decode(encoded);