From 1b317cf2eded59e946234dbc729a42d7a5698114 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Fri, 6 Sep 2024 20:00:07 +0100 Subject: [PATCH] Fix for Bug#108415 (Bug#34579258), NullPointerException in AbstractQuery::stopQueryTimer. Change-Id: I5a71825d70dd03dc0088ecaa71e743ac3e52ac8e --- CHANGES | 3 ++ .../java/com/mysql/cj/AbstractQuery.java | 4 ++- .../regression/StatementRegressionTest.java | 33 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index d197be6e8..e9c48e140 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,9 @@ Version 9.1.0 + - Fix for Bug#108415 (Bug#34579258), NullPointerException in AbstractQuery::stopQueryTimer. + Thanks to Anthony Milbourne for his contribution. + - Fix for Bug#115265 (Bug#36843227), Second stored procedure call with cacheCallableStmts might fail. - Fix for Bug#36936407, PrepareCall method doesn't work as expected when DB name is involved. diff --git a/src/main/core-impl/java/com/mysql/cj/AbstractQuery.java b/src/main/core-impl/java/com/mysql/cj/AbstractQuery.java index a10ef5ee1..04a528932 100644 --- a/src/main/core-impl/java/com/mysql/cj/AbstractQuery.java +++ b/src/main/core-impl/java/com/mysql/cj/AbstractQuery.java @@ -235,7 +235,9 @@ public void stopQueryTimer(CancelQueryTask timeoutTask, boolean rethrowCancelRea throw ExceptionFactory.createException(t.getMessage(), t); } - this.session.getCancelTimer().purge(); + if (this.session != null) { + this.session.getCancelTimer().purge(); + } if (checkCancelTimeout) { checkCancelTimeout(); diff --git a/src/test/java/testsuite/regression/StatementRegressionTest.java b/src/test/java/testsuite/regression/StatementRegressionTest.java index f3541255e..c679c7257 100644 --- a/src/test/java/testsuite/regression/StatementRegressionTest.java +++ b/src/test/java/testsuite/regression/StatementRegressionTest.java @@ -13796,4 +13796,37 @@ public void testBug112790() throws Exception { assertThrows(SQLException.class, this.stmt::getGeneratedKeys); } + /** + * Tests fix for Bug#108415 (Bug#34579258), NullPointerException in AbstractQuery::stopQueryTimer. + * + * @throws Exception + */ + @Test + void testBug108415() throws Exception { + Connection testConn = getNewConnection(); + final long sessionToKill = ((JdbcConnection) testConn).getId(); + + ExecutorService execServ = Executors.newSingleThreadExecutor(); + execServ.execute(() -> { + try { + TimeUnit.SECONDS.sleep(2); + } catch (InterruptedException e) { + } + try { + System.out.println("Killing process id " + sessionToKill); + this.stmt.execute("KILL " + sessionToKill); + } catch (SQLException e) { + } + }); + + Statement testStmt = testConn.createStatement(); + testStmt.setQueryTimeout(15); + assertThrows(SQLException.class, () -> { + testStmt.executeQuery("SELECT SLEEP(15)"); + return null; + }); + + execServ.shutdown(); + } + }