EL returns null for any Map entry keyed by an empty String
----------------------------------------------------------

         Key: MYFACES-315
         URL: http://issues.apache.org/jira/browse/MYFACES-315
     Project: MyFaces
        Type: Bug
    Versions: 1.0.9 beta    
 Environment: Java 1.4.x, Tomcat 5.x
    Reporter: Duffy Gillman
    Priority: Critical


The expression language is coded to return null for any Map access using and 
empty String ("") as a key.  Without a great deal of knowledge about the code 
behind the EL, I was able to find this:

  (source: org/apache/myfaces/el/PropertyResolverImpl.java)

    public Object getValue(Object base, Object property)
            throws EvaluationException, PropertyNotFoundException
    {
        try
        {
            if (base == null || property == null ||
                property instanceof String && ((String)property).length() == 0)
            {
                return null;
            }
            if (base instanceof Map)
            {
                return ((Map) base).get(property);
            }
                                                                                
            // If none of the special bean types, then process as normal Bean
            return getProperty(base, property.toString());
        }

The initial conditional makes it impossible to pass an empty String to a Map, 
even though this is not a violation of the Map contract.  A potential solution 
is:

           if (base == null || property == null ||
                (property instanceof String && ((String)property).length() == 0 
&&
                 !(base instanceof Map)))
            {
                return null;
            }
            if (base instanceof Map)
            {
                return ((Map) base).get(property);
            }

Breaking out the if-conditional into smaller chunks may be more readable.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to