Search in sources :

Example 1 with ObjectInstantiationException

use of org.gradle.internal.reflect.ObjectInstantiationException in project gradle by gradle.

the class DependencyInjectingInstantiator method newInstance.

public <T> T newInstance(Class<? extends T> type, Object... parameters) {
    try {
        CachedConstructor cached = cachedConstructors.get(type);
        if (cached.error != null) {
            throw cached.error;
        }
        Constructor<?> constructor = cached.constructor;
        Object[] resolvedParameters = convertParameters(type, constructor, parameters);
        try {
            Object instance = constructor.newInstance(resolvedParameters);
            if (instance instanceof WithServiceRegistry) {
                ((WithServiceRegistry) instance).setServices(services);
            }
            return type.cast(instance);
        } catch (InvocationTargetException e) {
            throw e.getCause();
        }
    } catch (Throwable e) {
        throw new ObjectInstantiationException(type, e);
    }
}
Also used : ObjectInstantiationException(org.gradle.internal.reflect.ObjectInstantiationException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ObjectInstantiationException (org.gradle.internal.reflect.ObjectInstantiationException)1