From 5be4e8cb1b01ef80ba464de9b108ba0983078cad Mon Sep 17 00:00:00 2001 From: Alexander Soklakov Date: Wed, 17 Feb 2021 14:53:31 +0400 Subject: [PATCH] Fix for Bug#22508715, SETSESSIONMAXROWS() CALL ON CLOSED CONNECTION RESULTS IN NPE. --- CHANGES | 2 ++ .../java/com/mysql/cj/jdbc/ConnectionImpl.java | 3 ++- .../regression/ConnectionRegressionTest.java | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 72372da30..596e22873 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,8 @@ Version 8.0.24 + - Fix for Bug#22508715, SETSESSIONMAXROWS() CALL ON CLOSED CONNECTION RESULTS IN NPE. + - Fix for Bug#102131 (32338451), UPDATABLERESULTSET NPE WHEN USING DERIVED QUERIES OR VIEWS. - Fix for Bug#101596 (32151143), GET THE 'HOST' PROPERTY ERROR AFTER CALLING TRANSFORMPROPERTIES() METHOD. diff --git a/src/main/user-impl/java/com/mysql/cj/jdbc/ConnectionImpl.java b/src/main/user-impl/java/com/mysql/cj/jdbc/ConnectionImpl.java index 6d5b6cb46..b8aa34781 100644 --- a/src/main/user-impl/java/com/mysql/cj/jdbc/ConnectionImpl.java +++ b/src/main/user-impl/java/com/mysql/cj/jdbc/ConnectionImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2020, Oracle and/or its affiliates. + * Copyright (c) 2002, 2021, Oracle and/or its affiliates. * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, version 2.0, as published by the @@ -2426,6 +2426,7 @@ public int getSessionMaxRows() { @Override public void setSessionMaxRows(int max) throws SQLException { synchronized (getConnectionMutex()) { + checkClosed(); if (this.session.getSessionMaxRows() != max) { this.session.setSessionMaxRows(max); this.session.execSQL(null, "SET SQL_SELECT_LIMIT=" + (this.session.getSessionMaxRows() == -1 ? "DEFAULT" : this.session.getSessionMaxRows()), diff --git a/src/test/java/testsuite/regression/ConnectionRegressionTest.java b/src/test/java/testsuite/regression/ConnectionRegressionTest.java index a82eaaa5f..e584ee662 100644 --- a/src/test/java/testsuite/regression/ConnectionRegressionTest.java +++ b/src/test/java/testsuite/regression/ConnectionRegressionTest.java @@ -11796,4 +11796,21 @@ public Properties transformProperties(Properties props) { return props; } } + + /** + * Tests fix for Bug#22508715, SETSESSIONMAXROWS() CALL ON CLOSED CONNECTION RESULTS IN NPE. + * + * @throws Exception + */ + @Test + public void testBug22508715() throws Exception { + Properties props = new Properties(); + Connection con = getConnectionWithProps(props); + con.close(); + + assertThrows(SQLNonTransientConnectionException.class, "No operations allowed after connection closed.*", () -> { + ((JdbcConnection) con).setSessionMaxRows(0); + return null; + }); + } }