Java keywords not allowed as EL identifiers

丶灬走出姿态 提交于 2019-12-22 04:33:23

问题


Recently I upgraded my development tomcat from 7.0.0 to 7.0.4. I had things like:

<c:set var="static" value=".." />
<c:set var="class" value=".." />

Both worked on 7.0.0 but stopped working on 7.0.4. I opened a bug, it was closed, with the answer that:

In and of itself, that tag will compile.

The checks for Java identifiers were added to the EL processing so I suspect you have some illegal EL elsewhere on the page.

This didn't sound quite clear, but I didn't get a subsequent answer, so I looked at the EL spec. For the JSP 2.1 (the latest being 2.2) I found that:

Chapter 1, page 21: An identifier is constrained to be a Java identifier - e.g., no -, no /, etc.

And that's the most that I found. I would read this line in a way that the syntax requirements applying to java identifiers apply, but not the reserved words (since neighter class nor static appear in the list of reserved words in EL). The JLS isn't referred to for the term "Java identifier" (and it is for some other cases in the 2.2 spec, which I didn't review fully)

So, is Tomcat right to reject these names; which point of the spec they are referring to, and do you think they are interpreting it correctly.


回答1:


The spec says identifiers are limited to identifiers that would be valid in Java.

Both static and class are Java keywords, and so can't possibly be valid identifiers. You couldn't, for example, write this:

public int static = 7;

And so neither static nor class will be valid identifiers here either.




回答2:


From JSP 2.2 EL specification:

1.14 Reserved Words

The following words are reserved for the language and must not be used as identifiers.

    and   eq     gt     true   instanceof
    or    ne     le     false  empty
    not   lt     ge     null   div        mod

Note that many of these words are not in the language now, but they may be in the future, so developers must avoid using these words.

I don't see static, class, etc. This change in Tomcat 7.0.4 does not make sense to me.



来源:https://stackoverflow.com/questions/4019185/java-keywords-not-allowed-as-el-identifiers

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