UnknownCharset and UnsupportedCharset can't recognized by Charset
Brought to you by:
achimwestermann
As we all know, code Charset.forName(String) is to get an Charset instance by a canonical name or an alias.
I tested the following codes
System.out.println(StandardCharsets.UTF_8);
System.out.println(Charset.forName(StandardCharsets.UTF_8.name()));
System.out.println(StandardCharsets.UTF_16);
System.out.println(Charset.forName(StandardCharsets.UTF_16.name()));
As I expected, the result is
UTF-8
UTF-8
true
UTF-16
UTF-16
So I supposed that if I type
Charset.forName(UnknownCharset.getInstance().name())`
OR
Charset.forName("void")
I would get an UnknownCharset instance. But exception happend like
Exception in thread "main" java.nio.charset.UnsupportedCharsetException: void
at java.nio.charset.Charset.forName(Charset.java:536)
at Test.main(Test.java:13)