SpEL cannot handle 'é'?

冷暖自知 提交于 2021-02-10 07:35:12

问题


I'm a french so I put some é è ê ô û in my code. (and I don't speek english very well).

I've a method like that in a class Formulaires:

  public static Formulaire exposé()

And in a config spring xml file, I try :

<entry 
key="intro" 
value="#{T(com.myproject.Formulaires).exposé()}"/>

But Spring says :

Caused by: java.lang.IllegalStateException: Cannot handle (233) 'é'
    at org.springframework.expression.spel.standard.Tokenizer.process(Tokenizer.java:193)
    at org.springframework.expression.spel.standard.Tokenizer.<init>(Tokenizer.java:47)
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:110)
    at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:56)
    at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:1)
    at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpressions(TemplateAwareExpressionParser.java:128)
    at org.springframework.expression.common.TemplateAwareExpressionParser.parseTemplate(TemplateAwareExpressionParser.java:74)
    at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:64)
    at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:119)
    ... 47 more

If I put e and not é all is good.

Is there some SpEL limit about accents ?

I use spring 3.0.5.

Thanks.


回答1:


Accented characters do not exist in a basic UTF-8 character encoding and the Spring XML files probably use that. As the error says, the parser can't handle accented characters.

There's nothing that you can do to easily solve this problem. Accented characters will give problems in other areas of programming too. I think it would be best to prevent using them.




回答2:


Here's more to it . The code below in Tokenizer decides if it's an alphabetic character

private boolean isAlphabetic(char ch) {
    if (ch>255) {
        return false;
    }
    return (flags[ch] & IS_ALPHA)!=0;
}

Your character é is <=255 but the flags[ch] is initialized by the static block below

static {
    for (int ch='0';ch<='9';ch++) {
        flags[ch]|=IS_DIGIT | IS_HEXDIGIT;
    }
    for (int ch='A';ch<='F';ch++) {
        flags[ch]|= IS_HEXDIGIT;
    }
    for (int ch='a';ch<='f';ch++) {
        flags[ch]|= IS_HEXDIGIT;
    }
    for (int ch='A';ch<='Z';ch++) {
        flags[ch]|= IS_ALPHA;
    }
    for (int ch='a';ch<='z';ch++) {
        flags[ch]|= IS_ALPHA;
    }

Hence only a-z or A-Z can be considered ..



来源:https://stackoverflow.com/questions/8571992/spel-cannot-handle-%c3%a9

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!