public static String getTypeName(Type type) {
    if (type == null)
      return "null";
    
    if (! (type instanceof Class<?>))
      return type.toString();
  
    Class<?> cls = (Class<?>) type;
    if (cls.isArray()) {
      // ??? in Field.getTypeName, this block was wrapped with a try block
      // which allowed a Throwable to simply fall through. Why? 
      Class<?> cl = cls;
      StringBuilder rank = new StringBuilder();
      while (cl.isArray()) {
        rank.append("[]");
        cl = cl.getComponentType();
      }

      return new StringBuilder(cl.getName()).append(rank.toString()).toString();
    }
  
    return cls.getName();
  }