svn commit: r1863685 - /ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java

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

svn commit: r1863685 - /ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java

nmalin
Author: nmalin
Date: Wed Jul 24 06:56:44 2019
New Revision: 1863685

URL: http://svn.apache.org/viewvc?rev=1863685&view=rev
Log:
Fixed: EntityCondition(EntityOperator, fields...) raise exception with a null value
(OFBIZ-11143)

When you write an entity condition like
  rawProdcuts = from(Product).where(
    EntityCondition.makeCondition(EntityOperator.AND,
       'productTypeId', 'RAW_MATERIAL',
       'quantityUomId', null)
    ).queryList()

the function

  public static EntityFieldMap makeCondition(EntityJoinOperator joinOp, Object... keysValues)

raise a IllegalArgumentException

The problem came from EntityUtil.makeFields(V... args) (EntityUtil.java:65) who check if a value is an insteance of Comparable and Serializable but didn't take the case tat where have a null value.

Thanks to Pawan Verma for the review

Modified:
    ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java

Modified: ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java?rev=1863685&r1=1863684&r2=1863685&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java Wed Jul 24 06:56:44 2019
@@ -66,12 +66,16 @@ public final class EntityUtil {
         Map<String, V> fields = new HashMap<>();
         if (args != null) {
             for (int i = 0; i < args.length;) {
-                if (!(args[i] instanceof String)) throw new IllegalArgumentException("Key(" + i + "), with value(" + args[i] + ") is not a String.");
-                String key = (String) args[i];
+                V keyValue = args[i];
+                if (!(keyValue instanceof String)) throw new IllegalArgumentException("Key(" + i + "), with value(" + args[i] + ") is not a String.");
+                String key = (String) keyValue;
                 i++;
-                if (!(args[i] instanceof Comparable<?>)) throw new IllegalArgumentException("Value(" + i + "), with value(" + args[i] + ") does not implement Comparable.");
-                if (!(args[i] instanceof Serializable)) throw new IllegalArgumentException("Value(" + i + "), with value(" + args[i] + ") does not implement Serializable.");
-                fields.put(key, args[i]);
+                V value = args[i];
+                if (value != null) {
+                    if (! (value instanceof Comparable<?>)) throw new IllegalArgumentException("Value(" + i + "), with value(" + args[i] + ") does not implement Comparable.");
+                    if (! (value instanceof Serializable)) throw new IllegalArgumentException("Value(" + i + "), with value(" + args[i] + ") does not implement Serializable.");
+                }
+                fields.put(key, value);
                 i++;
             }
         }