How do you get around PropertyAccessExceptions when the top level key in the hash map may or may not exist?
In the example below, if the property exists, it works just fine, but if the property does not exist in the variable map, it throws a PropertyAccessExceptions. I am aware that I can use the ? for null safe navigation, but this does not work when the property exists on the top level.
Any suggestions?
HashMap<String, Object> variables = new HashMap<>();
variables.put("aProperty", "aValue");
Boolean result = MVEL.evalToBoolean("'aValue' == aProperty", variables);
assertThat(result).isTrue(); //This works
result = MVEL.evalToBoolean("'aValue' == aNonExistentProperty", variables);
assertThat(result).isFalse(); //This throws a PropertyAccessException, since aNonExistentProperty is not defined
I would like a workaround to avoid PropertyAccessExceptions.