mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8270490: Charset.forName() taking fallback default value
Reviewed-by: joehw, rriggs, serb, dfuchs
This commit is contained in:
parent
a29273336b
commit
168081efc8
3 changed files with 109 additions and 8 deletions
|
@ -582,17 +582,12 @@ public final class Console implements Flushable
|
|||
csname = GetPropertyAction.privilegedGetProperty("sun.stdout.encoding");
|
||||
}
|
||||
if (csname != null) {
|
||||
try {
|
||||
cs = Charset.forName(csname);
|
||||
} catch (Exception ignored) { }
|
||||
cs = Charset.forName(csname, null);
|
||||
}
|
||||
}
|
||||
if (cs == null) {
|
||||
try {
|
||||
cs = Charset.forName(StaticProperty.nativeEncoding());
|
||||
} catch (Exception ignored) {
|
||||
cs = Charset.defaultCharset();
|
||||
}
|
||||
cs = Charset.forName(StaticProperty.nativeEncoding(),
|
||||
Charset.defaultCharset());
|
||||
}
|
||||
|
||||
CHARSET = cs;
|
||||
|
|
|
@ -527,6 +527,39 @@ public abstract class Charset
|
|||
throw new UnsupportedCharsetException(charsetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
try {
|
||||
Charset cs = lookup(charsetName);
|
||||
return cs != null ? cs : fallback;
|
||||
} catch (IllegalCharsetNameException icne) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
// Fold charsets from the given iterator into the given map, ignoring
|
||||
// charsets whose names already have entries in the map.
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue