https://bz.apache.org/bugzilla/show_bug.cgi?id=69406

            Bug ID: 69406
           Summary: StringInterpreterEnum rethrows
                    IllegalArgumentException for invalid enum
           Product: Tomcat 9
           Version: 9.0.x
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Jasper
          Assignee: dev@tomcat.apache.org
          Reporter: jeng...@amazon.com
  Target Milestone: -----

When StringInterpreterEnum is used, an attempt to evaluate a non-existent enum
value results in an IllegalArgumentException that interrupts JSP code
generation and is recorded by the caller.  The desired behavior is to instead
fall back to request-time EL interpretation, similar to the behavior of
ELInterpretertagSetters when encountering a non-existent enum value.

The use of non-existent enums shows up repeatedly in our large application
thanks to a poor coding practice of using "${''}" to represent null. This works
during EL resolution but not at compile-time.


Current code:

@Override
protected String coerceToOtherType(Class<?> c, String s, boolean
isNamedAttribute) {
        if (c.isEnum() && !isNamedAttribute) {
                @SuppressWarnings({ "unchecked", "rawtypes" })
                Enum<?> enumValue = Enum.valueOf((Class<? extends Enum>) c, s);
                return c.getName() + "." + enumValue.name();
        }

        return null;
}

Should be wrapped in a try/catch such as:

@Override
protected String coerceToOtherType(Class<?> c, String s, boolean
isNamedAttribute) {
        if (c.isEnum() && !isNamedAttribute) {
                @SuppressWarnings({ "unchecked", "rawtypes" })
        try {
                        Enum<?> enumValue = Enum.valueOf((Class<? extends
Enum>) c, s);
                        return c.getName() + "." + enumValue.name();
                } catch (IllegalArgumentException iae) {
            log.debug(Localizer.getMessage("jsp.error.typeConversion", s,
"Enum[" + c.getName() + "]"), iae);
                }
        }

        return null;
}

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to