diff --git a/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java b/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java index 41d2fa6c3a..f35258c38d 100644 --- a/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java +++ b/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java @@ -1151,21 +1151,12 @@ public class CommunicationEventServices { inputFields.put("infoString_ic", caseInsensitiveEmail); result = dispatcher.runSync("performFind", UtilMisc.toMap("entityName", "WorkEffortContactMechView" ,"inputFields", inputFields, "userLogin", userLogin)); - EntityListIterator listIt = (EntityListIterator) result.get("listIt"); - - try { + try (EntityListIterator listIt = (EntityListIterator) result.get("listIt")) { List list = listIt.getCompleteList(); List filteredList = EntityUtil.filterByDate(list); tempResults.addAll(filteredList); } catch (GenericEntityException e) { Debug.logError(e, module); - } finally { - try { - listIt.close(); - } catch (GenericEntityException e) { - Debug.logError(e, module); - } - } } } } diff --git a/framework/common/src/main/java/org/apache/ofbiz/common/test/PerformFindTests.java b/framework/common/src/main/java/org/apache/ofbiz/common/test/PerformFindTests.java index bfac86aaa0..1704ad18ce 100644 --- a/framework/common/src/main/java/org/apache/ofbiz/common/test/PerformFindTests.java +++ b/framework/common/src/main/java/org/apache/ofbiz/common/test/PerformFindTests.java @@ -42,20 +42,11 @@ public class PerformFindTests extends OFBizTestCase { } private List getCompleteList(Map context) { - EntityListIterator listIt = (EntityListIterator) context.get("listIt"); List foundElements = new LinkedList(); - if (listIt != null) { - try { + try (EntityListIterator listIt = (EntityListIterator) context.get("listIt")) { foundElements = listIt.getCompleteList(); } catch (GenericEntityException e) { Debug.logError(" Failed to extract values from EntityListIterator after a performFind service", module); - } finally { - try { - listIt.close(); - } catch (GenericEntityException e) { - Debug.logError(" Failed to close EntityListIterator after a performFind service", module); - } - } } return foundElements; }