Closed psmf22 closed 1 year ago
Potentially we can implement and use a custom OperatorOverloader to handle this situation, overloading the matches
operator to return false
if any of the operands is null
.
We'd need to configure this custom operator overloader on the SpEL evaluation context created in the JsonHelper::createSpelEvaluationContext
method. However, we currently use a SimpleEvaluationContext
, which doesn't support custom operator overloaders. So, in order to be able to use a custom overloader, we should either:
SimpleEvaluationContext
that supports custom operator overloadersSimpleEvaluationContextDecorator
that delegates all method calls to a standard SimpleEvaluationContext
instance, except for returning our custom operator overloader in the getOperatorOverloader()
methodStandardEvaluationContext
and configure it to behave in the same way as SimpleEvaluationContext
The OperatorOverloader does not apply to "matches" operations, there is no easy way to fix this. As a workaround guard your expressions with a null check:
If you want to include results with null values: stringValue == null || stringValue matches 'value1|value2'
To exclude results with null values: stringValue != null && stringValue matches 'value1|value2'
As described in the previous comment, there's no easy/proper fix to handle this natively in fcli; users will need to explicitly handle null-values in their expressions if they wish to use the matches
operator. Issue #382 has been opened to properly document this, and as such this issue will be closed.
The "matches" operator throws an IllegalStateException when being applied to a field with null value.
To reproduce execute fcli util sample-data list -q "stringValue matches 'value1|value2'
Stacktrace: