SpEL Parser returning false when it's supposed to return true

91 Views Asked by At

I am running below piece of code live and for very few traffic[.025%] ~(500 out of 2 million). The SpEL Parser is behaving wierd and returning response as false where it should return true.

Context Class file

@Getter
@Builder
@ToString
public class EvaluationContext {
    private String requestKey;
    private String namespace;
    private ContextAmount totalAmount;
    private double threshold;
    private String processingModel;
    private String channel;
}

Rule file

@Getter
@Setter
@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
@JsonIgnoreProperties(ignoreUnknown = true)
public class PolicyEvaluationRule {
    private String namespace;
    private String ruleName = "test1";
    private String expression = "'SAMPLE'.equals(Context?.ProcessingModel)";
    private EvaluationContext context;
}

Evaluating SPEL rule as below

ExpressionParser parser = new SpelExpressionParser();
        StandardEvaluationContext context = new StandardEvaluationContext(rule);
        Boolean result = parser.parseExpression(rule.getExpression()).getValue(context, Boolean.class);

For, all these failed instances assigned value in processingModel was 'SAMPLE'. And parseExpression here never ran into exception or returned result as null. So, it becomes really difficult to identify how to separate out these cases from main flow.

I added logs to identify that the result from the parser was false and there was no exception from the parser. If parser is having some error I believe it should throw exception or minimum the result should have been null

0

There are 0 best solutions below