Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8275348

Charset.forName() taking fallback default value

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 18
    • core-libs
    • None
    • source
    • minimal
    • This is a new method. Thus the compatibility risk is minimal.
    • Java API
    • SE

      Summary

      Provide an overload method to java.nio.charset.Charset#forName() that takes fallback Charset object.

      Problem

      The existing forName() method throws UnsupportedCharsetException or IllegalCharsetNameException when the named charset is not available. The call site always has to try-catch it to determine whether the desired charset is returned or not.

      Solution

      Provide an overload method that takes fallback Charset. If the named charset is not available, the fallback charset is returned.

      Specification

      Add a new method in java.nio.charset.Charset as follows:

      /**
       * 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) 

            naoto Naoto Sato
            naoto Naoto Sato
            Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: