diff --git a/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java b/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java index 8370d2dcc6..a0e7065c1b 100644 --- a/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java +++ b/framework/common/src/main/java/org/apache/ofbiz/common/FindServices.java @@ -438,11 +438,9 @@ public class FindServices { int start = viewIndex.intValue() * viewSize.intValue(); List list = null; Integer listSize = 0; - try { - EntityListIterator it = (EntityListIterator) result.get("listIt"); + try (EntityListIterator it = (EntityListIterator) result.get("listIt")) { list = it.getPartialList(start+1, viewSize); // list starts at '1' listSize = it.getResultsSizeAfterPartialList(); - it.close(); } catch (Exception e) { Debug.logInfo("Problem getting partial list" + e,module); } @@ -752,13 +750,11 @@ public class FindServices { List list = null; GenericValue item= null; - try { - EntityListIterator it = (EntityListIterator) result.get("listIt"); + try (EntityListIterator it = (EntityListIterator) result.get("listIt")) { list = it.getPartialList(1, 1); // list starts at '1' if (UtilValidate.isNotEmpty(list)) { item = list.get(0); } - it.close(); } catch (Exception e) { Debug.logInfo("Problem getting list Item" + e,module); } diff --git a/framework/common/src/main/java/org/apache/ofbiz/common/login/LoginServices.java b/framework/common/src/main/java/org/apache/ofbiz/common/login/LoginServices.java index af082d39f1..c8757f1102 100644 --- a/framework/common/src/main/java/org/apache/ofbiz/common/login/LoginServices.java +++ b/framework/common/src/main/java/org/apache/ofbiz/common/login/LoginServices.java @@ -150,7 +150,7 @@ public class LoginServices { // check the user login object again try { - userLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", username).cache(isServiceAuth).queryOne(); + userLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", username).cache(isServiceAuth).queryOne(); } catch (GenericEntityException e) { Debug.logWarning(e, "", module); } @@ -434,29 +434,29 @@ public class LoginServices { // Not saving password history, so return from here. return; } - - EntityListIterator eli = EntityQuery.use(delegator) - .from("UserLoginPasswordHistory") - .where("userLoginId", userLoginId) - .orderBy("-fromDate") - .cursorScrollInsensitive() - .queryIterator(); + EntityQuery eq = EntityQuery.use(delegator) + .from("UserLoginPasswordHistory") + .where("userLoginId", userLoginId) + .orderBy("-fromDate") + .cursorScrollInsensitive(); Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); - GenericValue pwdHist; - if ((pwdHist = eli.next()) != null) { - // updating password so set end date on previous password in history - pwdHist.set("thruDate", nowTimestamp); - pwdHist.store(); - // check if we have hit the limit on number of password changes to be saved. If we did then delete the oldest password from history. - eli.last(); - int rowIndex = eli.currentIndex(); - if (rowIndex==passwordChangeHistoryLimit) { - eli.afterLast(); - pwdHist = eli.previous(); - pwdHist.remove(); + + try (EntityListIterator eli = eq.queryIterator()) { + GenericValue pwdHist; + if ((pwdHist = eli.next()) != null) { + // updating password so set end date on previous password in history + pwdHist.set("thruDate", nowTimestamp); + pwdHist.store(); + // check if we have hit the limit on number of password changes to be saved. If we did then delete the oldest password from history. + eli.last(); + int rowIndex = eli.currentIndex(); + if (rowIndex==passwordChangeHistoryLimit) { + eli.afterLast(); + pwdHist = eli.previous(); + pwdHist.remove(); + } } } - eli.close(); // save this password in history GenericValue userLoginPwdHistToCreate = delegator.makeValue("UserLoginPasswordHistory", UtilMisc.toMap("userLoginId", userLoginId,"fromDate", nowTimestamp)); @@ -904,7 +904,7 @@ public class LoginServices { public static void checkNewPassword(GenericValue userLogin, String currentPassword, String newPassword, String newPasswordVerify, String passwordHint, List errorMessageList, boolean ignoreCurrentPassword, Locale locale) { Delegator delegator = userLogin.getDelegator(); - boolean useEncryption = "true".equals(EntityUtilProperties.getPropertyValue("security", "password.encrypt", delegator)); + boolean useEncryption = "true".equals(EntityUtilProperties.getPropertyValue("security", "password.encrypt", delegator)); String errMsg = null;