<p>findPossibleConstructor.</p>

@param klass a {@link java.lang.Class} object.
@param args a {@link java.lang.Object} object.
@param <T> a T object.
@return a {@link java.lang.reflect.Constructor} object.
@throws java.lang.NoSuchMethodException if any.
979179
@SuppressWarnings({"unchecked"})
    public static <T> Constructor<T> findPossibleConstructor( Class<T> klass, Object... args ) throws NoSuchMethodException
    {
        for (Constructor constructor : klass.getConstructors())
        {
            if (arityMatches(constructor, args)) return constructor;
        }

        throw noSuitableConstructorException(klass, args);
    }
1078121
public static Object getGenInstance(Class<?> cls, Object... args) throws ParserException
    {
        Class<?> parserClass = getGenClass(cls);
        try
        {
            if (args.length == 0)
            {
                return parserClass.newInstance();
            }
            else
            {
                for (Constructor constructor : parserClass.getConstructors())
                {
                    Class[] parameterTypes = constructor.getParameterTypes();
                    if (parameterTypes.length == args.length)
                    {
                        boolean match = true;
                        int index = 0;
                        for (Class c : parameterTypes)
                        {
                            if (!c.isAssignableFrom(args[index++].getClass()))
                            {
                                match = false;
                                break;
                            }
                        }
                        if (match)
                        {
                            return constructor.newInstance(args);
                        }
                    }
                }
                throw new IllegalArgumentException("no required constructor for "+cls);
            }
        }

        catch (InstantiationException | IllegalAccessException | SecurityException | IllegalArgumentException | InvocationTargetException ex)
        {
            throw new ParserException(ex);
        }
    }
941710
protected MethodNode checkGroovyStyleConstructor(final ClassNode node, final ClassNode[] arguments, final ASTNode source) {
        if (node.equals(ClassHelper.OBJECT_TYPE) || node.equals(ClassHelper.DYNAMIC_TYPE)) {
            // in that case, we are facing a list constructor assigned to a def or object
            return null;
        }
        List<ConstructorNode> constructors = node.getDeclaredConstructors();
        if (constructors.isEmpty() && arguments.length == 0) {
            return null;
        }
        List<MethodNode> constructorList = findMethod(node, "<init>", arguments);
        if (constructorList.isEmpty()) {
            if (isBeingCompiled(node) && arguments.length == 1 && LINKEDHASHMAP_CLASSNODE.equals(arguments[0])) {
                // there will be a default hash map constructor added later
                ConstructorNode cn = new ConstructorNode(Opcodes.ACC_PUBLIC, new Parameter[]{
                        new Parameter(LINKEDHASHMAP_CLASSNODE, "args")
                }, ClassNode.EMPTY_ARRAY, EmptyStatement.INSTANCE);
                return cn;
            } else {
                addStaticTypeError("No matching constructor found: " + node + toMethodParametersString("<init>", arguments), source);
                return null;
            }
        } else if (constructorList.size() > 1) {
            addStaticTypeError("Ambiguous constructor call " + node + toMethodParametersString("<init>", arguments), source);
            return null;
        }
        return constructorList.get(0);
    }
79703
@SafeVarargs
    public static <T> Constructor<T> getDeclaredConstructor(final Class<T> cls, final Class<?>... parameterTypes) {
        Map<Class<?>[], Constructor<?>> constructorPool = classDeclaredConstructorPool.get(cls);
        Constructor<T> constructor = null;

        if (constructorPool != null) {
            constructor = (Constructor<T>) constructorPool.get(parameterTypes);
        }

        if (constructor == null) {
            try {
                constructor = cls.getDeclaredConstructor(parameterTypes);

                // SHOULD NOT set it true here.
                // constructor.setAccessible(true);
            } catch (NoSuchMethodException e) {
                // ignore.
            }

            if (constructor != null) {
                if (constructorPool == null) {
                    constructorPool = new ArrayHashMap<>(ConcurrentHashMap.class);
                    classDeclaredConstructorPool.put(cls, constructorPool);
                }

                constructorPool.put(parameterTypes.clone(), constructor);
            }
        }

        return constructor;
    }
515317
private static Constructor<?> getConstructor(final Class<?> genericClass, final Class<?>[] constructorParameterTypes) {
        Constructor<?> constructor = null;
        try {
            constructor = genericClass.getConstructor(constructorParameterTypes);
        } catch (final NoSuchMethodException e) {
            // Return the first constructor as a workaround
            constructor = genericClass.getConstructors()[0];
        } catch (final SecurityException e) {
            LOGGER.log(NO_CONSTRUCTOR, e);
            throw e; // Pop up the exception to let it managed by the caller method
        }
        return constructor;
    }
850471
private static Object callConstructor(final Class<?> cls, final Class<?>[] argTypes,
      final Object[] args) {
    try {
      final Constructor<?> cons = cls.getConstructor(argTypes);
      return cons.newInstance(args);
    } catch (final InvocationTargetException e) {
      throw getCause(e);
    } catch (final IllegalAccessException | NoSuchMethodException | InstantiationException e) {
      throw new IllegalStateException(e);
    }
  }
497311
public static void instanceOf(final Object arg, final Class<?> clazz, final String name) {
        
        if(arg == null) {
            throw new IllegalArgumentException(String.format("%s should not be null.", name));
        }
        
        if(!clazz.isAssignableFrom(arg.getClass())) {
            throw new IllegalArgumentException(String.format("%s should not be class with '%s'.", name, clazz.getName()));
        }
        
    }
40966
@SuppressWarnings("unchecked")
    public static <T> T instantiate(final Class<T> tClass) {
        try {
            if(tClass == null)
                return null;

            final Constructor<?> zeroArgConstructor = Arrays.stream(tClass.getDeclaredConstructors())
                    .filter(c -> c.getParameterCount() == 0)
                    .findFirst().orElse(null);

            if(zeroArgConstructor == null) {
                logger.warning("[CAN NOT INSTANTIATE] : " + tClass + ", have NO zero arg constructor.");
                return null;
            }

            return ((T) zeroArgConstructor.newInstance());
        } catch (InstantiationException | InvocationTargetException e) {
            logger.warning("[CAN NOT INSTANTIATE] : " + tClass
                    + " - class may be an abstract class, an interface, "
                    + "array, primitive." + e.getMessage());
        } catch (IllegalAccessException e) {
            logger.warning("[CAN NOT INSTANTIATE] : " + tClass
                    + " - no access to instantiating object." + e.getMessage());
        }
        return null;
    }
598892
public static <T> Constructor<T> getConstructor(Class<T> instantiable, Class<?>... constructorParameterTypes)
    {
        try
        {
            return instantiable.getConstructor(constructorParameterTypes);
        }
        catch (NoSuchMethodException ignored)
        {
            return ReflectionHelper.searchForConstructor(instantiable, constructorParameterTypes);
        }
    }
1097729
public static @Nonnull <T> Optional<T> tryInstantiate(@Nonnull Constructor<T> type, Object... args) {
        try {
            return Optional.of(type.newInstance(args));
        } catch (Throwable e) {
            Logger log = ClassUtils.REFLECTION_LOGGER;
            if (log.isDebugEnabled()) {
                log.debug("Tried, but could not instantiate type: " + type, e);
            }
            return Optional.empty();
        }
    }
1150409
public static Object invokeConstructor(Class<?> clazz, Object... args) {
    try {
      return InvokerHelper.invokeConstructorOf(clazz, args);
    } catch (InvokerInvocationException e) {
      ExceptionUtil.sneakyThrow(e.getCause());
      return null; // never reached
    }
  }
54026
static KryoInstantiator reflect(Class<? extends KryoInstantiator> instClass, Config optConf)
    throws ConfigurationException {
    try {
      try {
        return instClass.getConstructor(Config.class).newInstance(optConf);
      } catch (NoSuchMethodException ex3) {
        return instClass.newInstance();
      }
    }
    catch(InstantiationException x) {
      throw new ConfigurationException(x);
    }
    catch(IllegalAccessException x) {
      throw new ConfigurationException(x);
    }
    catch(InvocationTargetException x) {
      throw new ConfigurationException(x);
    }
  }
216518
private static NoSuchBeingException missingConstructorException(Class<?> clazz, Object... arguments)
  {
    Type[] types = new Type[arguments.length];
    for(int i = 0; i < arguments.length; ++i) {
      types[i] = arguments[i].getClass();
    }
    return new NoSuchBeingException("Missing constructor(%s) for |%s|.", Arrays.toString(types), clazz);
  }
1075736
public static Object callConstructor(final Class<?> cls, final Object... args) {
    return callConstructor(cls, getTypes(args), args);
  }
1271839
public static <T> Constructor<T> bestConstructor(Class<T> clazz, Class<?>[] argTypes) throws AmbiguousConstructorMatchException {
        return bestConstructor(collectConstructors(clazz), argTypes);
    }
1254568
private ClassModel getClassModelFromArg(KernelArg arg, final Class<?> arrayClass) {
	  ClassModel c = null;
      if (arg.getObjArrayElementModel() == null) {
          final String tmp = arrayClass.getName().substring(2).replace('/', '.');
          final String arrayClassInDotForm = tmp.substring(0, tmp.length() - 1);

          if (logger.isLoggable(Level.FINE)) {
             logger.fine("looking for type = " + arrayClassInDotForm);
          }

          // get ClassModel of obj array from entrypt.objectArrayFieldsClasses
          c = entryPoint.getObjectArrayFieldsClasses().get(arrayClassInDotForm);
          arg.setObjArrayElementModel(c);
       } else {
          c = arg.getObjArrayElementModel();
       }
       assert c != null : "should find class for elements " + arrayClass.getName();
       
       return c;
   }
9837
public static <T> Clazz<T> FindClazz( Class<T> clazz )
	{
		return impl.FindClazz( clazz );
	}