Skip to content

Commit

Permalink
OF-2800: Guard against surplus Exceptions when closing transactional …
Browse files Browse the repository at this point in the history
…connection

All other methods that close database resources perform a null-check. This commit applies the same check when closing a transactional connection.

This prevents (additional) NullPointerExceptions from being logged when a transactional connection that could not be obtained (and thus is null) is 'closed'.
  • Loading branch information
guusdk committed Feb 17, 2024
1 parent 552254e commit ca49f0b
Showing 1 changed file with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2004-2008 Jive Software, 2017-2022 Ignite Realtime Foundation. All rights reserved.
* Copyright (C) 2004-2008 Jive Software, 2017-2024 Ignite Realtime Foundation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -244,28 +244,30 @@ public static void closeTransactionConnection(PreparedStatement pstmt, Connectio
* @param abortTransaction true if the transaction should be rolled back.
*/
public static void closeTransactionConnection(Connection con, boolean abortTransaction) {
// Rollback or commit the transaction
if (isTransactionsSupported()) {
try {
if (abortTransaction) {
con.rollback();
if (con != null) {
// Rollback or commit the transaction
if (isTransactionsSupported()) {
try {
if (abortTransaction) {
con.rollback();
}
else {
con.commit();
}
}
else {
con.commit();
catch (Exception e) {
Log.error(e.getMessage(), e);
}
// Reset the connection to auto-commit mode.
try {
con.setAutoCommit(true);
}
catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
catch (Exception e) {
Log.error(e.getMessage(), e);
}
// Reset the connection to auto-commit mode.
try {
con.setAutoCommit(true);
}
catch (Exception e) {
Log.error(e.getMessage(), e);
}
closeConnection(con);
}
closeConnection(con);
}

/**
Expand Down

0 comments on commit ca49f0b

Please sign in to comment.