From a568cb297c2b4d3fef5900a9e56a6e4e06e65be1 Mon Sep 17 00:00:00 2001 From: Scott Leberknight <174812+sleberknight@users.noreply.github.com> Date: Sat, 25 Nov 2023 13:49:46 -0500 Subject: [PATCH] Fix CodeQL code scanning alert in ApplicationErrorJdbcTest Even though it's a test, better to do it correctly and ensure the Statement and ResultSet are closed using try-with-resources --- .../error/dao/ApplicationErrorJdbcTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/kiwiproject/dropwizard/error/dao/ApplicationErrorJdbcTest.java b/src/test/java/org/kiwiproject/dropwizard/error/dao/ApplicationErrorJdbcTest.java index 31c0560..ae21424 100644 --- a/src/test/java/org/kiwiproject/dropwizard/error/dao/ApplicationErrorJdbcTest.java +++ b/src/test/java/org/kiwiproject/dropwizard/error/dao/ApplicationErrorJdbcTest.java @@ -173,12 +173,13 @@ void shouldMigrate_H2InMemoryDatabase() throws SQLException { ApplicationErrorJdbc.migrateDatabase(conn); - var stmt = conn.createStatement(); - var rs = stmt.executeQuery("select * from databasechangelog"); - nextOrThrow(rs); + try (var stmt = conn.createStatement()) { + var rs = stmt.executeQuery("select * from databasechangelog"); + nextOrThrow(rs); - var filename = rs.getString("filename"); - assertThat(filename).isEqualTo("dropwizard-app-errors-migrations.xml"); + var filename = rs.getString("filename"); + assertThat(filename).isEqualTo("dropwizard-app-errors-migrations.xml"); + } } }