Uploaded image for project: 'Commons BeanUtils'
  1. Commons BeanUtils
  2. BEANUTILS-402

Double-Checked Locking anti pattern in WeakFastHashMap

    XMLWordPrintableJSON

Details

    Description

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

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              malzahn Volker Malzahn
              Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m