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

Charset.forName() taking fallback default value

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 18
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      source
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      This is a new method. Thus the compatibility risk is minimal.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      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) 

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: