Bug 50105

Summary: Violation of JSP-EL spec version 2.1 when coerce Enum to String
Product: Tomcat 6 Reporter: Oliver Siegmar <oliver>
Component: JasperAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 6.0.29   
Target Milestone: default   
Hardware: PC   
OS: Linux   

Description Oliver Siegmar 2010-10-17 05:26:20 UTC
Section 1.18.2 of the 2.1 JSP-EL spec (Coerce A to String) says "if A is Enum, return A.name()". This is not always the case in Tomcat 6.0.29. To demonstrate the bug, I created some custom code (enum, Tag, JSP):

Tag:

public class MyCustomTag implements Tag {
    public void setValue(String value) {
        System.out.println(value);
    }
    @Override public void setPageContext(PageContext pc) {}
    @Override public void setParent(Tag t) {}
    @Override public Tag getParent() { return null; }
    @Override public int doStartTag() throws JspException { return SKIP_BODY; }
    @Override public int doEndTag() throws JspException { return EVAL_PAGE; }
    @Override public void release() {}
}

TLD:

<?xml version="1.0" encoding="UTF-8" ?>
<taglib xsi:schemaLocation="http://java.sun.com/xml/ns/javaeeweb-
jsptaglibrary_2_1.xsd" xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1">
    <tlibversion>1.0</tlibversion>
    <uri>http://my-domain.org/customLib</uri>
    <tag>
        <name>customTag</name>
        <tagclass>mypackage.MyCustomTag</tagclass>
        <bodycontent>empty</bodycontent>
        <attribute>
            <name>value</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
</taglib>

Enum:

public enum MyEnum {

    APPLE, ORANGE;

    @Override
    public String toString() {
        return "this is a " + name();
    }

}

JSP:

<%@taglib prefix="myLib" uri="http://my-domain.org/customLib"%>

<myLib:customTag value="${myEnum}"/>
<myLib:customTag value="foo.${myEnum}.bar"/>

Because the value myEnum is was set to MyEnum.ORANGE, i would expect, that this outputs:

ORANGE
foo.ORANGE.bar

But the output in catalina.out instead is:

ORANGE
foo.this is a ORANGE.bar


Which is a violation of the JSP-EL spec (if I understood it right).
Comment 1 Mark Thomas 2010-10-19 09:06:18 UTC
You understood it right.

I have fixed this in trunk which will be included in 7.0.5 onwards. I have also proposed the same fix for 6.0.x.
Comment 2 Mark Thomas 2010-10-25 12:03:37 UTC
This has been fixed in 6.0.x and will be included in 6.0.30 onwards.