Bug 50147 - [static] is not a valid Java identifier
Summary: [static] is not a valid Java identifier
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Jasper (show other bugs)
Version: 7.0.4
Hardware: PC Windows XP
: P2 normal with 1 vote (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
: 51108 (view as bug list)
Depends on:
Reported: 2010-10-24 03:28 UTC by bozho
Modified: 2011-05-13 04:09 UTC (History)
2 users (show)


Note You need to log in before you can comment on or make changes to this bug.
Description bozho 2010-10-24 03:28:58 UTC
I have this in a jsp:

<c:url value="/static" var="static" />

On tomcat 7.0.0 it is fine, but I tried running it on 7.0.4, and I'm getting:

[static] is not a valid Java identifier

I don't think this should be verified, because after all these are request attributes, so they do not collide with java keywords.

Same goes for "class": [class] is not a valid Java identifier

(Btw, 7.0.4 is not in the version list in bugzilla)
Comment 1 Mark Thomas 2010-10-24 07:26:04 UTC
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.
Comment 2 bozho 2010-10-24 08:05:38 UTC
(In reply to comment #1)
> 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.

Well, I removed all instance of "static" and then "class" started complaining.

I didn't understand whether this is expected behaviour (part of EL spec, for example)
Comment 3 balusc 2010-10-25 21:28:59 UTC
From JSP 2.2 EL specification:

1.14 Reserved Words

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

    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" nor "class" in the list.
Comment 4 Mark Thomas 2010-10-26 04:54:09 UTC
That part of the EL specification is mis-leading. The important part for this discussion is on page 21.

Identifier ::= Java language identifier

Java language identifier is defined by the Java Language Specification (JLS). Tomcat correctly limits valid EL identifiers based on the rules in the JLS.
Comment 5 Konstantin Kolinko 2011-04-22 11:07:39 UTC
*** Bug 51108 has been marked as a duplicate of this bug. ***
Comment 6 Richard Kennard 2011-05-13 01:55:07 UTC
Hi guys,

Can I beg a little advice? I think this is the right place to ask because others who encounter this bug may have the same question.

EL has always lacked some kind of 'instanceof' operator for determining the type of an Object. In the past, a common workaround for this has been to do...

${foo.class.name == 'com.myapp.Person'}


${foo.class.simpleName == 'Person'}

...these aren't the greatest from a type-safety point of view, but they are quite readable and work fine. Note they are equivalent of writing (in Java): new Foo().getClass()' not 'Foo.class' (ie. they are calling the getter, not trying to use the Java keyword 'class')

However now that 'class' is a reserved word in EL because of (as mentioned above)...

Identifier ::= Java language identifier

...such EL expressons fail to compile. What is the suggested alternative?


Comment 7 balusc 2011-05-13 03:33:11 UTC
Use the brace notation.


The same story applies to Session#isNew() by the way.

Comment 8 Richard Kennard 2011-05-13 04:09:23 UTC
Perfect! Thanks for that.