Author: jleroux
Date: Tue Jun 6 14:32:25 2017
New Revision: 1797790
URL:
http://svn.apache.org/viewvc?rev=1797790&view=revLog:
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/content/src/main/java/org/apache/ofbiz/content/survey/SurveyWrapper.java
Modified: ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/survey/SurveyWrapper.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/survey/SurveyWrapper.java?rev=1797790&r1=1797789&r2=1797790&view=diff==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/survey/SurveyWrapper.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/content/src/main/java/org/apache/ofbiz/content/survey/SurveyWrapper.java Tue Jun 6 14:32:25 2017
@@ -534,22 +534,19 @@ public class SurveyWrapper {
// index 1 = total yes
// index 2 = total no
- EntityListIterator eli = this.getEli(question, -1);
-
- if (eli != null) {
- GenericValue value;
- while (((value = eli.next()) != null)) {
- if ("Y".equalsIgnoreCase(value.getString("booleanResponse"))) {
- result[1]++;
- } else {
- result[2]++;
+ try (EntityListIterator eli = this.getEli(question, -1)) {
+ if (eli != null) {
+ GenericValue value;
+ while (((value = eli.next()) != null)) {
+ if ("Y".equalsIgnoreCase(value.getString("booleanResponse"))) {
+ result[1]++;
+ } else {
+ result[2]++;
+ }
+ result[0]++; // increment the count
}
- result[0]++; // increment the count
}
-
- eli.close();
}
-
return result;
} catch (GenericEntityException e) {
try {
@@ -577,11 +574,9 @@ public class SurveyWrapper {
// index 2 = average
boolean beganTransaction = false;
- try {
+ try (EntityListIterator eli = this.getEli(question, -1)) {
beganTransaction = TransactionUtil.begin();
- EntityListIterator eli = this.getEli(question, -1);
-
if (eli != null) {
GenericValue value;
while (((value = eli.next()) != null)) {
@@ -607,8 +602,6 @@ public class SurveyWrapper {
}
result[0]++; // increment the count
}
-
- eli.close();
}
} catch (GenericEntityException e) {
try {