tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maximilian Stocker <>
Subject RE: Inconsistent output of Java 5 enums
Date Fri, 15 Oct 2010 17:47:18 GMT
I did some testing myself just now with a simple enum and I think this is a Tomcat bug somewhere.
Whether the old behaviour was right or wrong vs the new I don't know. I also think that your
enum is screwy or doing something different then you think.

At any rate I created a simple enum

public enum Fruit{APPLE,ORANGE,BANANA;

        public String toString(){
                case APPLE:
                        return "A is for Apple";
                case ORANGE:
                        return "O is for Orange";
                                return "B is for Banana";

I then used the following in a JSP (enumtest is a simple model object with a Fruit property
set to Fruit.APPLE)

#1 = ${enumtest.fruit}
#2 = <c:out value="${enumtest.fruit}"/>

On tomcat 5.5. I get

#1 = A is for Apple
#2 = A is for Apple

On tomcat 6 I get

#1 = APPLE
#2 = A is for Apple

Which is obviously not the same, and surprised me, but it seems if I understand this thread
that it is the opposite of what you are seeing and that I really don't understand.

-----Original Message-----
From: Oliver Siegmar []
Sent: Friday, October 15, 2010 1:29 PM
To: Tomcat Users List
Subject: Re: Inconsistent output of Java 5 enums


Am Friday 15 October 2010 schrieb Maximilian Stocker:
> > > Or, just consistently use EL, since that actually works as you expect.
> >
> > +1  '<c:out' seems surplus.
> And how do you escape XML characters to entity codes using pure EL?
> This seems a valid reason except that is this a problem for your enum?

As stated before, it was just a simplified example.

> If it really is a problem then did you try and create a new getter method
> that returns your to string content in the enum? And then call that with
> c:out.

The enum is part of a 3rd party lib. And of course, there are several
workarounds available, but I want to understand what is happening here and
clearify if it's a bug.

And it's not just the c:out tag - it also happens with other Tags. For
demonstration I've created a custom Tag:

public class MyCustomTag implements Tag {

    public void setValue(String value) {

    public void setPageContext(PageContext pc) {

    public void setParent(Tag t) {

    public Tag getParent() {
        return null;

    public int doStartTag() throws JspException {
        return SKIP_BODY;

    public int doEndTag() throws JspException {
        return EVAL_PAGE;

    public void release() {



<?xml version="1.0" encoding="UTF-8" ?>
<taglib xsi:schemaLocation=" web-
jsptaglibrary_2_1.xsd" xmlns=""
xmlns:xsi="" version="2.1">

And in my JSP file is use it:

<%@taglib prefix="myLib" uri=""%>

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

I would expect, that this outputs:


The output in catalina.out is very interesting:

foo.VALID result, code

Remember, VALID is the enum name() and "VALID result, code 0" is the enum
toString(). I think that is REALLY weird...



To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message