Share

FreeMarker

Tracker: Bugs

5 concurrent modification of simplehash - ID: 1939742
Last Update: Comment added ( ddekany )

i want to iterate through a hash checking for keys and variations of keys.
for example:

<#list myhash?keys as key>
<#if myhash[key] == 'foo'>
do something
<#elseif myhash[key + 'variation'] == 'bar'>
do something else
</#if>
</#list>

if key + 'variation' doesn't exist in myhash, then SimpleHash will do a put
(SimpleHash line 204), which will cause a ConcurrentModificationException
on the next iteration because the hash has been modified.

the reason for the put seems to be to cache the value wrapped in a
TemplateModel. i'm sure this is a good thing for performance reasons, but
it obviously has its side effects.

the solution is to not add a new entry to the hash. if you are just
replacing the value for a particular key with a new value, then you won't
trigger a ConcurrentModificationException. but if the key isn't in the
hash, then you shouldn't add it.

so after line 202, add this:

if (result == null) return tm;


Alex Burgel ( aburgel ) - 2008-04-10 21:33

5

Closed

Fixed

Attila Szegedi

None

None

Public


Comments ( 2 )




Date: 2008-05-08 13:54
Sender: ddekanyProject Admin


Fix released with 2.3.13.


Date: 2008-04-28 07:52
Sender: szegediaProject AdminAccepting Donations


Fixed on 2.3 branch. 2.4 doesn't seem to have the problem since it was
reworked for JAVA_NULL handling.


Log in to comment.

Attached File

No Files Currently Attached

Changes ( 4 )

Field Old Value Date By
status_id Open 2008-05-08 13:54 ddekany
close_date - 2008-05-08 13:54 ddekany
resolution_id None 2008-04-28 07:52 szegedia
assigned_to nobody 2008-04-28 07:52 szegedia