-
Enhancement
-
Resolution: Duplicate
-
P3
-
8, 9
-
generic
-
generic
A DESCRIPTION OF THE REQUEST :
URL{En,De}coder have methods that allow you to specify the name of the character set to encode to/from. It would be convenient if these methods also had an override that accepted Charset as well. This is especially true since most of the time these methods will be called with UTF-8, and then you could use StandardCharsets.UTF_8 instead of having to pass in "UTF-8".
JUSTIFICATION :
This would get rid of all the boilerplate code to handle the UnsupportedCharSetException, which can normally never occur, as the we are using UTF-8 anyway, which is guaranteed to be supported by the JVM.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
That there are methods:
URLEncoder:
public static String encode(String s, java.nio.Charset enc)
URLDecoder:
public static String decode(String s, java.nio.Charset enc)
ACTUAL -
These methods do not exist.
---------- BEGIN SOURCE ----------
public class Test {
String s = java.net.URLEncoder.encode("string", java.nio.charset.StandardCharsets.UTF_8);
String s = java.net.URLDecoder.decode("string", java.nio.charset.StandardCharsets.UTF_8);
}
This class should compile, but does not.
---------- END SOURCE ----------
URL{En,De}coder have methods that allow you to specify the name of the character set to encode to/from. It would be convenient if these methods also had an override that accepted Charset as well. This is especially true since most of the time these methods will be called with UTF-8, and then you could use StandardCharsets.UTF_8 instead of having to pass in "UTF-8".
JUSTIFICATION :
This would get rid of all the boilerplate code to handle the UnsupportedCharSetException, which can normally never occur, as the we are using UTF-8 anyway, which is guaranteed to be supported by the JVM.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
That there are methods:
URLEncoder:
public static String encode(String s, java.nio.Charset enc)
URLDecoder:
public static String decode(String s, java.nio.Charset enc)
ACTUAL -
These methods do not exist.
---------- BEGIN SOURCE ----------
public class Test {
String s = java.net.URLEncoder.encode("string", java.nio.charset.StandardCharsets.UTF_8);
String s = java.net.URLDecoder.decode("string", java.nio.charset.StandardCharsets.UTF_8);
}
This class should compile, but does not.
---------- END SOURCE ----------
- duplicates
-
JDK-4707784 URLEncoder / URLDecoder usage change from 1.3 to 1.4
-
- Closed
-
-
JDK-8054317 java.net.URLDecoder / URLEncoder should accept java.nio.charset.Charset
-
- Closed
-
-
JDK-8178081 Add java.net.URLEncoder.encode(String, Charset)
-
- Closed
-
- relates to
-
JDK-8183743 Umbrella: add overloads that take a Charset parameter
-
- Resolved
-