svn commit: r1797079 - /ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/WorkEffortSearch.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1797079 - /ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/WorkEffortSearch.java

jleroux@apache.org
Author: jleroux
Date: Wed May 31 17:25:36 2017
New Revision: 1797079

URL: http://svn.apache.org/viewvc?rev=1797079&view=rev
Log:
Fixed: Find Projects throw "EntityListIterator Not Closed for Entity" error
(OFBIZ-7406)

Steps to regenerate issue:
1. Go to PROJECTS component
2. Click on sub-menu "Projects"
3. Click on find button
________________________________________________
#Browse the link:
https://localhost:8443/projectmgr/control/FindProject

This is similar with OFBIZ-9385 but the case is one of the convoluted.
The fix is though rather simple: use try-with-ressources and refactor around

Thanks: Vaibhav Jain for report

Modified:
    ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/WorkEffortSearch.java

Modified: ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/WorkEffortSearch.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/WorkEffortSearch.java?rev=1797079&r1=1797078&r2=1797079&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/WorkEffortSearch.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/workeffort/src/main/java/org/apache/ofbiz/workeffort/workeffort/WorkEffortSearch.java Wed May 31 17:25:36 2017
@@ -188,23 +188,18 @@ public class WorkEffortSearch {
             long startMillis = System.currentTimeMillis();
 
             // do the query
-            EntityListIterator eli = this.doQuery(delegator);
-            ArrayList<String> workEffortIds = this.makeWorkEffortIdList(eli);
-            if (eli != null) {
-                try {
-                    eli.close();
-                } catch (GenericEntityException e) {
-                    Debug.logError(e, "Error closing WorkEffortSearch EntityListIterator");
-                }
-            }
-
-            long endMillis = System.currentTimeMillis();
-            double totalSeconds = ((double)endMillis - (double)startMillis)/1000.0;
+            try (EntityListIterator eli = this.doQuery(delegator)) {
+                ArrayList<String> workEffortIds = this.makeWorkEffortIdList(eli);
+                long endMillis = System.currentTimeMillis();
+                double totalSeconds = ((double)endMillis - (double)startMillis)/1000.0;
 
-            // store info about results in the database, attached to the user's visitId, if specified
-            this.saveSearchResultInfo(Long.valueOf(workEffortIds.size()), Double.valueOf(totalSeconds));
-
-            return workEffortIds;
+                // store info about results in the database, attached to the user's visitId, if specified
+                this.saveSearchResultInfo(Long.valueOf(workEffortIds.size()), Double.valueOf(totalSeconds));
+                return workEffortIds;
+            } catch (GenericEntityException e) {
+                Debug.logError(e, module);
+                return null;
+            }
         }
 
         public void finishKeywordConstraints() {