JDK-8178704 : Add Charset overloads to URLDecoder and URLEncoder
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2017-04-12
  • Updated: 2017-12-02
  • Resolved: 2017-12-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10
10Resolved
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
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 ----------


Comments
[~vtewari] can you please take a look at this one.
25-08-2017