Bug 44994

Summary: JSP EL condition expression fails when nested: ${a ? b ? x: y: z}
Product: Tomcat 6 Reporter: James Manger <James.H.Manger>
Component: JasperAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P2    
Version: 6.0.16   
Target Milestone: default   
Hardware: Sun   
OS: Solaris   

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:
    "." ...
    "[" ...

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))*

<       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.