commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hans-Peter Störr (JIRA) <j...@apache.org>
Subject [jira] [Commented] (BEANUTILS-402) Double-Checked Locking anti pattern in WeakFastHashMap
Date Tue, 30 Aug 2016 14:04:20 GMT

    [ https://issues.apache.org/jira/browse/BEANUTILS-402?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15449094#comment-15449094
] 

Hans-Peter Störr commented on BEANUTILS-402:
--------------------------------------------

Why don't you just fix it with making org.apache.commons.beanutils.WeakFastHashMap.map volatile?
That's easy and solves the problem. I guess hardly anyone uses Java versions less than Java
5.

> Double-Checked Locking anti pattern in WeakFastHashMap
> ------------------------------------------------------
>
>                 Key: BEANUTILS-402
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-402
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: Bean / Property Utils, ConvertUtils & Converters, Locale BeanUtils
/ Converters
>    Affects Versions: 1.8.3
>         Environment: Win XP, but doesn't matter
>            Reporter: Volker Malzahn
>             Fix For: 2.0
>
>
> The implementation of WeakFastHashMap has the flaw of implementing the Double-Checked
Locking anti pattern (see JavaDoc of that class). As described in the JavaDoc "This class
is not cross-platform.". In https://issues.apache.org/jira/browse/BEANUTILS-318 and https://issues.apache.org/jira/browse/BEANUTILS-373
this was solved for MethodUtils (usage of WeakFastHashMap). But following classes still use
WeakFastHashMap for a cache: BeanUtils, ConvertUtilsBean, PropertyUtilsBean, LocaleConvertUtilsBean.
> I would suggest to make WeakFastHashMap deprecated and to change every usage of that
class inside the commons-beanutils classes to a synchronized normal WeakHashMap like done
(as the second step) in https://issues.apache.org/jira/browse/BEANUTILS-318. Otherwise strange
things may happen in unusual plattforms/environments. An alternative could be to use "volatile"
inside WeakFastHashMap which would fix it for Java 5 and higher (see http://en.wikipedia.org/wiki/Double-checked_locking
or http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html#volatile).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message