Finally fixed in antoher way at r883682

Jacques

From: "Jacques Le Roux" <[email protected]>
Actually it seems that most (if not all) warnings are generated  by this line
if (UtilValidate.isEmpty(curField)) {
at EntityExpr.java[274]

I will put a special check to avoid it...

Jacques

From: "Jacques Le Roux" <[email protected]>
I see your point now (that's why I asked was not sure what you meaned). But we need to differentiate known from unknown, so I propose rather

Index: framework/base/src/org/ofbiz/base/util/ObjectType.java
===================================================================
--- framework/base/src/org/ofbiz/base/util/ObjectType.java (revision 883647)
+++ framework/base/src/org/ofbiz/base/util/ObjectType.java (working copy)
@@ -754,25 +754,36 @@
    }

    public static boolean isEmpty(Object value) {
-        if (value == null) return true;
+        if (value == null) {
+            return true;
+        }

        if (value instanceof String) {
            if (((String) value).length() == 0) {
                return true;
+            } else {
+         return false;
            }
        } else if (value instanceof Collection) {
            if (((Collection<?>) value).size() == 0) {
                return true;
+            } else {
+         return false;
            }
        } else if (value instanceof Map) {
            if (((Map<?,?>) value).size() == 0) {
                return true;
+            } else {
+         return false;
            }
        } else if (value instanceof CharSequence) {
            if (((CharSequence) value).length() == 0) {
                return true;
+            } else {
+         return false;
            }
        }
+        Debug.logWarning("In ObjectType.isEmpty(Object) returning false for unknown 
not-null Object.", module);
        return false;
    }

Jacques

----- Original Message ----- From: "Scott Gray" <[email protected]>
To: <[email protected]>
Sent: Tuesday, November 24, 2009 11:44 AM
Subject: Re: svn commit: r883613 - 
/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java


Wrong spot, it needs to go just before the end of the method:
Debug.logWarning("In ObjectType.isEmpty(Object) returning false for  unknown 
not-null Object.");
return false;

Regards
Scott

On 24/11/2009, at 11:33 PM, Jacques Le Roux wrote:

Hi Scott,

What do you think about adding this check at the beginning of  
ObjectType.isEmpty()  something like

Index: framework/base/src/org/ofbiz/base/util/ObjectType.java
===================================================================
--- framework/base/src/org/ofbiz/base/util/ObjectType.java (revision  883647)
+++ framework/base/src/org/ofbiz/base/util/ObjectType.java (working  copy)
@@ -754,7 +754,10 @@
   }

   public static boolean isEmpty(Object value) {
-        if (value == null) return true;
+        if (value == null) {
+            Debug.logWarning("a warning", module);
+            return true;
+        }

Jacques


From: "Scott Gray" <[email protected]>
Thanks Jacques, it wasn't a compilation problem but a run-install problem, empty fields were being treated as empty strings instead of null which was causing all sorts of fk problems during data load.

If you do work on UtilValidate it might be a good idea to log a warning whenever an object is passed in that we can only do a null check on, it might help people avoid this sort of issue and help us identify any areas where the checks aren't doing what we probably intended them to do.

Regards
Scott

On 24/11/2009, at 9:49 PM, Jacques Le Roux wrote:

Thanks Scott,

I did not notice build issues. I will double check possible   CharSequence uses 
or rather coonsider implementing
UtilValidate.is(Not)Empty for it (I can't see any reason to not  do  it at this 
stage)

Jacques

From: <[email protected]>
Author: lektran
Date: Tue Nov 24 07:43:18 2009
New Revision: 883613

URL: http://svn.apache.org/viewvc?rev=883613&view=rev
Log:
Revert Jacques changes to EntitySaxReader.java from r883549 and 883507, the UtilValidate.is(Not)Empty methods are not setup to
test CharSequence instances.  Hopefully there aren't too many  more  out there.

Modified:
 ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/  EntitySaxReader.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/  
EntitySaxReader.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/EntitySaxReader.java?rev=883613&r1=883612&r2=883613&view=diff
= = = = = = = = =  = = 
===================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/  
EntitySaxReader.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/util/  
EntitySaxReader.java Tue Nov 24 07:43:18 2009
@@ -375,7 +375,7 @@

      if (currentValue != null) {
          if (currentFieldName != null) {
-                if (UtilValidate.isNotEmpty(currentFieldValue)) {
+                if (currentFieldValue != null &&   currentFieldValue.length() 
> 0) {
                  if   (currentValue 
.getModelEntity().isField(currentFieldName.toString())) {
                      ModelEntity modelEntity =   currentValue.getModelEntity();
                      ModelField modelField =   
modelEntity.getField(currentFieldName.toString());
@@ -499,7 +499,7 @@
              CharSequence name = attributes.getLocalName(i);
              CharSequence value = attributes.getValue(i);

-                if (UtilValidate.isEmpty(name)) {
+                if (name == null || name.length() == 0) {
                  name = attributes.getQName(i);
              }
              newElement.setAttribute(name.toString(),   value.toString());
@@ -548,12 +548,12 @@
                  CharSequence name = attributes.getLocalName(i);
                  CharSequence value = attributes.getValue(i);

-                    if (UtilValidate.isEmpty(name)) {
+                    if (name == null || name.length() == 0) {
                      name = attributes.getQName(i);
                  }
                  try {
                      // treat empty strings as nulls
-                        if (UtilValidate.isNotEmpty(value)) {
+                        if (value != null && value.length() > 0) {
                          if   
(currentValue.getModelEntity().isField(name.toString())) {
                                currentValue.setString(name.toString(), 
value.toString());
                          } else {















Reply via email to