{"record":{"id":"90ce55f8fcdb9b0a","repo":"tursodatabase/turso","slug":"the-resultset-is-not-open","errorCode":null,"errorMessage":"The resultSet is not open","messagePattern":"The resultSet is not open","errorType":"exception","errorClass":"java.sql.SQLException","httpStatus":null,"severity":"error","filePath":"bindings/java/src/main/java/tech/turso/core/TursoResultSet.java","lineNumber":74,"sourceCode":"    while (next()) {}\n  }\n\n  /**\n   * Moves the cursor forward one row from its current position. A {@link TursoResultSet} cursor is\n   * initially positioned before the first fow; the first call to the method <code>next</code> makes\n   * the first row the current row; the second call makes the second row the current row, and so on.\n   * When a call to the <code>next</code> method returns <code>false</code>, the cursor is\n   * positioned after the last row.\n   *\n   * <p>Note that turso only supports <code>ResultSet.TYPE_FORWARD_ONLY</code>, which means that the\n   * cursor can only move forward.\n   *\n   * @return true if the new current row is valid; false if there are no more rows\n   * @throws SQLException if a database access error occurs\n   */\n  public boolean next() throws SQLException {\n    if (!open) {\n      throw new SQLException(\"The resultSet is not open\");\n    }\n\n    if (isEmptyResultSet || pastLastRow) {\n      return false; // completed ResultSet\n    }\n\n    if (maxRows != 0 && row == maxRows) {\n      return false;\n    }\n\n    lastStepResult = this.statement.step();\n    log.debug(\"lastStepResult: {}\", lastStepResult);\n    if (lastStepResult.isRow()) {\n      row++;\n    }\n\n    if (lastStepResult.isInInvalidState()) {\n      open = false;","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/java/src/main/java/tech/turso/core/TursoResultSet.java#L56-L92","documentation":"next() checks the open flag before stepping; on a closed set it throws this SQLException instead of returning false. The set is closed explicitly by close() and implicitly by next() itself after an invalid native step result. Note the wording differs from the equivalent guards elsewhere in the same class ('The result set is not open' in consumeAll, 'ResultSet closed' in checkOpen), so branching on exact message text is fragile.","triggerScenarios":"Calling next() after close(); continuing a while (rs.next()) loop after another thread or helper closed the set; stepping again after a prior invalid-state step auto-closed the set.","commonSituations":"Utility methods closing result sets they do not own while the outer loop keeps stepping; cancellation/timeout paths racing with iteration; double-processing in retry logic.","solutions":["Guard iteration when the set is shared: while (rs.isOpen() && rs.next())","Give exactly one component ownership of close(); prefer try-with-resources at the outermost caller only","After catching a step() invalid-result error, discard the set and re-execute instead of stepping again"],"exampleFix":"// before\nwhile (rs.next()) { /* ... */ } // throws if closed elsewhere\n\n// after\nwhile (rs.isOpen() && rs.next()) { /* ... */ }\n// one owner closes unconditionally afterwards","handlingStrategy":"validation","validationCode":"while (rs.isOpen() && rs.next()) {\n  // process row\n}","typeGuard":null,"tryCatchPattern":"try {\n  while (rs.next()) { /* ... */ }\n} catch (SQLException e) {\n  // set is dead (auto-closed): stop iterating; re-execute on a fresh statement if needed\n}","preventionTips":["One owner for close(); use try-with-resources at the outermost caller only","After catching any step error, discard the ResultSet instead of stepping again","Never share a live ResultSet across threads"],"tags":["java","jdbc","result-set","iteration","resource-lifecycle"],"backgroundTag":"result-set-closed","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}