RFR: 8270490: Charset.forName() taking fallback default value [v3]

Naoto Sato naoto at openjdk.java.net
Sat Oct 23 22:13:41 UTC 2021


On Sat, 23 Oct 2021 19:29:30 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:

> Just an idea, should we check that the second parameter is null or not? Any pros and cons of that? For example should this code be allowed:
> 
> ```
> var cs = Charset.forName(charsetName, null);
> if (cs == null) {
>    System.err.println("Used UTF-8 encoding instead of "+charsetName+");
>    cs = StandardCharsets.UTF_8;
> }
> ```

Yes, that's the whole purpose of allowing `null` for `fallback`.

> src/java.base/share/classes/java/io/Console.java line 589:
> 
>> 587:         }
>> 588:         if (cs == null) {
>> 589:             cs = Charset.forName(StaticProperty.nativeEncoding(), Charset.defaultCharset());
> 
> Not sure but looks like this class tries to maintain 80 chars per line rule?

Fixed.

-------------

PR: https://git.openjdk.java.net/jdk/pull/6045


More information about the core-libs-dev mailing list