RFR: 8270490: Charset.forName() taking fallback default value [v2]
Naoto Sato
naoto at openjdk.java.net
Thu Oct 21 16:06:07 UTC 2021
On Thu, 21 Oct 2021 09:33:30 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:
>> Right, I think both try-catch usages will be removed.
>
> Apparently `IllegalCharsetNameException` or `IllegalArgumentException` could still be thrown - so removing the `try-catch` would be a change of behaviour in those cases. It all depends on whether there is a chance that these exceptions could be thrown in this particular context (with these particular input parameters) - which I am not able to tell - but maybe someone more familiar with this code could...
I first thought of swallowing all exceptions in 2-arg forName(), but decided not to do that. Because `IllegalArgumentException` and `IllegalCharsetNameException` are for the validity of the passed `charsetName`, like detecting `null` or invalid chars like "". On the other hand, `UnsupportedCharsetException` is for the availability which varies depending on the user's settings and or platform, which can be safely replaced with `fallback` charset. So yes, it is not totally getting rid of `try-catch` but it avoids `UnsupportedCharsetException` which is only detectable at runtime.
-------------
PR: https://git.openjdk.java.net/jdk/pull/6045
More information about the core-libs-dev
mailing list