static Class getFactoryType()

in src/main/java/org/apache/commons/pool3/impl/PoolImplUtils.java [44:67]


    static Class<?> getFactoryType(final Class<? extends PooledObjectFactory> factoryClass) {
        final Class<PooledObjectFactory> type = PooledObjectFactory.class;
        final Object genericType = getGenericType(type, factoryClass);
        if (genericType instanceof Integer) {
            // POOL-324 org.apache.commons.pool3.impl.GenericObjectPool.getFactoryType() throws
            // java.lang.ClassCastException
            //
            // A bit hackish, but we must handle cases when getGenericType() does not return a concrete types.
            final ParameterizedType pi = getParameterizedType(type, factoryClass);
            if (pi != null) {
                final Type[] bounds = ((TypeVariable) pi.getActualTypeArguments()[((Integer) genericType).intValue()])
                        .getBounds();
                if (bounds != null && bounds.length > 0) {
                    final Type bound0 = bounds[0];
                    if (bound0 instanceof Class) {
                        return (Class<?>) bound0;
                    }
                }
            }
            // last resort: Always return a Class
            return Object.class;
        }
        return (Class<?>) genericType;
    }