code: private static Locale parseLocale(String locale, String variant) {
  
          Locale ret = null;
          String language = locale;
          String country = null;
          int index = -1;
  
          if (((index = locale.indexOf(HYPHEN)) > -1)
                  || ((index = locale.indexOf(UNDERSCORE)) > -1)) {
              language = locale.substring(0, index);
              country = locale.substring(index + 1);
          }
  
          if ((language == null) || (language.length() == 0)) {
              // LOCALE_NO_LANGUAGE
              throw new IllegalArgumentException("Missing language component in 'value' attribute in &lt;setLocale&gt;");
          }
  
          if (country == null) {
              if (variant != null) {
                  ret = new Locale(language, "", variant);
              } else {
                  ret = new Locale(language, "");
              }
          } else if (country.length() > 0) {
              if (variant != null) {
                  ret = new Locale(language, country, variant);
              } else {
                  ret = new Locale(language, country);
              }
          } else {
              // LOCALE_EMPTY_COUNTRY
              throw new IllegalArgumentException("Empty country component in 'value' attribute in &lt;setLocale&gt;");
          }
  
          return ret;
      }
docs: Parses the given locale string into its language and (optionally)
  country components, and returns the corresponding
  <tt>java.util.Locale</tt> object.
  <p>If the given locale string is null or empty, the runtime's default
  locale is returned.
  
  @param locale  the locale string to parse
  @param variant the variant
  @return <tt>java.util.Locale</tt> object corresponding to the given
  locale string, or the runtime's default locale if the locale string is
  null or empty
  @throws IllegalArgumentException if the given locale does not have a
  language component or has an empty country component