Skip to content
Permalink
Browse files

Fixed: EntityCondition(EntityOperator, fields...) raise exception wit…

…h 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

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1863685 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
nmalin committed Jul 24, 2019
1 parent 2185b37 commit 46414241e6f105a25296d082c43025b2732e0968
Showing with 9 additions and 5 deletions.
  1. +9 −5 framework/entity/src/main/java/org/apache/ofbiz/entity/util/EntityUtil.java
@@ -66,12 +66,16 @@ private 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++;
}
}

0 comments on commit 4641424

Please sign in to comment.
You can’t perform that action at this time.