Bug 44994 - JSP EL condition expression fails when nested: ${a ? b ? x: y: z}
Summary: JSP EL condition expression fails when nested: ${a ? b ? x: y: z}
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Jasper (show other bugs)
Version: 6.0.16
Hardware: Sun Solaris
: P2 normal (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-13 23:38 UTC by James Manger
Modified: 2008-05-20 15:39 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description James Manger 2008-05-13 23:38:42 UTC
A JSP Expression Language (EL) conditional expression cannot have another conditional expression as its "true" expression.

The following fails:
  ${0 lt a ? 1 lt a ? "many": "one": "none"}

It throws the following exception (the 19th character is the second question mark):
  org.apache.el.parser.ParseException: Encountered "?" at line 1, column 19.
  Was expecting one of:
    "." ...
    "[" ...
...
	org.apache.el.parser.ELParser.generateParseException(ELParser.java:1890)
	org.apache.el.parser.ELParser.jj_consume_token(ELParser.java:1770)
	org.apache.el.parser.ELParser.Choice(ELParser.java:220)

The expression succeeds if brackets are added around the inner conditional expression:
  ${0 lt a ? (1 lt a ? "many": "one"): "none"}

I assume the bug is in ELParser.jjt (in apache-tomcat-6.0.16-src/java/org/apache/el/parser/). It uses Or(), instead of Choice(), for the "true" expression.

WRONG:   Or() (<QUESTIONMARK> Or() <COLON> Choice() #Choice(3))*
RIGHT:   Or() (<QUESTIONMARK> Choice() <COLON> Choice() #Choice(3))*


Diff:
107c107
<       Or() (<QUESTIONMARK> Or() <COLON> Choice() #Choice(3))*
---
>       Or() (<QUESTIONMARK> Choice() <COLON> Choice() #Choice(3))*

This bug was not present in Tomcat 5.5.
Comment 1 Mark Thomas 2008-05-17 10:36:36 UTC
This has been fixed in trunk and proposed for 6.0.x
Comment 2 Mark Thomas 2008-05-20 15:39:53 UTC
This has been fixed in 6.0.x and will be included in 6.0.17 onwards.