code: public static String decode(String s, Type t) {
          if (s == null) {
              throw new IllegalArgumentException();
          }
  
          final int n = s.length();
          if (n == 0) {
              return s;
          }
  
          // If there are no percent-escaped octets
          if (s.indexOf('%') < 0) {
              // If there are no '+' characters for query param
              if (t == Type.QUERY_PARAM) {
                  if (s.indexOf('+') < 0) {
                      return s;
                  }
              } else {
                  return s;
              }
          } else {
              // Malformed percent-escaped octet at the end
              if (n < 2) // TODO localize
              {
                  throw new IllegalArgumentException("Malformed percent-encoded octet at index 1");
              }
  
              // Malformed percent-escaped octet at the end
              if (s.charAt(n - 2) == '%') // TODO localize
              {
                  throw new IllegalArgumentException("Malformed percent-encoded octet at index " + (n - 2));
              }
          }
  
          if (t == null) {
              return decode(s, n);
          }
  
          switch (t) {
              case HOST:
                  return decodeHost(s, n);
              case QUERY_PARAM:
                  return decodeQueryParam(s, n);
              default:
                  return decode(s, n);
          }
      }
docs: Decodes characters of a string that are percent-encoded octets using
  UTF-8 decoding (if needed).
  <p>
  It is assumed that the string is valid according to an (unspecified) URI
  component type. If a sequence of contiguous percent-encoded octets is
  not a valid UTF-8 character then the octets are replaced with '\uFFFD'.
  <p>
  If the URI component is of type HOST then any "%" found between "[]" is
  left alone. It is an IPv6 literal with a scope_id.
  <p>
  If the URI component is of type QUERY_PARAM then any "+" is decoded as
  as ' '.
  <p>
  
  @param s the string to be decoded.
  @param t the URI component type, may be null.
  @return the decoded string.
  @throws IllegalArgumentException if a malformed percent-encoded octet is
  detected