#225 race condition when statistics are enabled

Dozer v5.2
closed-fixed
5
2009-12-08
2009-10-21
Jeff Mark
No

We are seeing a race condition in StatisticsManager of Dozer 4.2.1. Specifically here is the stack trace:

java.lang.IllegalArgumentException: Statistic already exists for type: Field Mapping Success Count
at net.sf.dozer.util.mapping.stats.StatisticsManager.addStatistic(StatisticsManager.java:144)
at net.sf.dozer.util.mapping.stats.StatisticsManager.increment(StatisticsManager.java:114)
at net.sf.dozer.util.mapping.stats.StatisticsManager.increment(StatisticsManager.java:89)
at net.sf.dozer.util.mapping.stats.StatisticsManager.increment(StatisticsManager.java:85)

and the 4.2.1 code that is in question would do this if multiple threads get to this point at the same time and both try to add the new object to the map you would get the exception. So either need to synchronize this block or just drop the statistic.

// Get Statistic object for the specified type. If it doesnt aleady exist, create it
Statistic statistic = (Statistic) statisticsMap.get(statisticType);
if (statistic == null) {
statistic = new Statistic(statisticType);
addStatistic(statistic);
}

I checked dozer 4.4.1 and the same code is above. Also dozer 5.1 still seems to have this issue, see below from StatisticsManagerImpl.java in dozer-5.1:

// Get Statistic object for the specified type. If it doesnt aleady exist, create it
Statistic<T> statistic = (Statistic<T>) statisticsMap.get(statisticType);
if (statistic == null) {
statistic = new Statistic<T>(statisticType);
addStatistic(statistic);
}

Discussion

  • dmitry (lv)

    dmitry (lv) - 2009-12-08
    • milestone: 898417 --> Dozer v5.2
    • assigned_to: nobody --> buzdin
    • status: open --> closed-fixed
     
  • dmitry (lv)

    dmitry (lv) - 2009-12-08

    fixed in upcoming 5.2. Thank you for the detailed explanation. Will be using ConcurrentHashMap instead simple Map and ignore tries to overwrite existing statistics object.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks