svn commit: r1797791 - /ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderListState.java

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

svn commit: r1797791 - /ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderListState.java

jleroux@apache.org
Author: jleroux
Date: Tue Jun  6 14:35:33 2017
New Revision: 1797791

URL: http://svn.apache.org/viewvc?rev=1797791&view=rev
Log:
Improved: EntityListIterator closed but not in case of exception
(OFBIZ-9385)

This is an improvement only because no cases were reported. But obviously in
case of unlucky exception after the EntityListIterator creation and before it's
closed the EntityListIterator remains in memory.
It should be closed in EntityListIterator.finalize() but the less happens there
the better.

The solution is to use try-with-ressources

Modified:
    ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderListState.java

Modified: ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderListState.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderListState.java?rev=1797791&r1=1797790&r2=1797791&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderListState.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderListState.java Tue Jun  6 14:35:33 2017
@@ -257,18 +257,18 @@ public class OrderListState implements S
             allConditions.add(typeConditionsList);
         }
 
-        EntityListIterator iterator = EntityQuery.use(delegator).from("OrderHeader")
+        EntityQuery eq = EntityQuery.use(delegator).from("OrderHeader")
                 .where(allConditions)
                 .orderBy("orderDate DESC")
                 .maxRows(viewSize * (viewIndex + 1))
-                .cursorScrollInsensitive()
-                .queryIterator();
-
-        // get subset corresponding to pagination state
-        List<GenericValue> orders = iterator.getPartialList(viewSize * viewIndex, viewSize);
-        orderListSize = iterator.getResultsSizeAfterPartialList();
-        iterator.close();
-        return orders;
+                .cursorScrollInsensitive();
+        
+        try (EntityListIterator iterator = eq.queryIterator()) {
+            // get subset corresponding to pagination state
+            List<GenericValue> orders = iterator.getPartialList(viewSize * viewIndex, viewSize);
+            orderListSize = iterator.getResultsSizeAfterPartialList();
+            return orders;
+        }
     }
 
     @Override