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

Jean-Noel Rouvignac
05.04.2013 899b32151ee1995627602f150607ef16b4f4fa05
Code cleanup.

If I see another if (c != null) try{ c.close(); }catch (Throwable t){}, I am going to bail out!!
2 files modified
143 ■■■■ changed files
opends/src/server/org/opends/server/core/LockFileManager.java 117 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/StaticUtils.java 26 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/core/LockFileManager.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2006-2008 Sun Microsystems, Inc.
 *      Portions Copyright 2013 ForgeRock AS
 */
package org.opends.server.core;
@@ -60,19 +61,19 @@
  // A map between the filenames and the lock files for exclusive locks.
  /** A map between the filenames and the lock files for exclusive locks. */
  private static HashMap<String,FileLock> exclusiveLocks =
       new HashMap<String,FileLock>();
  // A map between the filenames and the lock files for shared locks.
  /** A map between the filenames and the lock files for shared locks. */
  private static HashMap<String,FileLock> sharedLocks =
       new HashMap<String,FileLock>();
  // A map between the filenames and reference counts for shared locks.
  /** A map between the filenames and reference counts for shared locks. */
  private static HashMap<String,Integer> sharedLockReferences =
       new HashMap<String,Integer>();
  // The lock providing threadsafe access to the lock map data.
  /** The lock providing threadsafe access to the lock map data. */
  private static Object mapLock = new Object();
@@ -156,17 +157,7 @@
        failureReason.append(ERR_FILELOCKER_LOCK_SHARED_FAILED_OPEN.get(
                lockFile, getExceptionMessage(e)));
        if (raf != null)
        {
          try
          {
            raf.close();
          }
          catch (Throwable t)
          {
          }
        }
        close(raf);
        return false;
      }
@@ -187,26 +178,7 @@
        failureReason.append(
                ERR_FILELOCKER_LOCK_SHARED_FAILED_LOCK.get(
                        lockFile, getExceptionMessage(e)));
        if (channel != null)
        {
          try
          {
            channel.close();
          }
          catch (Throwable t)
          {
          }
        }
        if (raf != null)
        {
          try
          {
            raf.close();
          }
          catch (Throwable t)
          {
          }
        }
        close(channel, raf);
        return false;
      }
@@ -217,26 +189,7 @@
      {
        failureReason.append(
                ERR_FILELOCKER_LOCK_SHARED_NOT_GRANTED.get(lockFile));
        if (channel != null)
        {
          try
          {
            channel.close();
          }
          catch (Throwable t)
          {
          }
        }
        if (raf != null)
        {
          try
          {
            raf.close();
          }
          catch (Throwable t)
          {
          }
        }
        close(channel, raf);
        return false;
      }
      else
@@ -326,16 +279,7 @@
        failureReason.append(ERR_FILELOCKER_LOCK_EXCLUSIVE_FAILED_OPEN.get(
                lockFile, getExceptionMessage(e)));
        if (raf != null)
        {
          try
          {
            raf.close();
          }
          catch (Throwable t)
          {
          }
        }
        close(raf);
        return false;
      }
@@ -356,27 +300,7 @@
        failureReason.append(
                ERR_FILELOCKER_LOCK_EXCLUSIVE_FAILED_LOCK.get(lockFile,
                                        getExceptionMessage(e)));
        if (channel != null)
        {
          try
          {
            channel.close();
          }
          catch (Throwable t)
          {
          }
        }
        if (raf != null)
        {
          try
          {
            raf.close();
          }
          catch (Throwable t)
          {
          }
        }
        close(channel, raf);
        return false;
      }
@@ -387,26 +311,7 @@
      {
        failureReason.append(
                ERR_FILELOCKER_LOCK_EXCLUSIVE_NOT_GRANTED.get(lockFile));
        if (channel != null)
        {
          try
          {
            channel.close();
          }
          catch (Throwable t)
          {
          }
        }
        if (raf != null)
        {
          try
          {
            raf.close();
          }
          catch (Throwable t)
          {
          }
        }
        close(channel, raf);
        return false;
      }
      else
opends/src/server/org/opends/server/util/StaticUtils.java
@@ -23,7 +23,7 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011-2012 ForgeRock AS
 *      Portions Copyright 2011-2013 ForgeRock AS
 */
package org.opends.server.util;
@@ -4588,5 +4588,29 @@
    }
  }
  /**
   * Closes the provided {@link Closeable}'s ignoring any errors which
   * occurred.
   *
   * @param closeables The closeables to be closed, which may be
   *        <code>null</code>.
   */
  public static void close(Closeable... closeables)
  {
    for (Closeable closeable : closeables)
    {
      if (closeable != null)
      {
        try
        {
          closeable.close();
        }
        catch (IOException ignored)
        {
          // Ignore.
        }
      }
    }
  }
}