A DESCRIPTION OF THE REQUEST :
Currently URLDecoder has this API:
static String decode(String s, String enc) throws UnsupportedEncodingException
Which is unsafe and annoying because of checked Exception which is in most cases useless when used with a fixed String in code.
Instead, URLDecoder should (additionally) have a method
static String decode(String s, Charset charset)
which does not raise a checked Exception.
JUSTIFICATION :
This is in line with
public byte[] getBytes(Charset charset)
public byte[] getBytes(String charsetName)
throws UnsupportedEncodingException
of java.lang.String
The equivalent reasoning holds for URLEncoder.encode()
As a result code written using these classes can be safer against typos ("UFT-8"), and unnecessary try/catch blocks can be eliminated.
Currently URLDecoder has this API:
static String decode(String s, String enc) throws UnsupportedEncodingException
Which is unsafe and annoying because of checked Exception which is in most cases useless when used with a fixed String in code.
Instead, URLDecoder should (additionally) have a method
static String decode(String s, Charset charset)
which does not raise a checked Exception.
JUSTIFICATION :
This is in line with
public byte[] getBytes(Charset charset)
public byte[] getBytes(String charsetName)
throws UnsupportedEncodingException
of java.lang.String
The equivalent reasoning holds for URLEncoder.encode()
As a result code written using these classes can be safer against typos ("UFT-8"), and unnecessary try/catch blocks can be eliminated.
- duplicates
-
JDK-8178704 Add Charset overloads to URLDecoder and URLEncoder
-
- Closed
-