coverity 1315775: proper getting of networkLabel

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

Branch: refs/heads/master
Commit: 1ab3b9659475e8c9f02954d9f47ac1c5a8636e25
Parents: a3ae8e0
Author: Daan Hoogland <[email protected]>
Authored: Wed Aug 12 01:10:31 2015 +0200
Committer: Daan Hoogland <[email protected]>
Committed: Wed Aug 12 01:10:31 2015 +0200

----------------------------------------------------------------------
 .../src/com/cloud/upgrade/dao/Upgrade30xBase.java    | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1ab3b965/engine/schema/src/com/cloud/upgrade/dao/Upgrade30xBase.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade30xBase.java 
b/engine/schema/src/com/cloud/upgrade/dao/Upgrade30xBase.java
index 2ca562a..47b877d 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade30xBase.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade30xBase.java
@@ -34,20 +34,15 @@ public abstract class Upgrade30xBase extends 
LegacyDbUpgrade {
     protected String getNetworkLabelFromConfig(Connection conn, String name) {
         String sql = "SELECT value FROM `cloud`.`configuration` where name = 
?";
         String networkLabel = null;
-        PreparedStatement pstmt = null;
-        ResultSet rs = null;
-        try {
-            pstmt = conn.prepareStatement(sql);
+        try (PreparedStatement pstmt = conn.prepareStatement(sql);) {
             pstmt.setString(1,name);
-            rs = pstmt.executeQuery();
-            if (rs.next()) {
-                networkLabel = rs.getString(1);
+            try (ResultSet rs = pstmt.executeQuery();) {
+                if (rs.next()) {
+                    networkLabel = rs.getString(1);
+                }
             }
         } catch (SQLException e) {
             throw new CloudRuntimeException("Unable to fetch network label 
from configuration", e);
-        } finally {
-            closeAutoCloseable(rs);
-            closeAutoCloseable(pstmt);
         }
         return networkLabel;
     }

Reply via email to