On Wed, 20 Oct 2021 19:02:30 GMT, Naoto Sato <na...@openjdk.org> wrote:
>> During the review of JEP 400, a proposal to provide an overloaded method to >> `Charset.forName()` was suggested >> [[1]](https://github.com/openjdk/jdk/pull/4733#discussion_r669693954). This >> PR is to implement the proposal. A CSR is also drafted as >> https://bugs.openjdk.java.net/browse/JDK-8275348 > > Naoto Sato has updated the pull request incrementally with one additional > commit since the last revision: > > Moved the null sentence into @param tag. I'm not reviewer. I think maybe we should check all the usage of `Charset.isSupported`. At present, `Charset.isSupported` and `Charset.forName` are often used continuously, such as in `StringCoding`: class StringCoding { // ... private static Charset lookupCharset(String csn) { if (Charset.isSupported(csn)) { try { return Charset.forName(csn); } catch (UnsupportedCharsetException x) { throw new Error(x); } } return null; } //... } This calls `Charset.lookup` twice. Replacing it with such code should eliminate unnecessary lookup: private static Charset lookupCharset(String csn) { return Charset.forName(csn, null); } ------------- PR: https://git.openjdk.java.net/jdk/pull/6045