coverity 1315774: improvement of code to negate false positive

This commit is contained in:
Daan Hoogland 2015-08-12 01:04:06 +02:00
parent fa56b3f37e
commit a3ae8e0645

View File

@ -230,30 +230,26 @@ public class DbUtil {
} }
public static boolean releaseGlobalLock(String name) { public static boolean releaseGlobalLock(String name) {
Connection conn = getConnectionForGlobalLocks(name, false); try (Connection conn = getConnectionForGlobalLocks(name, false);) {
if (conn == null) { if (conn == null) {
s_logger.error("Unable to acquire DB connection for global lock system"); s_logger.error("Unable to acquire DB connection for global lock system");
assert (false); assert (false);
return false; return false;
} }
PreparedStatement pstmt = null; try (PreparedStatement pstmt = conn.prepareStatement("SELECT COALESCE(RELEASE_LOCK(?), 0)");) {
ResultSet rs = null; pstmt.setString(1, name);
try { try (ResultSet rs = pstmt.executeQuery();) {
pstmt = conn.prepareStatement("SELECT COALESCE(RELEASE_LOCK(?), 0)"); if (rs != null && rs.first()) {
pstmt.setString(1, name); return rs.getInt(1) > 0;
rs = pstmt.executeQuery(); }
if (rs != null && rs.first()) s_logger.error("releaseGlobalLock:RELEASE_LOCK() returns unexpected result");
return rs.getInt(1) > 0; }
s_logger.error("releaseGlobalLock:RELEASE_LOCK() returns unexpected result"); }
} catch (SQLException e) { } catch (SQLException e) {
s_logger.error("RELEASE_LOCK() throws exception ", e); s_logger.error("RELEASE_LOCK() throws exception ", e);
} catch (Throwable e) { } catch (Throwable e) {
s_logger.error("RELEASE_LOCK() throws exception ", e); s_logger.error("RELEASE_LOCK() throws exception ", e);
} finally {
closeResultSet(rs);
closeStatement(pstmt);
closeConnection(conn);
} }
return false; return false;
} }