Skip to content

Commit

Permalink
[CONJ-1011] correcting possible NPE when using statement.cancel() tha…
Browse files Browse the repository at this point in the history
…t coincide with statement.close() in another thread
  • Loading branch information
rusher committed Sep 30, 2022
1 parent 6cfdd7e commit b6e80e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/main/java/org/mariadb/jdbc/MariaDbStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ public void close() throws SQLException {
closed = true;
if (results != null) {
if (results.getFetchSize() != 0) {
skipMoreResults();
skipMoreResults(protocol);
}

results.close();
Expand Down Expand Up @@ -972,17 +972,19 @@ public void setLocalInfileInputStream(InputStream inputStream) throws SQLExcepti
* <code>Statement</code>
*/
public void cancel() throws SQLException {
// use local protocol variable, in case statement is closed during cancellation
Protocol initialProtocol = this.protocol;
checkClose();
boolean locked = lock.tryLock();
try {
if (executing) {
protocol.cancelCurrentQuery();
initialProtocol.cancelCurrentQuery();
} else if (results != null
&& results.getFetchSize() != 0
&& !results.isFullyLoaded(protocol)) {
&& !results.isFullyLoaded(initialProtocol)) {
try {
protocol.cancelCurrentQuery();
skipMoreResults();
initialProtocol.cancelCurrentQuery();
skipMoreResults(initialProtocol);
} catch (SQLException e) {
// eat exception
}
Expand Down Expand Up @@ -1186,7 +1188,7 @@ public long getLargeUpdateCount() {
return -1;
}

protected void skipMoreResults() throws SQLException {
protected void skipMoreResults(Protocol protocol) throws SQLException {
try {
protocol.skip();
warningsCleared = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ public boolean executeBatchClient(
// INSERT INTO X(a,b) VALUES (1,2), (3,4), ...
executeBatchRewrite(results, prepareResult, parametersList, true);
return true;

}

if (options.useBulkStmts
Expand Down

0 comments on commit b6e80e2

Please sign in to comment.