From 0d2e314f041c80c185d499b1138d97cade173e1b Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Fri, 21 Jan 2011 08:44:18 +0000
Subject: [PATCH] Code cleanup removing potential issues detected by FindBugs

---
 opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java            |   10 ++++
 opendj-sdk/opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java |   82 ++++++++++++++++++++---------------------
 opendj-sdk/opends/src/server/org/opends/server/util/args/ArgumentParser.java                             |   10 +++--
 3 files changed, 55 insertions(+), 47 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/args/ArgumentParser.java b/opendj-sdk/opends/src/server/org/opends/server/util/args/ArgumentParser.java
index fccbfce..b3a1fc8 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/args/ArgumentParser.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/util/args/ArgumentParser.java
@@ -23,6 +23,7 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
+ *      Portions Copyright 2011 ForgeRock AS
  */
 package org.opends.server.util.args;
 import org.opends.messages.Message;
@@ -577,7 +578,7 @@
 
   /**
    * Adds the provided argument to the set of arguments handled by this parser
-   * and puts the arguement in the general group.
+   * and puts the argument in the general group.
    *
    * @param  argument  The argument to be added.
    *
@@ -613,9 +614,9 @@
       throw new ArgumentException(message);
     }
 
-    if (versionArgument != null)
+    if ((versionArgument != null) && (shortID != null))
     {
-      if (shortID == versionArgument.getShortIdentifier())
+      if (shortID.equals(versionArgument.getShortIdentifier()))
       {
         // Update the version argument to not display its short identifier.
         try {
@@ -1401,7 +1402,8 @@
     {
       if (trailingArgsDisplayName == null)
       {
-        buffer.append(" "+INFO_ARGPARSER_USAGE_TRAILINGARGS.get());
+        buffer.append(" ");
+        buffer.append(INFO_ARGPARSER_USAGE_TRAILINGARGS.get());
       }
       else
       {
diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java b/opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
index f266ad8..4239669 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/util/cli/LDAPConnectionConsoleInteraction.java
@@ -23,6 +23,7 @@
  *
  *
  *      Copyright 2008-2010 Sun Microsystems, Inc.
+ *      Portions Copyright 2011 ForgeRock AS
  */
 
 package org.opends.server.util.cli;
@@ -1150,7 +1151,14 @@
       copySecureArgsList.keyStorePathArg.addValue(keystorePath);
       commandBuilder.addArgument(copySecureArgsList.keyStorePathArg);
     }
-
+    else
+    {
+      // KeystorePath is null. Either it's unspecified or there's a pb
+      // We should throw an exception here, anyway since code below will
+      // anyway
+      throw ArgumentExceptionFactory
+          .incompatiblePropertyModification("null keystorePath");
+    }
 
     // Then the keystore password.
     keystorePassword = secureArgsList.keyStorePasswordArg.getValue();
diff --git a/opendj-sdk/opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java b/opendj-sdk/opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java
index c61f1bb..a578d6f 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/workflowelement/externalchangelog/ECLSearchOperation.java
@@ -23,7 +23,7 @@
  *
  *
  *      Copyright 2008-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2010 ForgeRock AS
+ *      Portions Copyright 2010-2011 ForgeRock AS
  */
 package org.opends.server.workflowelement.externalchangelog;
 
@@ -608,55 +608,51 @@
     // Start a specific ECL session
     eclSession = replicationServer.createECLSession(startECLSessionMsg);
 
-    if (true)
-    {
-      // Loop on result entries
-      int INITIAL=0;
-      int PSEARCH=1;
-      int phase=INITIAL;
-      boolean returnedRoot = false;
-      while (true)
-      {
-        // Check for a request to cancel this operation.
-        checkIfCanceled(false);
+    // Loop on result entries
+    int phase = 0; // 0 is initial phase, 1 is psearch
+    boolean returnedRoot = false;
 
-        ECLUpdateMsg update = eclSession.getNextUpdate();
-        if (update!=null)
+    while (true)
+    {
+      // Check for a request to cancel this operation.
+      checkIfCanceled(false);
+
+      ECLUpdateMsg update = eclSession.getNextUpdate();
+      if (update!=null)
+      {
+        if (!returnedRoot)
         {
-          if (!returnedRoot)
+          returnRootEntryIfRequired(true);
+          returnedRoot = true;
+        }
+        if (phase == 0)
+        {
+          if (!buildAndReturnEntry(update))
           {
-            returnRootEntryIfRequired(true);
-            returnedRoot = true;
-          }
-          if (phase==INITIAL)
-          {
-            if (!buildAndReturnEntry(update))
-            {
-              // Abandon, Size limit reached
-              eclSession.close();
-              break;
-            }
+            // Abandon, Size limit reached
+            eclSession.close();
+            break;
           }
         }
-        else
+      }
+      else
+      {
+        if (!returnedRoot)
         {
-          if (!returnedRoot)
+          returnRootEntryIfRequired(false);
+          returnedRoot = true;
+        }
+        if (phase == 0)
+        {
+          if (this.persistentSearch == null)
           {
-            returnRootEntryIfRequired(false);
-            returnedRoot = true;
+            eclSession.close();
+            break;
           }
-          if (phase==INITIAL)
+          else
           {
-            if (this.persistentSearch == null)
-            {
-              eclSession.close();
-              break;
-            }
-            else
-            {
-              phase=PSEARCH;
-              break;
-            }
+            phase = 1;
+            break;
           }
         }
       }
@@ -1535,6 +1531,7 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   public CancelResult cancel(CancelRequest cancelRequest)
   {
     if (debugEnabled())
@@ -1553,6 +1550,7 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   public void abort(CancelRequest cancelRequest)
   {
     if (debugEnabled())
@@ -1580,7 +1578,7 @@
   {
     //  the conversion from one unique identifier to an other is
     //  a question of formating : the last "-" is placed
-    StringBuffer buffer = new StringBuffer(entryUid);
+    StringBuilder buffer = new StringBuilder(entryUid);
     //  Delete a "-" at 13 to get something like
     buffer.deleteCharAt(13);
 

--
Gitblit v1.10.0