Original title: Does SpEL support Chinese variables?
I try to use SpEL to execute some code which includes some Chinese variables.
void test() {
SimpleEvaluationContext evaluationContext = SimpleEvaluationContext
.forReadWriteDataBinding()
.withMethodResolvers(DataBindingMethodResolver.forInstanceMethodInvocation())
.build();
evaluationContext.setVariable("中文", 1);
ExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("#中文 == 1");
Boolean value = expression.getValue(evaluationContext, Boolean.class);
System.out.println(value);
}
Exception stack trace:
java.lang.IllegalStateException: Cannot handle (20013) '中'
at org.springframework.expression.spel.standard.Tokenizer.process(Tokenizer.java:268)
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:127)
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:61)
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:33)
at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:52)
at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:43)
Comment From: sbrannen
For identifiers such as variables, SpEL does not support characters whose integer value is greater than 255.
https://github.com/spring-projects/spring-framework/blob/6c2cb8ecf5d1d755f09aff80489aa8b6e49d70b1/spring-expression/src/main/java/org/springframework/expression/spel/standard/Tokenizer.java#L569-L574
However, the documentation in the reference manual does not explicitly state this fact.
Thus, we can improve the documentation here to be explicit.