Skip to content

Commit 87ae150

Browse files
committed
CLOUDSTACK-8656: replace empty catch block on close by try-with-resource
1 parent f221b9a commit 87ae150

1 file changed

Lines changed: 3 additions & 19 deletions

File tree

‎framework/config/src/org/apache/cloudstack/framework/config/dao/ConfigurationDaoImpl.java‎

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -144,44 +144,28 @@ public void init() throws ConfigurationException {
144144
@Deprecated
145145
public boolean update(String name, String value) {
146146
TransactionLegacy txn = TransactionLegacy.currentTxn();
147-
PreparedStatement stmt = null;
148-
try {
149-
stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);
147+
try (PreparedStatement stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);){
150148
stmt.setString(1, value);
151149
stmt.setString(2, name);
152150
stmt.executeUpdate();
153151
return true;
154152
} catch (Exception e) {
155153
s_logger.warn("Unable to update Configuration Value", e);
156-
} finally {
157-
try {
158-
if (stmt != null)
159-
stmt.close();
160-
} catch (SQLException e) {
161-
}
162154
}
163155
return false;
164156
}
165157

166158
@Override
167159
public boolean update(String name, String category, String value) {
168160
TransactionLegacy txn = TransactionLegacy.currentTxn();
169-
PreparedStatement stmt = null;
170-
try {
171-
value = ("Hidden".equals(category) || "Secure".equals(category)) ? DBEncryptionUtil.encrypt(value) : value;
172-
stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);
161+
value = ("Hidden".equals(category) || "Secure".equals(category)) ? DBEncryptionUtil.encrypt(value) : value;
162+
try (PreparedStatement stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);) {
173163
stmt.setString(1, value);
174164
stmt.setString(2, name);
175165
stmt.executeUpdate();
176166
return true;
177167
} catch (Exception e) {
178168
s_logger.warn("Unable to update Configuration Value", e);
179-
} finally {
180-
try {
181-
if (stmt != null)
182-
stmt.close();
183-
} catch (SQLException e) {
184-
}
185169
}
186170
return false;
187171
}

0 commit comments

Comments
 (0)