Aapo Haapanen created DBCP-596: ---------------------------------- Summary: PoolingConnection.toString() causes StackOverflowError Key: DBCP-596 URL: https://issues.apache.org/jira/browse/DBCP-596 Project: Commons DBCP Issue Type: Bug Affects Versions: 2.11.0 Reporter: Aapo Haapanen
{{{}PoolingConnection{}}}, as it is constructed by {{PoolableConnectionFactory.makeObject()}} method, causes StackOverflowError in its {{toString()}} method. {{PoolingConnection}} acts as the object factory for the statement pool, while {{GenericKeyedObjectPool}} implements the statement pool. {{PoolingConnection.toString()}} calls the pool's {{toString()}} method, while {{GenericKeyedObjectPool.toStringAppendFields()}} calls the factory's {{{}toString(){}}}. Here is small test application that causes StackOverflowError: {code:java} import org.apache.commons.dbcp2.DelegatingPreparedStatement; import org.apache.commons.dbcp2.PoolingConnection; import org.apache.commons.pool2.impl.GenericKeyedObjectPool; import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; public class Main { public static void main(String[] args) { final var conn = new PoolingConnection(null); final var config = new GenericKeyedObjectPoolConfig<DelegatingPreparedStatement>(); final var stmtPool = new GenericKeyedObjectPool<>(conn, config); conn.setStatementPool(stmtPool); conn.toString(); } } {code} In normal use cases this doesn't cause a problem, but we've encountered this bug in some situations with network connectivity problems. -- This message was sent by Atlassian Jira (v8.20.10#820010)