From 67b0196d48f07937a9e333a091599c810d5bb538 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 11 Dec 2014 11:34:39 +0000
Subject: [PATCH] DN2URI.java, EntryContainer.java: Rewrote rather convoluted code to make its intent more explicit.

---
 opendj3-server-dev/src/server/org/opends/server/backends/jeb/EntryContainer.java |   42 ++++++++++++++++++++----------------------
 1 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/EntryContainer.java b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/EntryContainer.java
index 8661d84..a04a358 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/EntryContainer.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/EntryContainer.java
@@ -735,9 +735,8 @@
    * <CODE>SearchOperation.returnEntry</CODE> method.
    *
    * @param searchOperation The search operation to be processed.
-   * @throws org.opends.server.types.DirectoryException
-   *          If a problem occurs while processing the
-   *          search.
+   * @throws DirectoryException
+   *          If a problem occurs while processing the search.
    * @throws DatabaseException If an error occurs in the JE database.
    * @throws CanceledOperationException if this operation should be cancelled.
    */
@@ -1086,8 +1085,9 @@
      * "ou=people,dc=example,dc=com".
      */
     byte[] baseDNKey = dnToDNKey(aBaseDN, this.baseDN.size());
+    final byte special = 0x00;
     byte[] suffix = Arrays.copyOf(baseDNKey, baseDNKey.length+1);
-    suffix[suffix.length-1] = 0x00;
+    suffix[suffix.length - 1] = special;
 
     /*
      * Set the ending value to a value of equal length but slightly
@@ -1095,8 +1095,8 @@
      * reverse order we must set the first byte (the comma).
      * No possibility of overflow here.
      */
-    byte[] end = suffix.clone();
-    end[end.length-1] = (byte) (end[end.length-1] + 1);
+    byte[] end = Arrays.copyOf(suffix, suffix.length);
+    end[end.length - 1] = (byte) (special + 1);
 
     // Set the starting value.
     byte[] begin;
@@ -1609,15 +1609,16 @@
        * downwards.
        */
       byte[] entryDNKey = dnToDNKey(entryDN, this.baseDN.size());
+      byte special = 0x00;
       byte[] suffix = Arrays.copyOf(entryDNKey, entryDNKey.length+1);
-      suffix[suffix.length-1] = 0x00;
+      suffix[suffix.length - 1] = special;
 
       /*
        * Set the ending value to a value of equal length but slightly
        * greater than the suffix.
        */
-      byte[] end = suffix.clone();
-      end[end.length-1] = (byte) (end[end.length-1] + 1);
+      byte[] end = Arrays.copyOf(suffix, suffix.length);
+      end[end.length - 1] = (byte) (special + 1);
 
       int subordinateEntriesDeleted = 0;
 
@@ -2077,17 +2078,14 @@
    * @param modifyDNOperation The modify DN operation with which this action
    *                          is associated.  This may be <CODE>null</CODE>
    *                          for modify DN operations performed internally.
-   * @throws org.opends.server.types.DirectoryException
-   *          If a problem occurs while trying to perform
-   *          the rename.
-   * @throws org.opends.server.types.CanceledOperationException
-   *          If this backend noticed and reacted
-   *          to a request to cancel or abandon the
-   *          modify DN operation.
+   * @throws DirectoryException
+   *          If a problem occurs while trying to perform the rename.
+   * @throws CanceledOperationException
+   *          If this backend noticed and reacted to a request to cancel
+   *          or abandon the modify DN operation.
    * @throws DatabaseException If an error occurs in the JE database.
    */
-  public void renameEntry(DN currentDN, Entry entry,
-      ModifyDNOperation modifyDNOperation)
+  public void renameEntry(DN currentDN, Entry entry, ModifyDNOperation modifyDNOperation)
   throws DatabaseException, DirectoryException, CanceledOperationException
   {
     Transaction txn = beginTransaction();
@@ -2200,15 +2198,16 @@
        * downwards.
        */
       byte[] currentDNKey = dnToDNKey(currentDN, this.baseDN.size());
+      byte special = 0x00;
       byte[] suffix = Arrays.copyOf(currentDNKey, currentDNKey.length+1);
-      suffix[suffix.length-1] = 0x00;
+      suffix[suffix.length - 1] = special;
 
       /*
        * Set the ending value to a value of equal length but slightly
        * greater than the suffix.
        */
-      byte[] end = suffix.clone();
-      end[end.length-1] = (byte) (end[end.length-1] + 1);
+      byte[] end = Arrays.copyOf(suffix, suffix.length);
+      end[end.length - 1] = (byte) (special + 1);
 
       DatabaseEntry data = new DatabaseEntry();
       DatabaseEntry key = new DatabaseEntry(suffix);
@@ -2239,7 +2238,6 @@
           }
 
           // We have found a subordinate entry.
-
           EntryID oldID = new EntryID(data);
           Entry oldEntry = id2entry.get(txn, oldID, LockMode.DEFAULT);
 

--
Gitblit v1.10.0