{"record":{"id":"cb5a2032f2c3a7ff","repo":"pentaho/pentaho-kettle","slug":"error-closing-resultset-after-getting-synonyms-from-schema","errorCode":null,"errorMessage":"Error closing resultset after getting synonyms from schema []","messagePattern":"Error closing resultset after getting synonyms from schema \\[\\]","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":4478,"sourceCode":"        }\n\n        String table = alltables.getString( TABLES_META_DATA_TABLE_NAME );\n\n        if ( log.isRowLevel() ) {\n          log.logRowlevel( toString(), \"got synonym from meta-data: \"\n            + databaseMeta.getQuotedSchemaTableCombination( schema, table ) );\n        }\n        multimapPut( schema, table, synonymMap );\n      }\n    } catch ( SQLException e ) {\n      throw new KettleDatabaseException( \"Error getting synonyms from schema [\" + schemaname + \"]\", e );\n    } finally {\n      try {\n        if ( alltables != null ) {\n          alltables.close();\n        }\n      } catch ( SQLException e ) {\n        throw new KettleDatabaseException( \"Error closing resultset after getting synonyms from schema [\"\n          + schemaname + \"]\", e );\n      }\n    }\n\n    if ( log.isDetailed() ) {\n      log.logDetailed( \"read :\" + multimapSize( synonymMap ) + \" synonyms from db meta-data.\" );\n    }\n\n    return synonymMap;\n  }\n\n  private <K, V> void multimapPut( final K key, final V value, final Map<K, Collection<V>> map ) {\n    Collection<V> valueCollection = map.get( key );\n    if ( valueCollection == null ) {\n      valueCollection = new HashSet<>();\n    }\n    valueCollection.add( value );\n    map.put( key, valueCollection );","sourceCodeStart":4460,"sourceCodeEnd":4496,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L4460-L4496","documentation":"Thrown in the finally block of the synonym enumeration when the JDBC ResultSet cannot be closed. The synonym listing may have completed, but cursor cleanup failed, indicating a broken connection or driver cursor-close failure. Wrapped as KettleDatabaseException.","triggerScenarios":"Database.getSynonyms(...) where alltables ResultSet is non-null but close() throws SQLException — stale/dropped connection, driver cursor invalidation after a metadata error, or concurrent use of the connection.","commonSituations":"Oracle session killed mid metadata query; connection idle-timeout during long synonym scans; calling synonyms after an earlier SQLException already invalidated the driver's cursor state.","solutions":["Reconnect (checkConnection/disconnect+connect) before metadata calls on long-lived Database objects.","Avoid sharing one Database instance across threads; use one per thread.","Check DB/network logs for session drops (firewall, listener) and raise idle timeouts.","Inspect the chained SQLException cause to identify the driver-level failure."],"exampleFix":"// before\nList<String> syns = db.getSynonyms(false, schema); // long idle gap before call\n\n// after\nif (!db.checkConnection()) { db.disconnect(); db.connect(); }\nList<String> syns = db.getSynonyms(false, schema);","handlingStrategy":"try-catch","validationCode":"if (!db.checkConnection()) { db.disconnect(); db.connect(); }","typeGuard":"boolean connectionAlive(Database db) { return db != null && db.getConnection() != null; }","tryCatchPattern":"try {\n  synonyms = db.getSynonyms(false, schema);\n} catch (KettleDatabaseException e) {\n  log.warn(\"Synonym resultset close failed, reconnecting: \" + e.getMessage());\n  db.disconnect(); db.connect();\n}","preventionTips":["Reconnect after long idle periods before metadata reads","Avoid multi-threaded sharing of Database instances","Monitor for session kills in DB/network logs","Keep JDBC driver versions current"],"tags":["jdbc","database-metadata","resultset","connection"],"backgroundTag":"database-query-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}