-
CSR
-
Resolution: Approved
-
P4
-
None
-
source
-
minimal
-
This is a new method. Thus the compatibility risk is minimal.
-
Java API
-
SE
Summary
Provide an overload method to java.nio.charset.Charset#forName()
that takes fallback
Charset object.
Problem
The existing forName()
method throws UnsupportedCharsetException
or IllegalCharsetNameException
when the named charset is not available. The call site always has to try-catch it to determine whether the desired charset is returned or not.
Solution
Provide an overload method that takes fallback Charset. If the named charset is not available, the fallback charset is returned.
Specification
Add a new method in java.nio.charset.Charset
as follows:
/**
* Returns a charset object for the named charset. If the charset object
* for the named charset is not available or {@code charsetName} is not a
* legal charset name, then {@code fallback} is returned.
*
* @param charsetName
* The name of the requested charset; may be either
* a canonical name or an alias
*
* @param fallback
* fallback charset in case the charset object for the named
* charset is not available or {@code charsetName} is not a legal
* charset name. May be {@code null}
*
* @return A charset object for the named charset, or {@code fallback}
* in case the charset object for the named charset is not
* available or {@code charsetName} is not a legal charset name
*
* @throws IllegalArgumentException
* If the given {@code charsetName} is {@code null}
*
* @since 18
*/
public static Charset forName(String charsetName,
Charset fallback)
- csr of
-
JDK-8270490 Charset.forName() taking fallback default value
-
- Resolved
-