This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch release22.01
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git

commit fa7c9704121e6198af9faf80de28540066a03651
Author: Jacques Le Roux <jacques.le.r...@les7arts.com>
AuthorDate: Mon Dec 5 11:17:04 2022 +0100

    Fixed: EntityListIterator closed but not in case of exception (OFBIZ-9385)
    
    Following discussion
    https://lists.apache.org/thread/37vo721s7d5no0k73ym4959m8wtgtl95
    reverts "This fixes a bug introduced with r1797097"
    commit d9a24d5a347e28f241e73af9c4d9ea4bb55aeb16.
    Conflicts handled by hand in ListFinder.java
    
    Also as suggested by Deepak Dixit removes explicit eli.close call from
    handleOutput(), else we will get unnecessary console warning from
    EntityListIterator.close() method:
      Debug.logWarning("This EntityListIterator for Entity [" +
      modelEntityName + "] has already been closed, not closing again.",
      module);
    
    Thanks: Deepak Dixit for spotting the issue and discussion
---
 .../main/java/org/apache/ofbiz/entity/finder/EntityFinderUtil.java  | 1 -
 .../src/main/java/org/apache/ofbiz/entity/finder/ListFinder.java    | 6 +-----
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git 
a/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/EntityFinderUtil.java
 
b/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/EntityFinderUtil.java
index 121ad09e1a..79f7727b96 100644
--- 
a/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/EntityFinderUtil.java
+++ 
b/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/EntityFinderUtil.java
@@ -394,7 +394,6 @@ public final class EntityFinderUtil {
             int size = getSize(context);
             try {
                 listAcsr.put(context, eli.getPartialList(start, size));
-                eli.close();
             } catch (GenericEntityException e) {
                 String errMsg = "Error getting partial list in limit-range 
with start=" + start + " and size=" + size + ": " + e.toString();
                 Debug.logError(e, errMsg, MODULE);
diff --git 
a/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ListFinder.java 
b/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ListFinder.java
index f869aae029..cdac10b318 100644
--- 
a/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ListFinder.java
+++ 
b/framework/entity/src/main/java/org/apache/ofbiz/entity/finder/ListFinder.java
@@ -215,15 +215,11 @@ public abstract class ListFinder extends Finder {
                     options.setMaxRows(size * (index + 1));
                 }
                 boolean beganTransaction = false;
-                try {
+                try (EntityListIterator eli = delegator.find(entityName, 
whereEntityCondition, havingEntityCondition, fieldsToSelect, orderByFields, 
options)) {
                     if (useTransaction) {
                         beganTransaction = TransactionUtil.begin();
                     }
-                    EntityListIterator eli = delegator.find(entityName, 
whereEntityCondition, havingEntityCondition, fieldsToSelect, orderByFields,
-                            options);
                     this.outputHandler.handleOutput(eli, context, listAcsr);
-                    // NOTE: the eli EntityListIterator is not closed here. It 
SHOULD be closed later after the returned list will be used (eg see
-                    // EntityAnd.getChildren() in ModelTree.java)
                 } catch (GenericEntityException e) {
                     String errMsg = "Failure in by " + label + " find 
operation, rolling back transaction";
                     Debug.logError(e, errMsg, MODULE);

Reply via email to