cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [1/3] git commit: updated refs/heads/master to ff66175
Date Thu, 13 Aug 2015 14:26:01 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master aa7f8e57c -> ff66175f5


coverity 1315774: improvement of code to negate false positive

Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a3ae8e06
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a3ae8e06
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a3ae8e06

Branch: refs/heads/master
Commit: a3ae8e064556cbb1786092da2f2921f30c694aaa
Parents: fa56b3f
Author: Daan Hoogland <daan@onecht.net>
Authored: Wed Aug 12 01:04:06 2015 +0200
Committer: Daan Hoogland <daan@onecht.net>
Committed: Wed Aug 12 01:04:06 2015 +0200

----------------------------------------------------------------------
 framework/db/src/com/cloud/utils/db/DbUtil.java | 34 +++++++++-----------
 1 file changed, 15 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a3ae8e06/framework/db/src/com/cloud/utils/db/DbUtil.java
----------------------------------------------------------------------
diff --git a/framework/db/src/com/cloud/utils/db/DbUtil.java b/framework/db/src/com/cloud/utils/db/DbUtil.java
index d868905..9a21ca4 100644
--- a/framework/db/src/com/cloud/utils/db/DbUtil.java
+++ b/framework/db/src/com/cloud/utils/db/DbUtil.java
@@ -230,30 +230,26 @@ public class DbUtil {
     }
 
     public static boolean releaseGlobalLock(String name) {
-        Connection conn = getConnectionForGlobalLocks(name, false);
-        if (conn == null) {
-            s_logger.error("Unable to acquire DB connection for global lock system");
-            assert (false);
-            return false;
-        }
+        try (Connection conn = getConnectionForGlobalLocks(name, false);) {
+            if (conn == null) {
+                s_logger.error("Unable to acquire DB connection for global lock system");
+                assert (false);
+                return false;
+            }
 
-        PreparedStatement pstmt = null;
-        ResultSet rs = null;
-        try {
-            pstmt = conn.prepareStatement("SELECT COALESCE(RELEASE_LOCK(?), 0)");
-            pstmt.setString(1, name);
-            rs = pstmt.executeQuery();
-            if (rs != null && rs.first())
-                return rs.getInt(1) > 0;
-            s_logger.error("releaseGlobalLock:RELEASE_LOCK() returns unexpected result");
+            try (PreparedStatement pstmt = conn.prepareStatement("SELECT COALESCE(RELEASE_LOCK(?),
0)");) {
+                pstmt.setString(1, name);
+                try (ResultSet rs = pstmt.executeQuery();) {
+                    if (rs != null && rs.first()) {
+                        return rs.getInt(1) > 0;
+                    }
+                    s_logger.error("releaseGlobalLock:RELEASE_LOCK() returns unexpected result");
+                }
+            }
         } catch (SQLException e) {
             s_logger.error("RELEASE_LOCK() throws exception ", e);
         } catch (Throwable e) {
             s_logger.error("RELEASE_LOCK() throws exception ", e);
-        } finally {
-            closeResultSet(rs);
-            closeStatement(pstmt);
-            closeConnection(conn);
         }
         return false;
     }


Mime
View raw message