This is an automated email from the ASF dual-hosted git repository.
yuqi4733 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 1af9e85883 [#8482] Improvement(catalog): In
PostgreSqlSchemaOperations.java fix potential resource leak (#8495)
1af9e85883 is described below
commit 1af9e858832f73b74b77b445202f2b22686306ca
Author: Xiaojian Sun <[email protected]>
AuthorDate: Wed Sep 10 20:27:46 2025 +0800
[#8482] Improvement(catalog): In PostgreSqlSchemaOperations.java fix
potential resource leak (#8495)
### What changes were proposed in this pull request?
In PostgreSqlSchemaOperations.java fix potential resource leak
### Why are the changes needed?
Fix: #([8482](https://github.com/apache/gravitino/issues/8482))
### Does this PR introduce _any_ user-facing change?
N/A
### How was this patch tested?
N/A
---
.../postgresql/operation/PostgreSqlSchemaOperations.java | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git
a/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/operation/PostgreSqlSchemaOperations.java
b/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/operation/PostgreSqlSchemaOperations.java
index 2865839512..3866821f52 100644
---
a/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/operation/PostgreSqlSchemaOperations.java
+++
b/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/operation/PostgreSqlSchemaOperations.java
@@ -76,8 +76,8 @@ public class PostgreSqlSchemaOperations extends
JdbcDatabaseOperations {
@Override
public List<String> listDatabases() {
List<String> result = new ArrayList<>();
- try (Connection connection = getConnection()) {
- ResultSet resultSet = getSchema(connection, null);
+ try (Connection connection = getConnection();
+ ResultSet resultSet = getSchema(connection, null)) {
while (resultSet.next()) {
String schemaName = resultSet.getString(1);
if (!isSystemDatabase(schemaName)) {
@@ -162,10 +162,11 @@ public class PostgreSqlSchemaOperations extends
JdbcDatabaseOperations {
}
public boolean schemaExists(Connection connection, String schema) throws
SQLException {
- ResultSet resultSet = getSchema(connection, schema);
- while (resultSet.next()) {
- if (Objects.equals(resultSet.getString(1), schema)) {
- return true;
+ try (ResultSet resultSet = getSchema(connection, schema)) {
+ while (resultSet.next()) {
+ if (Objects.equals(resultSet.getString(1), schema)) {
+ return true;
+ }
}
}
return false;