Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalArgumentException: repeated interface: java.sql.Connection with HikariDataSource #25

Open
radist-nt opened this issue May 22, 2017 · 0 comments

Comments

@radist-nt
Copy link

java.lang.IllegalArgumentException: repeated interface: java.sql.Connection
	at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:597)
	at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:557)
	at java.lang.reflect.WeakCache$Factory.get(WeakCache.java:230)
	at java.lang.reflect.WeakCache.get(WeakCache.java:127)
	at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:419)
	at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:719)
	at org.jdbcdslog.ProxyUtils.proxyForCompatibleInterfaces(ProxyUtils.java:46)
	at org.jdbcdslog.ProxyUtils.wrapByConnectionProxy(ProxyUtils.java:84)
	at org.jdbcdslog.DataSourceProxyBase.getConnection(DataSourceProxyBase.java:48)
...

This happens because HikariDataSource provides HikariProxyConnection (implements Connection) object that inherits ProxyConnection (implements Connection).

Proposed fix for method org.jdbcdslog.ProxyUtils.findCompatibleInterfaces(Class, Class) is

    /**
     * Find all interfaces of clazz that is-a requiredInterface.
     *
     * @param clazz
     * @param requiredInterface
     * @return
     */
    public static Class<?>[] findCompatibleInterfaces(Class<?> clazz, Class<?> requiredInterface) {
        IdentityHashMap<Class<?>, Object> interfaces = new IdentityHashMap<Class<?>, Object>();
        //ArrayList<Class<?>> interfaces = new ArrayList<Class<?>>();
        for ( ; ! clazz.equals(Object.class) ; clazz = clazz.getSuperclass()) {
            for (Class<?> iface : clazz.getInterfaces()) {
                if (requiredInterface.isAssignableFrom(iface)) {
                    //interfaces.add(iface);
                    interfaces.put(iface, null);
                }
            }
        }
        //return interfaces.toArray(EMPTY_CLASS_ARRAY);
        return interfaces.keySet().toArray(EMPTY_CLASS_ARRAY);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant