No functional change, fix an ugly bug put in with r1798335 due to an
abandoned refactoring
@@ -283,7 +283,6 @@ public class CommunicationEventServices {
// Any exceptions thrown in this block will cause the service to return error
try {
-
GenericValue communicationEvent = EntityQuery.use(delegator).from("CommunicationEvent").where("communicationEventId", communicationEventId).queryOne();
GenericValue contactList = EntityQuery.use(delegator).from("ContactList").where("contactListId", contactListId).queryOne();
@@ -301,13 +300,14 @@ public class CommunicationEventServices {
EntityCondition.makeCondition("preferredContactMechId", EntityOperator.NOT_EQUAL, null),
EntityUtil.getFilterByDateExpr(), EntityUtil.getFilterByDateExpr("contactFromDate", "contactThruDate"));
- eli = EntityQuery.use(delegator).select("partyId", "preferredContactMechId", "fromDate", "infoString")
+ EntityQuery eq = EntityQuery.use(delegator).select("partyId", "preferredContactMechId", "fromDate", "infoString")
.from("ContactListPartyAndContactMech")
.where(EntityCondition.makeCondition(conditionList, EntityOperator.AND))
.cursorScrollInsensitive()
- .distinct()
- .queryIterator();
+ .distinct();
+
+ try (EntityListIterator eli = eq.queryIterator()) {
// Send an email to each contact list member
// loop through the list iterator
for (GenericValue contactListPartyAndContactMech; (contactListPartyAndContactMech = eli.next()) != null;) {
@@ -479,17 +479,12 @@ public class CommunicationEventServices {
errorMessages.add(errorInSendEmailToContactListService + ": " + nonFatalGSE.getMessage());
}
}
-
} catch (GenericEntityException fatalGEE) {
return ServiceUtil.returnError(fatalGEE.getMessage());
- } finally {
- if (eli != null) {
- try {
- eli.close();
- } catch (GenericEntityException e) {
- Debug.logError(e, module);
- }
}
+
+ } catch (GenericEntityException fatalGEE) {
+ return ServiceUtil.returnError(fatalGEE.getMessage());
}
return errorMessages.size() == 0 ? ServiceUtil.returnSuccess() : ServiceUtil.returnError(errorMessages);
