From 04ea94b45e747d19ad1bbf105434aab2f889f1ed Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Thu, 20 Sep 2007 13:54:09 +0000
Subject: [PATCH] Fix for 2244 : null pointer Exception in replication code.

---
 opendj-sdk/opends/src/server/org/opends/server/replication/plugin/Historical.java                                 |    3 +
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ModifyConflictTest.java |   42 +++++++++++++++++++++
 opendj-sdk/opends/src/server/org/opends/server/replication/plugin/AttrInfoSingle.java                             |   24 ++++++++++--
 3 files changed, 64 insertions(+), 5 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/AttrInfoSingle.java b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/AttrInfoSingle.java
index e57959a..c6aad7e 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/AttrInfoSingle.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/AttrInfoSingle.java
@@ -107,7 +107,15 @@
       break;
 
     case REPLACE:
-      deleteTime = addTime = changeNumber;
+      if (value == null)
+      {
+        // REPLACE with null value is actually a DELETE
+        deleteTime = changeNumber;
+      }
+      else
+      {
+        deleteTime = addTime = changeNumber;
+      }
       value = newValue;
       break;
 
@@ -184,9 +192,17 @@
       }
       else
       {
-        addTime = changeNumber;
-        value = newValue;
-        deleteTime = changeNumber;
+        if (newValue == null)
+        {
+          value = newValue;
+          deleteTime = changeNumber;
+        }
+        else
+        {
+          addTime = changeNumber;
+          value = newValue;
+          deleteTime = changeNumber;
+        }
       }
       break;
 
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/Historical.java b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/Historical.java
index 2912126..c5b60bb 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/Historical.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/Historical.java
@@ -281,7 +281,8 @@
           }
           else if (valInfo.getValueUpdateTime() != null)
           {
-            if (delAttr && valInfo.getValueUpdateTime() == deleteTime)
+            if ((delAttr && valInfo.getValueUpdateTime() == deleteTime)
+               && (valInfo.getValue() != null))
             {
               strValue = type.getNormalizedPrimaryName() + optionsString + ":" +
               valInfo.getValueUpdateTime().toString() +  ":repl:" +
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ModifyConflictTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ModifyConflictTest.java
index 7572bf8..260f328 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ModifyConflictTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ModifyConflictTest.java
@@ -161,6 +161,48 @@
                11, false);
 
   }
+  
+  /**
+   * Test that replace with null value is corrrectly seen as a delete
+   * by doing first a replace with null, then add at at previous time
+   * then check that the add was ignored
+   */
+  @Test()
+  public void replaceWithNull() throws Exception
+  {
+    Entry entry = initializeEntry();
+
+    // load historical from the entry
+    Historical hist = Historical.load(entry);
+
+    /*
+     * simulate a replace with null done at time t3
+     */
+    testModify(entry, hist, "displayname", ModificationType.REPLACE, null, 3,
+        true);
+
+    /*
+     * Now simulate an add at an earlier date that the previous replace. The
+     * conflict resolution should detect that this add must be ignored.
+     */
+    testModify(entry, hist, "displayname", ModificationType.ADD,
+        "older value", 1, false);
+
+    /*
+     * Now simulate an add at an earlier date that the previous delete. The
+     * conflict resolution should detect that this add must be ignored. (a
+     * second time to make sure that historical information is kept...)
+     */
+    testModify(entry, hist, "displayname", ModificationType.ADD,
+        "older value", 2, false);
+
+    /*
+     * Now simulate an add at a later date that the previous delete.
+     * conflict resolution should keep it
+     */
+    testModify(entry, hist, "displayname", ModificationType.ADD, "new value",
+        4, true);
+  }
 
   /**
    * Test that conflict between modify-add and modify-replace for

--
Gitblit v1.10.0