Skip to content

Commit 04c97d7

Browse files
BroadleafCommerce/QA#1517 - MVEL evaluation should use the null safe map operator "getProductAttributes().?get('somekey').?value == 'someval'" to prevent null pointer log messages in the modifyExpressions method for ValueAssignable maps
1 parent 12d106a commit 04c97d7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

common/src/main/java/org/broadleafcommerce/common/rule/MvelHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public static boolean evaluateRule(String rule, Map<String, Object> ruleParamete
194194
* <p>
195195
* For example, given an expression like getProductAttributes()['somekey'] == 'someval', getProductAttributes()['somekey']
196196
* actually returns a ProductAttribute object, not a String, so the comparison is wrong. Instead, we actually want
197-
* to do this: getProductAttributes()['somekey'].?value == 'someval'. This function performs that replacement
197+
* to do this: getProductAttributes().?get('somekey').?value == 'someval'. This function performs that replacement
198198
*
199199
* @param rule the rule to replace
200200
* @return a modified version of <b>rule</b>
@@ -203,7 +203,7 @@ public static boolean evaluateRule(String rule, Map<String, Object> ruleParamete
203203
protected static String modifyExpression(String rule, Map<String, Object> ruleParameters, ParserContext context) {
204204
String modifiedExpression = rule;
205205
for (String attributeMap : getRuleAttributeMaps()) {
206-
modifiedExpression = modifiedExpression.replaceAll(attributeMap + "\\(\\)\\[(.*)\\](?!\\.\\?value)", attributeMap + "()[$1].?value");
206+
modifiedExpression = modifiedExpression.replaceAll(attributeMap + "\\(\\)\\[(.*)\\](?!\\.\\?value)", attributeMap + "().?get($1).?value");
207207
}
208208
return modifiedExpression;
209209
}

0 commit comments

Comments
 (0)