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

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

commit 36b82f2b16f5222a523b55ecbbb4b30d8aa3f701
Author: Jacques Le Roux <[email protected]>
AuthorDate: Fri Dec 3 12:37:46 2021 +0100

    Improved: Fix some bugs Spotbugs reports (OFBIZ-12386)
    
    GenericEntity::getBoolean can't return null, so false
    
    CommunicationEventServices::sendEmailToContactList handles correctly
    tmpResult != null
---
 .../communication/CommunicationEventServices.java  | 61 +++++++++++-----------
 .../org/apache/ofbiz/entity/GenericEntity.java     |  4 +-
 2 files changed, 33 insertions(+), 32 deletions(-)

diff --git 
a/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
 
b/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
index 784fd57..ec7ea48 100644
--- 
a/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
+++ 
b/applications/party/src/main/java/org/apache/ofbiz/party/communication/CommunicationEventServices.java
@@ -585,7 +585,7 @@ public class CommunicationEventServices {
                         }
 
                         if (tmpResult == null || 
ServiceUtil.isError(tmpResult)) {
-                            if 
(ServiceUtil.getErrorMessage(tmpResult).startsWith("[ADDRERR]")) {
+                            if (tmpResult != null && 
ServiceUtil.getErrorMessage(tmpResult).startsWith("[ADDRERR]")) {
                                 // address error; mark the communication event 
as BOUNCED
                                 contactListCommStatusRecord.set("statusId", 
"COM_BOUNCED");
                                 try {
@@ -608,38 +608,39 @@ public class CommunicationEventServices {
                                 continue;
                             }
                             // If the send attempt fails, just log and skip 
the email address
-                            Debug.logError(errorCallingSendMailService + ": " 
+ ServiceUtil.getErrorMessage(tmpResult),
-                                    MODULE);
-                            errorMessages.add(errorCallingSendMailService + ": 
" + ServiceUtil.getErrorMessage(
-                                    tmpResult));
-                            continue;
+                            if (tmpResult != null) {
+                                Debug.logError(errorCallingSendMailService + 
": " + ServiceUtil.getErrorMessage(tmpResult), MODULE);
+                                errorMessages.add(errorCallingSendMailService 
+ ": " + ServiceUtil.getErrorMessage(tmpResult));
+                                continue;
+                            }
                         }
                         // attach the parent communication event to the new 
event created when sending
                         // the mail
-                        String thisCommEventId = (String) 
tmpResult.get("communicationEventId");
-                        GenericValue thisCommEvent = 
EntityQuery.use(delegator).from("CommunicationEvent").where(
-                                "communicationEventId", 
thisCommEventId).queryOne();
-                        if (thisCommEvent != null) {
-                            thisCommEvent.set("contactListId", contactListId);
-                            thisCommEvent.set("parentCommEventId", 
communicationEventId);
-                            thisCommEvent.store();
-                        }
-                        String messageId = (String) tmpResult.get("messageId");
-                        contactListCommStatusRecord.set("messageId", 
messageId);
-
-                        if ("Y".equals(contactList.get("singleUse"))) {
-
-                            // Expire the ContactListParty if the list is 
single use and sendEmail finishes successfully
-                            tmpResult = 
dispatcher.runSync("updateContactListParty", UtilMisc.toMap("contactListId",
-                                    
lastContactListPartyACM.get("contactListId"),
-                                    "partyId", partyId, "fromDate", 
lastContactListPartyACM.get("fromDate"),
-                                    "thruDate", UtilDateTime.nowTimestamp(), 
"userLogin", userLogin));
-                            if (ServiceUtil.isError(tmpResult)) {
-
-                                // If the expiry fails, just log and skip the 
email address
-                                
Debug.logError(errorCallingUpdateContactListPartyService + ": " + 
ServiceUtil.getErrorMessage(tmpResult), MODULE);
-                                
errorMessages.add(errorCallingUpdateContactListPartyService + ": " + 
ServiceUtil.getErrorMessage(tmpResult));
-                                continue;
+                        if (tmpResult != null) {
+                            String thisCommEventId = (String) 
tmpResult.get("communicationEventId");
+                            GenericValue thisCommEvent = 
EntityQuery.use(delegator).from("CommunicationEvent").where(
+                                    "communicationEventId", 
thisCommEventId).queryOne();
+                            if (thisCommEvent != null) {
+                                thisCommEvent.set("contactListId", 
contactListId);
+                                thisCommEvent.set("parentCommEventId", 
communicationEventId);
+                                thisCommEvent.store();
+                            }
+                            String messageId = (String) 
tmpResult.get("messageId");
+                            contactListCommStatusRecord.set("messageId", 
messageId);
+
+                            if ("Y".equals(contactList.get("singleUse"))) {
+                                // Expire the ContactListParty if the list is 
single use and sendEmail finishes successfully
+                                tmpResult = 
dispatcher.runSync("updateContactListParty", UtilMisc.toMap("contactListId",
+                                        
lastContactListPartyACM.get("contactListId"),
+                                        "partyId", partyId, "fromDate", 
lastContactListPartyACM.get("fromDate"),
+                                        "thruDate", 
UtilDateTime.nowTimestamp(), "userLogin", userLogin));
+                                if (ServiceUtil.isError(tmpResult)) {
+
+                                    // If the expiry fails, just log and skip 
the email address
+                                    
Debug.logError(errorCallingUpdateContactListPartyService + ": " + 
ServiceUtil.getErrorMessage(tmpResult), MODULE);
+                                    
errorMessages.add(errorCallingUpdateContactListPartyService + ": " + 
ServiceUtil.getErrorMessage(tmpResult));
+                                    continue;
+                                }
                             }
                         }
 
diff --git 
a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java 
b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
index 83f08af..e2b94ed 100644
--- a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
+++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericEntity.java
@@ -736,7 +736,7 @@ public class GenericEntity implements Map<String, Object>, 
LocalizedMap<Object>,
         Object obj = get(name);
 
         if (obj == null) {
-            return null;
+            return false;
         }
         if (obj instanceof Boolean) {
             return (Boolean) obj;
@@ -969,7 +969,7 @@ public class GenericEntity implements Map<String, Object>, 
LocalizedMap<Object>,
     /**
      * call by the previous method to be able to read with View entityName and 
entity Field and after for real entity
      * @param modelEntity the modelEntity, for a view it's the ViewEntity
-     * @param modelEntityToUse, same as before except if it's a second call 
for a view, and so it's the real modelEntity
+     * @param modelEntityToUse same as before except if it's a second call for 
a view, and so it's the real modelEntity
      * @return null or resourceValue
      */
     private Object get(ModelEntity modelEntity, ModelEntity modelEntityToUse, 
String name, String resource, Locale locale) {

Reply via email to