mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Nicolas Capponi
16.15.2015 5f13892a157ea60b88841e7d9895ee0988944a72
Prevent ConcurrentModificationException in Log read-only methods

Add missing usage of shared lock in getNewestRecord(),
getOldestRecord() and getNumberOfRecords() methods
1 files modified
26 ■■■■■ changed files
opendj3-server-dev/src/server/org/opends/server/replication/server/changelog/file/Log.java 26 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/replication/server/changelog/file/Log.java
@@ -21,7 +21,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2014 ForgeRock AS.
 *      Copyright 2014-2015 ForgeRock AS.
 */
package org.opends.server.replication.server.changelog.file;
@@ -624,8 +624,16 @@
   */
  public Record<K, V> getOldestRecord() throws ChangelogException
  {
    sharedLock.lock();
    try
    {
    return getOldestLogFile().getOldestRecord();
  }
    finally
    {
      sharedLock.unlock();
    }
  }
  /**
@@ -637,8 +645,16 @@
   */
  public Record<K, V> getNewestRecord() throws ChangelogException
  {
    sharedLock.lock();
    try
    {
    return getHeadLogFile().getNewestRecord();
  }
    finally
    {
      sharedLock.unlock();
    }
  }
  /**
   * Returns the number of records in the log.
@@ -650,12 +666,20 @@
  public long getNumberOfRecords() throws ChangelogException
  {
    long count = 0;
    sharedLock.lock();
    try
    {
    for (final LogFile<K, V> logFile : logFiles.values())
    {
      count += logFile.getNumberOfRecords();
    }
    return count;
  }
    finally
    {
      sharedLock.unlock();
    }
  }
  /**
   * Purge the log up to and excluding the provided key.