From 4b1d6c96c36b2c9de904520649dac89bd46c544c Mon Sep 17 00:00:00 2001
From: ludovicp <ludovicp@localhost>
Date: Mon, 31 May 2010 09:44:06 +0000
Subject: [PATCH] Fix an issue in MakeLDIF (NPE) with presence:n tag on RDN attribute

---
 opendj-sdk/opends/src/messages/messages/tools.properties                    |    4 ++++
 opendj-sdk/opends/src/server/org/opends/server/tools/makeldif/MakeLDIF.java |   34 ++++++++++++++++++++++++++++------
 2 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/opendj-sdk/opends/src/messages/messages/tools.properties b/opendj-sdk/opends/src/messages/messages/tools.properties
index 7139858..fa245b2 100644
--- a/opendj-sdk/opends/src/messages/messages/tools.properties
+++ b/opendj-sdk/opends/src/messages/messages/tools.properties
@@ -2564,3 +2564,7 @@
 INFO_TIMEOUT_PLACEHOLDER_1711={timeout}
 INFO_DESCRIPTION_CONNECTION_TIMEOUT_1712=Maximum length of time (in \
  milliseconds) that can be taken to establish a connection
+MILD_ERR_MAKELDIF_CANNOT_WRITE_ENTRY_WITHOUT_DN_1713=An error occurred while \
+attempting to write entry to LDIF:  Could not calculate the DN for the \
+entry (no value found for the RDN attribute %s)
+
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/makeldif/MakeLDIF.java b/opendj-sdk/opends/src/server/org/opends/server/tools/makeldif/MakeLDIF.java
index 9c30c39..d28e65d 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/makeldif/MakeLDIF.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/makeldif/MakeLDIF.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2009 Sun Microsystems, Inc.
+ *      Copyright 2006-2010 Sun Microsystems, Inc.
  */
 package org.opends.server.tools.makeldif;
 import org.opends.messages.Message;
@@ -37,6 +37,7 @@
 import java.util.Random;
 
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.types.AttributeType;
 import org.opends.server.types.ExistingFileBehavior;
 import org.opends.server.types.LDIFExportConfig;
 import org.opends.server.types.NullOutputStream;
@@ -434,12 +435,33 @@
   {
     try
     {
-      ldifWriter.writeTemplateEntry(entry);
-
-      if ((++entriesWritten % 1000) == 0)
+      if (entry.getDN() != null)
       {
-        Message message = INFO_MAKELDIF_PROCESSED_N_ENTRIES.get(entriesWritten);
-        out.println(wrapText(message, MAX_LINE_WIDTH));
+        ldifWriter.writeTemplateEntry(entry);
+
+        if ((++entriesWritten % 1000) == 0)
+        {
+          Message message =
+            INFO_MAKELDIF_PROCESSED_N_ENTRIES.get(entriesWritten);
+          out.println(wrapText(message, MAX_LINE_WIDTH));
+        }
+      }
+      else
+      {
+        AttributeType[] rdnAttrs = entry.getTemplate().getRDNAttributes();
+        String nullRdn = "";
+        for (AttributeType att : rdnAttrs)
+        {
+          if (entry.getValue(att) == null)
+          {
+            nullRdn = att.getNameOrOID();
+            break ;
+          }
+        }
+        Message message =
+          ERR_MAKELDIF_CANNOT_WRITE_ENTRY_WITHOUT_DN.get(nullRdn);
+        err.println(wrapText(message, MAX_LINE_WIDTH));
+        return true;
       }
 
       return true;

--
Gitblit v1.10.0