{"record":{"id":"7de329e50d329ccb","repo":"t8y2/dbx","slug":"not-connected-7de329","errorCode":null,"errorMessage":"Not connected","messagePattern":"Not connected","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"agents/common/src/main/java/com/dbx/agent/DatabaseAgent.java","lineNumber":163,"sourceCode":"\n    List<ForeignKeyInfo> listForeignKeys(String schema, String table);\n\n    List<TriggerInfo> listTriggers(String schema, String table);\n\n    default QueryResult executeQuery(String sql, String schema) {\n        return executeQuery(sql, schema, new ExecuteQueryOptions());\n    }\n\n    QueryResult executeQuery(String sql, String schema, ExecuteQueryOptions options);\n\n    default QueryPageResult executeQueryPage(String sql, String schema) {\n        return executeQueryPage(sql, schema, new QueryPageOptions());\n    }\n\n    default QueryPageResult executeQueryPage(String sql, String schema, QueryPageOptions options) {\n        Connection conn = getConnection();\n        if (conn == null) {\n            throw new IllegalStateException(\"Not connected\");\n        }\n        return AgentExecutionContext.jdbcExecutor().executePage(\n            conn,\n            sql,\n            schema,\n            this::setSchemaSQL,\n            this::resetSchemaSQL,\n            options,\n            AgentExecutionContext.jdbcExecutor()::defaultResultValue\n        );\n    }\n\n    default QueryPageResult fetchQueryPage(String sessionId, int pageSize) {\n        return AgentExecutionContext.jdbcExecutor().fetchPage(sessionId, pageSize);\n    }\n\n    default boolean closeQuerySession(String sessionId) {\n        return AgentExecutionContext.jdbcExecutor().closeQuerySession(sessionId);","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/common/src/main/java/com/dbx/agent/DatabaseAgent.java#L145-L181","documentation":"executeQueryPage() checks getConnection() before handing the SQL to the JDBC executor. If no connection is established (never connected, disconnected, or the connection was lost and set to null), it throws IllegalStateException(\"Not connected\") instead of attempting a query on a null Connection.","triggerScenarios":"Calling executeQueryPage(sql, schema) or executeQueryPage(sql, schema, options) before connect() succeeded, after disconnect(), or when the agent implementation's getConnection() returns null because the underlying connection died and was not re-established.","commonSituations":"App started paging queries before the connect call completed; the database restarted and the agent's stored connection is null; a long-lived session was disconnected by a timeout and pagination is attempted afterwards.","solutions":["Call connect(params) (and verify testConnection succeeds) before issuing executeQueryPage.","Before querying, validate agent.getConnection() != null and reconnect if null.","Catch IllegalStateException and trigger a reconnect + retry of the paged query.","Investigate why the connection is null (network drop, server restart, driver timeout) and add reconnect-on-failure logic."],"exampleFix":"// before\nQueryPageResult r = agent.executeQueryPage(sql, schema);\n// after\nif (agent.getConnection() == null) {\n    agent.connect(params);\n}\nQueryPageResult r = agent.executeQueryPage(sql, schema);","handlingStrategy":"validation","validationCode":"if (agent.getConnection() == null) {\n    agent.connect(params); // or throw a friendly 'reconnect required' error\n}","typeGuard":"static boolean isConnected(DatabaseAgent a) {\n    return a.getConnection() != null;\n}","tryCatchPattern":"try {\n    return agent.executeQueryPage(sql, schema, options);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Not connected\")) {\n        agent.connect(params);\n        return agent.executeQueryPage(sql, schema, options);\n    }\n    throw e;\n}","preventionTips":["Always call connect() (and check its result) before any query API.","Check getConnection() != null before paginated queries in long-lived sessions.","Implement reconnect-on-failure in the layer that owns agent lifecycle.","Handle database restarts/timeouts by resetting the agent instead of reusing a dead connection."],"tags":["connection-state","jdbc","lifecycle"],"backgroundTag":"not-connected","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}