Bug 41106 - "deferred" expression fails if <jsp-version> less than 2.0
Summary: "deferred" expression fails if <jsp-version> less than 2.0
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Jasper (show other bugs)
Version: 6.0.0
Hardware: Other other
: P2 normal (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2006-12-04 13:57 UTC by Stan Silvert
Modified: 2006-12-05 06:27 UTC (History)
0 users

war for testing (9.70 KB, application/binary)
2006-12-04 14:00 UTC, Stan Silvert

Note You need to log in before you can comment on or make changes to this bug.
Description Stan Silvert 2006-12-04 13:57:47 UTC
Some JSF taglibs such as Ajax4JSF mark the jsp-version tag in the TLD like this:

Then if a developer says something like action="#{foo}" in an Ajax4JSF tag, he
will get this:

This causes Ajax4JSF to fail with this error:
org.apache.jasper.JasperException: /index.jsp(26,4) According to TLD or
attribute directive in tag file, attribute action does not accept any expressions

Jasper tries to check the <jsp-version> in the TLD to see if the version is 2.1
and the attribute is not allowing deferred expressions.  However, pre-2.1, "#{"
had no meaning and was always allowed.

In Validator.java, Jasper has this line:
boolean checkDeferred = !tagInfo.getTagLibrary().getRequiredVersion().equals("2.0");

The problem is that while the logic will work if the TLD says
<jsp-version>2.0</jsp-version>, it won't work for any jsp-version below that.

A better way would be to say something like:
float taglibRequiredVersion =
boolean checkDeferred = taglibRequiredVersion > 2.0f;

I tried this and it works.  However, this is not a complete fix because it
doesn't catch NumberFormatException.

Also, some refactoring might be in order because this same logic is found
elsewhere in Validator.java and also in TagFileDirectiveVisitor.  I'm not sure
if the logic in those two places is correct or not.

I'm attaching a war with a simple tag that demonstrates the problem.

Comment 1 Stan Silvert 2006-12-04 14:00:30 UTC
Created attachment 19215 [details]
war for testing
Comment 2 Remy Maucherat 2006-12-04 15:27:28 UTC
I am not totally convinced this is really a bug. Maybe. Elsewhere in the class,
there's a check for 1.2 and 2.0, which seems more accurate (and easier).
Comment 3 Stan Silvert 2006-12-04 16:16:28 UTC
You could also say:

boolean checkDeferred = (!version.equals("1.2") && !version.equals("2.0"))

That takes advantage of the fact that 1.2,2.0, and 2.1 are the only versions
where the <jsp-version> tag was defined.  However, doing it that way doesn't
allow someone to say <jsp-version>1.1</jsp-version>.  Maybe it shouldn't be
allowed so you throw an error in that case?

As for it being a bug, I'm quite certain.  An application written for JSP 1.2
should run the same in JSP 2.1.  As of now, that is not true for taglibs with
<jsp-version>1.2</jsp-version>.  Backward compatibility is broken if an
attribute value starts with "#{".  Just try the WAR in Tomcat 5.5 and you will
see that it works.
Comment 4 Stan Silvert 2006-12-04 16:42:22 UTC
BTW, I suspect that this code in Validator.java is wrong as well (and I don't
mean just the JSP 2.2 comment (-: )

            // JSP.2.2 - '#{' not allowed in template text
            if (n.getType() == '#') {
                if (!pageInfo.isDeferredSyntaxAllowedAsLiteral()
                        && (tagInfo == null 
                                || ((tagInfo != null) &&
!tagInfo.getTagLibrary().getRequiredVersion().equals("2.0")))) {
                    err.jspError(n, "jsp.error.el.template.deferred");
                } else {
Comment 5 Remy Maucherat 2006-12-05 05:10:42 UTC
I don't really see what these old tags should do with new pages and EL. Maybe
it's supposed to remain compatible, but it does not make that much sense to me.
It's fixed now.
Comment 6 Stan Silvert 2006-12-05 06:27:17 UTC

The old JSF tags processed the EL themselves.  That's the root of the problem. 
So for an Ajax4JSF tag might look like this:

<a4j:commandButton actionListener="#{mybean.action}"/>

The tag would delegate to JSF 1.1 for processing the EL.  This component still
works in JSF 1.2 but now JSF 1.2 delegates back to the EL impl included in JSP
2.1.  So, the old JSF tags need #{mybean.action} to be passed in as a simple
String instead of a MethodExpression or ValueExpression object.