You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2021/12/29 08:04:57 UTC

[ofbiz-framework] branch release18.12 updated (5b6e427 -> c408896)

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

jleroux pushed a change to branch release18.12
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git.


    from 5b6e427  Fixed: [SECURITY] CVE-2021-44832: Apache Log4j2 (OFBIZ-12475)
     new 9853d10  Improved: suppresses 2 warnings related to deprecated CSVFormat.DEFAULT.withHeader()
     new c408896  Improved: suppresses 2 warnings related to deprecated CSVFormat.DEFAULT.withHeader()

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../ofbiz/accounting/invoice/InvoiceServices.java  | 22 +++++++++++++++++-----
 .../apache/ofbiz/party/party/PartyServices.java    |  6 ++++--
 2 files changed, 21 insertions(+), 7 deletions(-)

[ofbiz-framework] 01/02: Improved: suppresses 2 warnings related to deprecated CSVFormat.DEFAULT.withHeader()

Posted by jl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9853d10bd92dd9e4bd41dd466ef58f9a6dfecdd3
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Sun Dec 26 18:22:48 2021 +0100

    Improved: suppresses 2 warnings related to deprecated CSVFormat.DEFAULT.withHeader()
    
    Also adds a try-with-ressource in InvoiceServices::importInvoice to properly
    close csvReader on returns. Hence removes an useless csvReader.close().
    
    Several comments about Eclipse giving wrong advice
    <<Resource leak: '<unassigned Closeable value>' is not closed at this location>>
    It's OK, we are inside try-with-ressources.
    
    Finally removes a redundant final in PartyServices::importParty
    
    Conflicts in InvoiceServices.java handled by hand
---
 .../ofbiz/accounting/invoice/InvoiceServices.java    | 20 +++++++++++++++-----
 .../org/apache/ofbiz/party/party/PartyServices.java  |  4 ++--
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/invoice/InvoiceServices.java b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/invoice/InvoiceServices.java
index 4abfdaa..3b1da0c 100644
--- a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/invoice/InvoiceServices.java
+++ b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/invoice/InvoiceServices.java
@@ -3552,8 +3552,7 @@ public class InvoiceServices {
         String organizationPartyId = (String) context.get("organizationPartyId");
         String encoding = System.getProperty("file.encoding");
         String csvString = Charset.forName(encoding).decode(fileBytes).toString();
-        final BufferedReader csvReader = new BufferedReader(new StringReader(csvString));
-        CSVFormat fmt = CSVFormat.DEFAULT.withHeader();
+        CSVFormat fmt = CSVFormat.DEFAULT;
         List<String> errMsgs = new LinkedList<>();
         List<String> newErrMsgs;
         String lastInvoiceId = null;
@@ -3561,7 +3560,7 @@ public class InvoiceServices {
         String newInvoiceId = null;
         int invoicesCreated = 0;
 
-        try {
+        try (BufferedReader csvReader = new BufferedReader(new StringReader(csvString))) {
             for (final CSVRecord rec : fmt.parse(csvReader)) {
                 currentInvoiceId =  rec.get("invoiceId");
                 if (lastInvoiceId == null || !currentInvoiceId.equals(lastInvoiceId)) {
@@ -3626,11 +3625,18 @@ public class InvoiceServices {
                         try {
                             invoiceResult = dispatcher.runSync("createInvoice", invoice);
                             if (ServiceUtil.isError(invoiceResult)) {
+                                // Eclipse reports here: Resource leak: '<unassigned Closeable value>' is not closed at this location
+                                // but it's OK. As csvReader is in a try-with-ressource it will be closed anyway
+                                // I prefer to not put @SuppressWarnings("resource") to the whole method
+                                // BTW to be consistent Eclipse should also reports the same issue in PartyService (see there)
                                return ServiceUtil.returnError(ServiceUtil.getErrorMessage(invoiceResult));
                             }
                         } catch (GenericServiceException e) {
-                            csvReader.close();
-                            Debug.logError(e, module);
+                            Debug.logError(e, MODULE);
+                            // Eclipse reports here: Resource leak: '<unassigned Closeable value>' is not closed at this location
+                            // but it's OK. As csvReader is in a try-with-ressource it will be closed anyway
+                            // I prefer to not put @SuppressWarnings("resource") to the whole method
+                            // BTW to be consistent Eclipse should also reports the same issue in PartyService (see there)
                             return ServiceUtil.returnError(e.getMessage());
                         }
                         newInvoiceId = (String) invoiceResult.get("invoiceId");
@@ -3685,6 +3691,10 @@ public class InvoiceServices {
                         try {
                             Map<String, Object> result = dispatcher.runSync("createInvoiceItem", invoiceItem);
                             if (ServiceUtil.isError(result)) {
+                                // Eclipse reports here: Resource leak: '<unassigned Closeable value>' is not closed at this location
+                                // but it's OK. As csvReader is in a try-with-ressource it will be closed anyway
+                                // I prefer to not put @SuppressWarnings("resource") to the whole method
+                                // BTW to be consistent Eclipse should also reports the same issue in PartyService (see there)
                                return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result));
                             }
                         } catch (GenericServiceException e) {
diff --git a/applications/party/src/main/java/org/apache/ofbiz/party/party/PartyServices.java b/applications/party/src/main/java/org/apache/ofbiz/party/party/PartyServices.java
index 570021f..7bd0079 100644
--- a/applications/party/src/main/java/org/apache/ofbiz/party/party/PartyServices.java
+++ b/applications/party/src/main/java/org/apache/ofbiz/party/party/PartyServices.java
@@ -2326,7 +2326,7 @@ public class PartyServices {
         ByteBuffer fileBytes = (ByteBuffer) context.get("uploadedFile");
         String encoding = System.getProperty("file.encoding");
         String csvString = Charset.forName(encoding).decode(fileBytes).toString();
-        CSVFormat fmt = CSVFormat.DEFAULT.withHeader();
+        CSVFormat fmt = CSVFormat.DEFAULT;
         List<String> errMsgs = new LinkedList<>();
         List<String> newErrMsgs = new LinkedList<>();
         String lastPartyId = null;        // last partyId read from the csv file
@@ -2356,7 +2356,7 @@ public class PartyServices {
 
 
         try (BufferedReader csvReader = new BufferedReader(new StringReader(csvString))) {
-            for (final CSVRecord rec : fmt.parse(csvReader)) {
+            for (CSVRecord rec : fmt.parse(csvReader)) {
                 if (UtilValidate.isNotEmpty(rec.get("partyId"))) {
                     currentPartyId = rec.get("partyId");
                 }

[ofbiz-framework] 02/02: Improved: suppresses 2 warnings related to deprecated CSVFormat.DEFAULT.withHeader()

Posted by jl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit c4088961d32fde4e07b0329b349f9a6006f67f08
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Sun Dec 26 19:20:43 2021 +0100

    Improved: suppresses 2 warnings related to deprecated CSVFormat.DEFAULT.withHeader()
    
    This was not done correctly last time (previous commit e4d4329)
---
 .../java/org/apache/ofbiz/accounting/invoice/InvoiceServices.java     | 4 +++-
 .../src/main/java/org/apache/ofbiz/party/party/PartyServices.java     | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/invoice/InvoiceServices.java b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/invoice/InvoiceServices.java
index 3b1da0c..4cdf7d1 100644
--- a/applications/accounting/src/main/java/org/apache/ofbiz/accounting/invoice/InvoiceServices.java
+++ b/applications/accounting/src/main/java/org/apache/ofbiz/accounting/invoice/InvoiceServices.java
@@ -37,6 +37,7 @@ import java.util.Map.Entry;
 
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVFormat.Builder;
 import org.apache.commons.csv.CSVRecord;
 import org.apache.ofbiz.accounting.payment.PaymentGatewayServices;
 import org.apache.ofbiz.accounting.payment.PaymentWorker;
@@ -3552,7 +3553,8 @@ public class InvoiceServices {
         String organizationPartyId = (String) context.get("organizationPartyId");
         String encoding = System.getProperty("file.encoding");
         String csvString = Charset.forName(encoding).decode(fileBytes).toString();
-        CSVFormat fmt = CSVFormat.DEFAULT;
+        Builder csvFormatBuilder = Builder.create().setHeader();
+        CSVFormat fmt = csvFormatBuilder.build();
         List<String> errMsgs = new LinkedList<>();
         List<String> newErrMsgs;
         String lastInvoiceId = null;
diff --git a/applications/party/src/main/java/org/apache/ofbiz/party/party/PartyServices.java b/applications/party/src/main/java/org/apache/ofbiz/party/party/PartyServices.java
index 7bd0079..3022f47 100644
--- a/applications/party/src/main/java/org/apache/ofbiz/party/party/PartyServices.java
+++ b/applications/party/src/main/java/org/apache/ofbiz/party/party/PartyServices.java
@@ -34,6 +34,7 @@ import java.util.Locale;
 import java.util.Map;
 
 import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVFormat.Builder;
 import org.apache.commons.csv.CSVRecord;
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.UtilDateTime;
@@ -2326,7 +2327,8 @@ public class PartyServices {
         ByteBuffer fileBytes = (ByteBuffer) context.get("uploadedFile");
         String encoding = System.getProperty("file.encoding");
         String csvString = Charset.forName(encoding).decode(fileBytes).toString();
-        CSVFormat fmt = CSVFormat.DEFAULT;
+        Builder csvFormatBuilder = Builder.create().setHeader();
+        CSVFormat fmt = csvFormatBuilder.build();
         List<String> errMsgs = new LinkedList<>();
         List<String> newErrMsgs = new LinkedList<>();
         String lastPartyId = null;        // last partyId read from the csv file