BeanConvertor uses a WeakHashMap in the wrong way.
--------------------------------------------------

         Key: COCOON-1867
         URL: http://issues.apache.org/jira/browse/COCOON-1867
     Project: Cocoon
        Type: Bug

  Components: Blocks: Forms  
    Versions: 2.1.10-dev (current SVN), 2.1.9    
    Reporter: Simone Gianni
 Assigned to: Simone Gianni 
    Priority: Critical


In the BeanConvertor, when a bean is converted to a string, the bean is stored 
in a WeakHashMap this way :

m_objects.put(idValue, value);

Actually idValue is a string representing the bean (toString or evalued on 
id_path) while the value is the bean.

WeakHashMap DOES NOT remove a mapping when the bean is garbage collected, but 
actually removes it when the KEY is garbage collected. This means that since 
the string is serialized to XML in the form instance and then dropped, the 
mapping could be removed even while the user is filling the form, with the 
conseguence that the convertor stops working, see a null value, reports a 
validation error, even if the user correctly filled the form.

This is even worse when you are using a selection list of beans, because in 
that case the bean has no chanches to enter the m_objects map anymore, since 
the selection list has been generated and stored st the beginning of the form 
(maybe thru flow, or on-create) and is not asking the convertor to convert the 
beans anymore.

A better solution (and IMMO what the author intended to do) is to remove the 
mapping (so that the map does not hold references for everything) when the BEAN 
gets garbage collected. In this case I'm experimenting with apache commons 
ReferenceMap, which actually can remove mappings when the value (bean) is 
garbage collected.

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