From a3abe36554c024089a13517bb2e0a2dad4c6974d Mon Sep 17 00:00:00 2001 From: Adarsh-Me <122873385+Adarsh-Me@users.noreply.github.com> Date: Wed, 9 Sep 2026 08:15:51 +0000 Subject: [PATCH] Fix #13549: treat metadata result sets without a statement as open --- .../jdbc/thin/JdbcThinResultSetSelfTest.java | 26 +++++++++++++++++++ .../internal/jdbc/thin/JdbcThinResultSet.java | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinResultSetSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinResultSetSelfTest.java index 016850d125e70..b5f40328d58d9 100644 --- a/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinResultSetSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/jdbc/thin/JdbcThinResultSetSelfTest.java @@ -26,6 +26,7 @@ import java.sql.Blob; import java.sql.Clob; import java.sql.Connection; +import java.sql.DatabaseMetaData; import java.sql.Date; import java.sql.DriverManager; import java.sql.NClob; @@ -1882,6 +1883,31 @@ public void testExceptionOnClosedResultSet() throws Exception { }); } + /** + * Tests that metadata result sets, which are created without an associated statement (stmt == null), + * report a usable (not closed) state, in line with {@link ResultSet#isClosed()} semantics. + * + * @throws Exception If failed. + */ + @Test + public void testMetadataResultSetIsClosed() throws Exception { + DatabaseMetaData meta = stmt.getConnection().getMetaData(); + + ResultSet rs = meta.getTables(null, null, "%", null); + + // Metadata result sets are created without a statement and must be usable, not reported as closed. + assertFalse("Metadata result set must not be reported as closed", rs.isClosed()); + + // The result set must be iterable/usable. + while (rs.next()) + rs.getString("TABLE_NAME"); + + // Explicitly closing the metadata result set must mark it as closed. + rs.close(); + + assertTrue("Explicitly closed metadata result set must be reported as closed", rs.isClosed()); + } + /** * Test object. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinResultSet.java b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinResultSet.java index 58cb64c04e44e..86df0c5d20a00 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinResultSet.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinResultSet.java @@ -1487,7 +1487,7 @@ else if (cls == String.class || cls == Character.class) { /** {@inheritDoc} */ @Override public boolean isClosed() throws SQLException { - return closed || stmt == null || stmt.connection().isClosed(); + return closed || (stmt != null && stmt.connection().isClosed()); } /** {@inheritDoc} */