From 821d2150765f0ab0ac6ccbbc9f397aa65186d590 Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Wed, 25 Feb 2015 15:56:57 +0000
Subject: [PATCH] OPENDJ-1585 OPENDJ-1843 CR-5758 Improve code related to DN normalization

---
 opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/je/ReplicationDbEnv.java     |    6 
 opendj-server-legacy/src/main/java/org/opends/server/schema/CollationMatchingRuleFactory.java                  |   10 
 opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/Importer.java                                |    8 
 opendj-server-legacy/src/main/java/org/opends/server/tools/DBTest.java                                         |   17 
 opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationDomainMonitor.java          |    3 
 opendj-server-legacy/src/test/java/org/opends/server/extensions/EntryUUIDVirtualAttributeProviderTestCase.java |    4 
 opendj-server-legacy/src/main/java/org/opends/server/tasks/ImportTask.java                                     |   12 
 opendj-server-legacy/src/main/java/org/opends/server/types/RDN.java                                            |  316 +++++++---------------------
 opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/EntryHistorical.java                   |    2 
 opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/EntryContainer.java                          |    2 
 opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java                    |    4 
 opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/TestBindResponseProtocolOp.java            |    6 
 opendj-server-legacy/src/main/java/org/opends/server/types/DN.java                                             |  140 ++---------
 opendj-server-legacy/src/test/java/org/opends/server/types/TestRDN.java                                        |   18 
 opendj-server-legacy/src/test/java/org/opends/server/core/BackendConfigManagerTestCase.java                    |    2 
 opendj-server-legacy/src/main/java/org/opends/server/replication/server/MessageHandler.java                    |    2 
 opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestJebFormat.java                           |   13 
 opendj-server-legacy/src/main/java/org/opends/server/extensions/IsMemberOfVirtualAttributeProvider.java        |    2 
 opendj-server-legacy/src/test/java/org/opends/server/types/TestDN.java                                         |   30 +-
 opendj-server-legacy/src/main/java/org/opends/server/tools/ImportLDIF.java                                     |    2 
 opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java                          |    6 
 opendj-server-legacy/src/main/java/org/opends/server/core/EntryCacheConfigManager.java                         |   19 
 opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/RootContainer.java                           |    2 
 opendj-server-legacy/src/main/java/org/opends/server/extensions/EntryUUIDVirtualAttributeProvider.java         |    2 
 opendj-server-legacy/src/main/java/org/opends/server/plugins/EntryUUIDPlugin.java                              |    2 
 opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/TestJebFormat.java                     |   13 
 opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/TestDeleteResponseProtocolOp.java          |    1 
 opendj-server-legacy/src/main/java/org/opends/server/monitors/ConnectionHandlerMonitor.java                    |    6 
 opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestImportJob.java                           |    3 
 29 files changed, 201 insertions(+), 452 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/EntryContainer.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/EntryContainer.java
index c6509d9..c9dd8f0 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/EntryContainer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/EntryContainer.java
@@ -1675,7 +1675,7 @@
             if (!pluginResult.continueProcessing())
             {
               LocalizableMessage message =
-                  ERR_JEB_DELETE_ABORTED_BY_SUBORDINATE_PLUGIN.get(subordinateEntry.getName().toString());
+                  ERR_JEB_DELETE_ABORTED_BY_SUBORDINATE_PLUGIN.get(subordinateEntry.getName());
               throw new DirectoryException(
                   DirectoryServer.getServerErrorResultCode(), message);
             }
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/Importer.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/Importer.java
index c31ebfc..e46f193 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/Importer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/Importer.java
@@ -794,7 +794,7 @@
         {
           // Create a temp entry container
           sourceEntryContainer = entryContainer;
-          entryContainer = rootContainer.openEntryContainer(baseDN, baseDN.toIrreversibleReadableString()
+          entryContainer = rootContainer.openEntryContainer(baseDN, baseDN.toNormalizedUrlSafeString()
               + "_importTmp");
         }
       }
@@ -1039,7 +1039,7 @@
 
         final EntryContainer replacement = suffix.getEntryContainer();
         replacement.lock();
-        replacement.setDatabasePrefix(baseDN.toIrreversibleReadableString());
+        replacement.setDatabasePrefix(baseDN.toNormalizedUrlSafeString());
         replacement.unlock();
         rootContainer.registerEntryContainer(baseDN, replacement);
       }
@@ -4271,7 +4271,7 @@
         throws JebException
     {
       // Use a compact representation for key
-      byte[] dnBytesForKey = dn.toIrreversibleNormalizedByteString().toByteArray();
+      byte[] dnBytesForKey = dn.toNormalizedByteString().toByteArray();
       key.setData(hashCode(dnBytesForKey));
 
       // Use a reversible representation for value
@@ -4363,7 +4363,7 @@
     {
       Cursor cursor = null;
       DatabaseEntry key = new DatabaseEntry();
-      byte[] dnBytesForKey = dn.toIrreversibleNormalizedByteString().toByteArray();
+      byte[] dnBytesForKey = dn.toNormalizedByteString().toByteArray();
       key.setData(hashCode(dnBytesForKey));
       try
       {
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/RootContainer.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/RootContainer.java
index 52455b0..c7f2f91 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/RootContainer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/RootContainer.java
@@ -233,7 +233,7 @@
     String databasePrefix;
     if(name == null || name.equals(""))
     {
-      databasePrefix = baseDN.toIrreversibleReadableString();
+      databasePrefix = baseDN.toNormalizedUrlSafeString();
     }
     else
     {
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java
index 5021edb..566f3d6 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java
@@ -447,7 +447,7 @@
     this.config = config;
     this.storage = env;
     this.rootContainer = rootContainer;
-    this.databasePrefix = baseDN.toIrreversibleReadableString();
+    this.databasePrefix = baseDN.toNormalizedUrlSafeString();
 
     config.addPluggableChangeListener(this);
 
@@ -1739,7 +1739,7 @@
                   if (!pluginResult.continueProcessing())
                   {
                     LocalizableMessage message =
-                        ERR_JEB_DELETE_ABORTED_BY_SUBORDINATE_PLUGIN.get(subordinateEntry.getName().toString());
+                        ERR_JEB_DELETE_ABORTED_BY_SUBORDINATE_PLUGIN.get(subordinateEntry.getName());
                     throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message);
                   }
                 }
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java
index 67a73ea..74af7f7 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java
@@ -1013,7 +1013,7 @@
 
         final EntryContainer replacement = suffix.getEntryContainer();
         replacement.lock();
-        replacement.setDatabasePrefix(baseDN.toIrreversibleReadableString());
+        replacement.setDatabasePrefix(baseDN.toNormalizedUrlSafeString());
         replacement.unlock();
         rootContainer.registerEntryContainer(baseDN, replacement);
       }
@@ -4092,7 +4092,7 @@
     {
       // Use a compact representation for key
       // and a reversible representation for value
-      final ByteString key = hashCode(dn.toIrreversibleNormalizedByteString());
+      final ByteString key = hashCode(dn.toNormalizedByteString());
       final ByteStringBuilder dnValue = new ByteStringBuilder().append(dn.toString());
 
       return insert(key, dnValue);
@@ -4191,7 +4191,7 @@
     @Override
     public boolean contains(DN dn)
     {
-      final ByteString key = hashCode(dn.toIrreversibleNormalizedByteString());
+      final ByteString key = hashCode(dn.toNormalizedByteString());
       final ByteString existingDns = txn.read(dnCache, key);
       if (existingDns != null)
       {
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/core/EntryCacheConfigManager.java b/opendj-server-legacy/src/main/java/org/opends/server/core/EntryCacheConfigManager.java
index 34a43c3..117f682 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/core/EntryCacheConfigManager.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/core/EntryCacheConfigManager.java
@@ -77,8 +77,8 @@
   private SortedMap<Integer, EntryCache> cacheOrderMap =
       new TreeMap<Integer, EntryCache>();
 
-  /** The entry cache name to level map. The key is a byte string representation of the name (DN). */
-  private Map<ByteString,Integer> cacheNameToLevelMap = new HashMap<ByteString, Integer>();
+  /** The entry cache to level map. */
+  private Map<DN,Integer> cacheNameToLevelMap = new HashMap<DN, Integer>();
 
   // Global entry cache monitor provider name.
   private static final String
@@ -257,7 +257,7 @@
 
     if (!cacheOrderMap.isEmpty() && !cacheNameToLevelMap.isEmpty())
     {
-      final ByteString normDN = configuration.dn().toIrreversibleNormalizedByteString();
+      final ByteString normDN = configuration.dn().toNormalizedByteString();
       if (cacheNameToLevelMap.containsKey(normDN)) {
         int currentCacheLevel = cacheNameToLevelMap.get(normDN);
 
@@ -289,10 +289,10 @@
     // If we this entry cache is already installed and active it
     // should be present in the cache maps, if so use it.
     if (!cacheOrderMap.isEmpty() && !cacheNameToLevelMap.isEmpty()) {
-      final ByteString normDN = configuration.dn().toIrreversibleNormalizedByteString();
-      if (cacheNameToLevelMap.containsKey(normDN))
+      final DN dn = configuration.dn();
+      if (cacheNameToLevelMap.containsKey(dn))
       {
-        int currentCacheLevel = cacheNameToLevelMap.get(normDN);
+        int currentCacheLevel = cacheNameToLevelMap.get(dn);
         entryCache = cacheOrderMap.get(currentCacheLevel);
 
         // Check if the existing cache just shifted its level.
@@ -300,7 +300,7 @@
           // Update the maps then.
           cacheOrderMap.remove(currentCacheLevel);
           cacheOrderMap.put(configuration.getCacheLevel(), entryCache);
-          cacheNameToLevelMap.put(normDN, configuration.getCacheLevel());
+          cacheNameToLevelMap.put(dn, configuration.getCacheLevel());
         }
       }
     }
@@ -481,7 +481,7 @@
       }
       entryCache.finalizeEntryCache();
       cacheOrderMap.remove(configuration.getCacheLevel());
-      cacheNameToLevelMap.remove(configuration.dn().toIrreversibleNormalizedByteString());
+      cacheNameToLevelMap.remove(configuration.dn().toNormalizedByteString());
 
       // Push any changes made to the cache order map.
       setCacheOrder(cacheOrderMap);
@@ -527,8 +527,7 @@
 
     // Add this entry cache to the current cache config maps.
     cacheOrderMap.put(configuration.getCacheLevel(), entryCache);
-    cacheNameToLevelMap.put(configuration.dn().toIrreversibleNormalizedByteString(),
-      configuration.getCacheLevel());
+    cacheNameToLevelMap.put(configuration.dn(), configuration.getCacheLevel());
 
     // Push any changes made to the cache order map.
     setCacheOrder(cacheOrderMap);
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/extensions/EntryUUIDVirtualAttributeProvider.java b/opendj-server-legacy/src/main/java/org/opends/server/extensions/EntryUUIDVirtualAttributeProvider.java
index 83ca267..283883b 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/extensions/EntryUUIDVirtualAttributeProvider.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/extensions/EntryUUIDVirtualAttributeProvider.java
@@ -85,7 +85,7 @@
 
   private String getUUIDString(Entry entry)
   {
-    ByteString normDN = entry.getName().toIrreversibleNormalizedByteString();
+    ByteString normDN = entry.getName().toNormalizedByteString();
     return UUID.nameUUIDFromBytes(normDN.toByteArray()).toString();
   }
 
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/extensions/IsMemberOfVirtualAttributeProvider.java b/opendj-server-legacy/src/main/java/org/opends/server/extensions/IsMemberOfVirtualAttributeProvider.java
index 38ffe88..16e154b 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/extensions/IsMemberOfVirtualAttributeProvider.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/extensions/IsMemberOfVirtualAttributeProvider.java
@@ -314,7 +314,7 @@
             && filter.matchesEntry(e)
             // The set of returned DNs is only used for detecting set membership
             // so it's ok to use the irreversible representation of the DN
-            && (returnedDNs == null || returnedDNs.add(e.getName().toIrreversibleNormalizedByteString()))
+            && (returnedDNs == null || returnedDNs.add(e.getName().toNormalizedByteString()))
             && !searchOperation.returnEntry(e, null))
         {
           return false;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/monitors/ConnectionHandlerMonitor.java b/opendj-server-legacy/src/main/java/org/opends/server/monitors/ConnectionHandlerMonitor.java
index 8bb5578..1ac3b3b 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/monitors/ConnectionHandlerMonitor.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/monitors/ConnectionHandlerMonitor.java
@@ -89,6 +89,7 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   public void initializeMonitorProvider(MonitorProviderCfg configuration)
   {
     monitorName = connectionHandler.getConnectionHandlerName();
@@ -119,6 +120,7 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   public String getMonitorInstanceName()
   {
     return monitorName;
@@ -133,6 +135,7 @@
    * @return  The objectclass that should be included in the monitor entry
    *          created from this monitor provider.
    */
+  @Override
   public ObjectClass getMonitorObjectClass()
   {
     return DirectoryConfig.getObjectClass(OC_MONITOR_CONNHANDLER, true);
@@ -143,12 +146,13 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   public List<Attribute> getMonitorData()
   {
     LinkedList<Attribute> attrs = new LinkedList<Attribute>();
 
     // Configuration DN
-    attrs.add(Attributes.create(configDnType, String.valueOf(connectionHandler.getComponentEntryDN().toString())));
+    attrs.add(Attributes.create(configDnType, connectionHandler.getComponentEntryDN().toString()));
 
     int numConnections = 0;
     LinkedList<ClientConnection> conns = new LinkedList<ClientConnection>(
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/plugins/EntryUUIDPlugin.java b/opendj-server-legacy/src/main/java/org/opends/server/plugins/EntryUUIDPlugin.java
index fb4bd9f..79e26c1 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/plugins/EntryUUIDPlugin.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/plugins/EntryUUIDPlugin.java
@@ -170,7 +170,7 @@
     // Construct a new UUID.  In order to make sure that UUIDs are consistent
     // when the same LDIF is generated on multiple servers, we'll base the UUID
     // on the byte representation of the normalized DN.
-    byte[] dnBytes = entry.getName().toIrreversibleNormalizedByteString().toByteArray();
+    byte[] dnBytes = entry.getName().toNormalizedByteString().toByteArray();
     UUID uuid = UUID.nameUUIDFromBytes(dnBytes);
 
     Attribute uuidAttr = Attributes.create(entryUUIDType, uuid.toString());
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/EntryHistorical.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/EntryHistorical.java
index 5dc8d08..f1153d4 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/EntryHistorical.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/EntryHistorical.java
@@ -928,7 +928,7 @@
           entryDN);
     }
 
-    return UUID.nameUUIDFromBytes(entryDN.toIrreversibleNormalizedByteString().toByteArray()).toString();
+    return UUID.nameUUIDFromBytes(entryDN.toNormalizedByteString().toByteArray()).toString();
   }
 }
 
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/MessageHandler.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/MessageHandler.java
index f79a557..2b43199 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/MessageHandler.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/MessageHandler.java
@@ -633,7 +633,7 @@
     else
     {
       this.baseDN = baseDN;
-      setDomain(!"cn=changelog".equals(baseDN.toIrreversibleReadableString())
+      setDomain(!"cn=changelog".equals(baseDN.toNormalizedUrlSafeString())
           && isDataServer);
     }
   }
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationDomainMonitor.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationDomainMonitor.java
index 93c9e7b..7d915cb 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationDomainMonitor.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ReplicationDomainMonitor.java
@@ -37,6 +37,7 @@
 import org.opends.server.replication.common.ServerState;
 import org.opends.server.replication.protocol.MonitorMsg;
 import org.opends.server.replication.protocol.MonitorRequestMsg;
+import org.opends.server.types.DN;
 import org.opends.server.util.TimeThread;
 
 import static org.opends.messages.ReplicationMessages.*;
@@ -154,7 +155,7 @@
       {
         try
         {
-          String baseDN = domain.getBaseDN().toString();
+          DN baseDN = domain.getBaseDN();
 
           // Prevent out of band monitor responses from updating our pending
           // table until we are ready.
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/je/ReplicationDbEnv.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/je/ReplicationDbEnv.java
index e400564..825ce9f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/je/ReplicationDbEnv.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/je/ReplicationDbEnv.java
@@ -479,7 +479,7 @@
    */
   static Entry<String, String> toReplicaEntry(DN baseDN, int serverId)
   {
-    final String key = serverId + FIELD_SEPARATOR + baseDN.toIrreversibleReadableString();
+    final String key = serverId + FIELD_SEPARATOR + baseDN.toNormalizedUrlSafeString();
     final String value = serverId + FIELD_SEPARATOR + baseDN;
     return new SimpleImmutableEntry<String, String>(key, value);
   }
@@ -496,7 +496,7 @@
    */
   static Entry<byte[], byte[]> toGenIdEntry(DN baseDN, long generationId)
   {
-    final String key = GENERATION_ID_TAG + FIELD_SEPARATOR + baseDN.toIrreversibleReadableString();
+    final String key = GENERATION_ID_TAG + FIELD_SEPARATOR + baseDN.toNormalizedUrlSafeString();
     final String data = GENERATION_ID_TAG + FIELD_SEPARATOR + generationId
         + FIELD_SEPARATOR + baseDN;
     return new SimpleImmutableEntry<byte[], byte[]>(toBytes(key), toBytes(data));
@@ -544,7 +544,7 @@
    */
   private static byte[] toReplicaOfflineKey(DN baseDN, int serverId)
   {
-    return toBytes(OFFLINE_TAG + FIELD_SEPARATOR + serverId + FIELD_SEPARATOR + baseDN.toIrreversibleReadableString());
+    return toBytes(OFFLINE_TAG + FIELD_SEPARATOR + serverId + FIELD_SEPARATOR + baseDN.toNormalizedUrlSafeString());
   }
 
   /** Returns an entry with the provided key and a null value. */
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/schema/CollationMatchingRuleFactory.java b/opendj-server-legacy/src/main/java/org/opends/server/schema/CollationMatchingRuleFactory.java
index e0ff470..cea2ffe 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/schema/CollationMatchingRuleFactory.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/schema/CollationMatchingRuleFactory.java
@@ -272,9 +272,7 @@
       if (nOID == null || languageTag == null)
       {
         configAcceptable = false;
-        LocalizableMessage msg =
-            WARN_ATTR_INVALID_COLLATION_MATCHING_RULE_FORMAT
-                .get(collation);
+        LocalizableMessage msg = WARN_ATTR_INVALID_COLLATION_MATCHING_RULE_FORMAT.get(collation);
         unacceptableReasons.add(msg);
         continue;
       }
@@ -282,10 +280,8 @@
       Locale locale = getLocale(languageTag);
       if (locale == null)
       {
-        LocalizableMessage msg =
-            WARN_ATTR_INVALID_COLLATION_MATCHING_RULE_LOCALE.get(
-                collation, configuration.dn().toString(),
-                languageTag);
+        LocalizableMessage msg = WARN_ATTR_INVALID_COLLATION_MATCHING_RULE_LOCALE.get(
+                collation, configuration.dn(), languageTag);
         unacceptableReasons.add(msg);
         configAcceptable = false;
         continue;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tasks/ImportTask.java b/opendj-server-legacy/src/main/java/org/opends/server/tasks/ImportTask.java
index 91e0250..e320a11 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tasks/ImportTask.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tasks/ImportTask.java
@@ -362,14 +362,14 @@
           {
             // The include branches span across multiple backends.
             LocalizableMessage message = ERR_LDIFIMPORT_INVALID_INCLUDE_BASE.get(
-                includeBranch.toString(), backend.getBackendID());
+                includeBranch, backend.getBackendID());
             throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
           }
         }
         else
         {
           // The include branch is not associated with any backend.
-          LocalizableMessage message = ERR_NO_BACKENDS_FOR_BASE.get(includeBranch.toString());
+          LocalizableMessage message = ERR_NO_BACKENDS_FOR_BASE.get(includeBranch);
           throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
         }
       }
@@ -387,7 +387,7 @@
       if (!Backend.handlesEntry(includeBranch, defaultIncludeBranches, excludeBranches))
       {
         LocalizableMessage message = ERR_LDIFIMPORT_INVALID_INCLUDE_BASE.get(
-            includeBranch.toString(), backend.getBackendID());
+            includeBranch, backend.getBackendID());
         throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
       }
     }
@@ -551,7 +551,7 @@
           else if(backend != locatedBackend)
           {
             // The include branches span across multiple backends.
-            logger.error(ERR_LDIFIMPORT_INVALID_INCLUDE_BASE, includeBranch.toString(), backend.getBackendID());
+            logger.error(ERR_LDIFIMPORT_INVALID_INCLUDE_BASE, includeBranch, backend.getBackendID());
             return TaskState.STOPPED_BY_ERROR;
           }
         }
@@ -613,12 +613,12 @@
     else
     {
       // Make sure the selected backend will handle all the include branches
-      for(DN includeBranch : includeBranches)
+      for (DN includeBranch : includeBranches)
       {
         if (! Backend.handlesEntry(includeBranch, defaultIncludeBranches,
                                    excludeBranches))
         {
-          logger.error(ERR_LDIFIMPORT_INVALID_INCLUDE_BASE, includeBranch.toString(), backend.getBackendID());
+          logger.error(ERR_LDIFIMPORT_INVALID_INCLUDE_BASE, includeBranch, backend.getBackendID());
           return TaskState.STOPPED_BY_ERROR;
         }
       }
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/DBTest.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/DBTest.java
index 241f78a..0733f2b 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/DBTest.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/DBTest.java
@@ -657,7 +657,7 @@
       for(EntryContainer ec : rc.getEntryContainers())
       {
         builder.startRow();
-        builder.appendCell(ec.getBaseDN().toString());
+        builder.appendCell(ec.getBaseDN());
         builder.appendCell(ec.getDatabasePrefix());
         builder.appendCell(ec.getEntryCount());
         count++;
@@ -754,7 +754,7 @@
         if(ec == null)
         {
           printMessage(ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(
-              base.toString(), backend.getBackendID()));
+              base, backend.getBackendID()));
           return 1;
         }
 
@@ -925,8 +925,7 @@
       EntryContainer ec = rc.getEntryContainer(base);
       if(ec == null)
       {
-        printMessage(ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(
-            base.toString(), backend.getBackendID()));
+        printMessage(ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(base, backend.getBackendID()));
         return 1;
       }
 
@@ -1112,8 +1111,7 @@
       EntryContainer ec = rc.getEntryContainer(base);
       if(ec == null)
       {
-        printMessage(ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(
-            base.toString(), backend.getBackendID()));
+        printMessage(ERR_DBTEST_NO_ENTRY_CONTAINERS_FOR_BASE_DN.get(base, backend.getBackendID()));
         return 1;
       }
 
@@ -1134,8 +1132,7 @@
       if(databaseContainer == null)
       {
         printMessage(ERR_DBTEST_NO_DATABASE_CONTAINERS_FOR_NAME.get(
-            databaseName.getValue(), base.toString(),
-            backend.getBackendID()));
+            databaseName.getValue(), base, backend.getBackendID()));
         return 1;
       }
 
@@ -1257,7 +1254,7 @@
               {
                 try
                 {
-                  formatedKey = ByteString.valueOf(key.getData()).toHexString() + ec.getBaseDN();
+                  formatedKey = new String(key.getData()) + ec.getBaseDN();
                   keyLabel = INFO_LABEL_DBTEST_ENTRY_DN.get();
                 }
                 catch(Exception e)
@@ -1493,7 +1490,7 @@
         || databaseContainer instanceof DN2URI)
     {
       // Encode the value as a DN
-      return DN.valueOf(value).toIrreversibleNormalizedByteString().toByteArray();
+      return DN.valueOf(value).toNormalizedByteString().toByteArray();
     }
     else if(databaseContainer instanceof ID2Entry)
     {
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/ImportLDIF.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/ImportLDIF.java
index c04b773..fca8896 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/ImportLDIF.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/ImportLDIF.java
@@ -1041,7 +1041,7 @@
         if (! Backend.handlesEntry(includeBranch, defaultIncludeBranches,
                                    excludeBranches))
         {
-          logger.error(ERR_LDIFIMPORT_INVALID_INCLUDE_BASE, includeBranch.toString(), backendID.getValue());
+          logger.error(ERR_LDIFIMPORT_INVALID_INCLUDE_BASE, includeBranch, backendID.getValue());
           return 1;
         }
       }
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/DN.java b/opendj-server-legacy/src/main/java/org/opends/server/types/DN.java
index f75e39e..d604537 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/DN.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/DN.java
@@ -57,13 +57,6 @@
      mayInvoke=true)
 public final class DN implements Comparable<DN>, Serializable
 {
-/*
- * NOTE:  Any changes to the set of non-static public methods defined
- *        in this class or the arguments that they contain must also
- *        be made in the org.opends.server.interop.LazyDN package to
- *        ensure continued interoperability with third-party
- *        applications that rely on that functionality.
- */
   private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
 
   /**
@@ -89,8 +82,6 @@
    */
   private static final long serialVersionUID = 1184263456768819888L;
 
-
-
   /** The number of RDN components that comprise this DN. */
   private final int numComponents;
 
@@ -103,11 +94,12 @@
   /** The string representation of this DN. */
   private String dnString;
 
-  /** The irreversible normalized byte string representation of this DN. */
+  /**
+   * The normalized byte string representation of this DN, which is not
+   * a valid DN and is not reversible to a valid DN.
+   */
   private ByteString normalizedDN;
 
-
-
   /**
    * Creates a new DN with no RDN components (i.e., a null DN or root
    * DSE).
@@ -117,8 +109,6 @@
     this(new RDN[0]);
   }
 
-
-
   /**
    * Creates a new DN with the provided set of RDNs, arranged with the
    * suffix as the last element.
@@ -2595,50 +2585,24 @@
     {
       return true;
     }
+
     if (o instanceof DN)
     {
-      DN other = (DN) o;
-      if (numComponents == other.numComponents)
-      {
-        if (numComponents == 0)
-        {
-          return true;
-        }
-        for (int i = 0; i < numComponents; i++)
-        {
-          if (!rdnComponents[i].equals(other.rdnComponents[i]))
-          {
-            return false;
-          }
-        }
-        return true;
-      }
-     }
-     return false;
+      DN otherDN = (DN) o;
+      return toNormalizedByteString().equals(otherDN.toNormalizedByteString());
+    }
+    return false;
   }
 
   /**
-   * Retrieves the hash code for this DN.  The hash code will be the
-   * sum of the hash codes for all the RDN components.
+   * Returns the hash code for this DN.
    *
    * @return  The hash code for this DN.
    */
   @Override
   public int hashCode()
   {
-      if (numComponents == 0) {
-          return 0;
-      }
-      int length = numComponents - 1;
-      int hash = 31 * rdnComponents[length].hashCode();
-      if (numComponents > 1)
-      {
-          for (int i = 0; i < length; i++)
-          {
-            hash += rdnComponents[i].hashCode();
-          }
-      }
-      return hash;
+     return toNormalizedByteString().hashCode();
   }
 
   /**
@@ -2687,16 +2651,16 @@
     buffer.append(this);
   }
 
-
-
   /**
-   * Retrieves a normalized representation of the DN with the provided
-   * components.
+   * Retrieves a normalized string representation of this DN.
+   * <p>
    *
-   * @return  The normalized string representation of the provided RDN
-   *          components.
+   * This representation is safe to use in an URL or in a file name.
+   * However, it is not a valid DN and can't be reverted to a valid DN.
+   *
+   * @return  The normalized string representation of this DN.
    */
-  public String toIrreversibleReadableString()
+  public String toNormalizedUrlSafeString()
   {
     if (rdnComponents.length == 0)
     {
@@ -2704,30 +2668,29 @@
     }
 
     StringBuilder buffer = new StringBuilder();
-    rdnComponents[0].toNormalizedReadableString(buffer);
+    buffer.append(rdnComponents[0].toNormalizedUrlSafeString());
 
     for (int i=1; i < rdnComponents.length; i++)
     {
       buffer.append(',');
-      rdnComponents[i].toNormalizedReadableString(buffer);
+      buffer.append(rdnComponents[i].toNormalizedUrlSafeString());
     }
 
     return buffer.toString();
   }
 
   /**
-   * Returns the irreversible normalized byte string representation of a DN,
-   * suitable for equality and comparisons, and providing a natural hierarchical
-   * ordering, but not usable as a valid DN nor reversible to a valid DN.
+   * Retrieves a normalized byte string representation of this DN.
    * <p>
-   * This representation should be used only when a byte string representation
-   * is needed and when no reversibility to a valid DN is needed. Always consider
-   * using a {@code CompactDn} as an alternative.
+   * This representation is suitable for equality and comparisons, and for providing a
+   * natural hierarchical ordering.
+   * However, it is not a valid DN and can't be reverted to a valid DN.
    *
-   * @return The normalized byte string representation of the provided DN, not
-   *         usable as a valid DN
+   * You should consider using a {@code CompactDn} as an alternative.
+   *
+   * @return  The normalized string representation of this DN.
    */
-  public ByteString toIrreversibleNormalizedByteString()
+  public ByteString toNormalizedByteString()
   {
     if (normalizedDN == null)
     {
@@ -2751,9 +2714,8 @@
   }
 
   /**
-   * Compares this DN with the provided DN based on a natural order. This order
-   * will be first hierarchical (ancestors will come before descendants) and
-   * then alphabetical by attribute name(s) and value(s).
+   * Compares this DN with the provided DN based on a natural order, as defined by
+   * the toNormalizedByteString() method.
    *
    * @param other
    *          The DN against which to compare this DN.
@@ -2764,47 +2726,7 @@
   @Override
   public int compareTo(DN other)
   {
-    if (isRootDN())
-    {
-      /** root DN always come first. */
-      return other.isRootDN() ? 0 : -1;
-    }
-
-    if (other.isRootDN())
-    {
-      // this comes after other.
-      return 1;
-    }
-
-    int size1 = numComponents - 1;
-    int size2 = other.numComponents - 1;
-    while (size1 >= 0 && size2 >= 0)
-    {
-      RDN rdn1 = getRDN(size1);
-      RDN rdn2 = other.getRDN(size2);
-      size1--;
-      size2--;
-      int result = rdn1.compareTo(rdn2);
-      if (result > 0)
-      {
-        return 1;
-      }
-      else if (result < 0)
-      {
-        return -1;
-      }
-    }
-
-    // Check remaining sizes
-    if (size1 > size2)
-    {
-      return 1;
-    }
-    else if (size1 < size2)
-    {
-      return -1;
-    }
-    return 0;
+    return toNormalizedByteString().compareTo(other.toNormalizedByteString());
   }
 }
 
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/RDN.java b/opendj-server-legacy/src/main/java/org/opends/server/types/RDN.java
index 2a32000..f760861 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/RDN.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/RDN.java
@@ -41,6 +41,7 @@
 import org.forgerock.opendj.ldap.DecodeException;
 import org.forgerock.opendj.ldap.ResultCode;
 import org.forgerock.opendj.ldap.schema.MatchingRule;
+import org.forgerock.util.Reject;
 import org.opends.server.core.DirectoryServer;
 
 import static org.opends.messages.CoreMessages.*;
@@ -67,15 +68,6 @@
   /** The set of values for the elements in this RDN. */
   private ByteString[] attributeValues;
 
-  /** The number of values for this RDN. */
-  private int numValues;
-
-  /** The string representation of the normalized form of this RDN. */
-  private String normalizedRDN;
-
-  /** The string representation of this RDN. */
-  private String rdnString;
-
   /** The set of user-provided names for the attributes in this RDN. */
   private String[] attributeNames;
 
@@ -89,16 +81,13 @@
    * @param  attributeValue  The value for this RDN.  It must not be
    *                         {@code null}.
    */
-  public RDN(AttributeType attributeType,
-             ByteString attributeValue)
+  @SuppressWarnings("unchecked")
+  public RDN(AttributeType attributeType, ByteString attributeValue)
   {
+    Reject.ifNull(attributeType, attributeValue);
     attributeTypes  = new AttributeType[] { attributeType };
     attributeNames  = new String[] { attributeType.getPrimaryName() };
     attributeValues = new ByteString[] { attributeValue };
-
-    numValues     = 1;
-    rdnString     = null;
-    normalizedRDN = null;
   }
 
 
@@ -113,16 +102,13 @@
    * @param  attributeValue  The value for this RDN.  It must not be
    *                         {@code null}.
    */
-  public RDN(AttributeType attributeType, String attributeName,
-             ByteString attributeValue)
+  @SuppressWarnings("unchecked")
+  public RDN(AttributeType attributeType, String attributeName, ByteString attributeValue)
   {
+    Reject.ifNull(attributeType, attributeName, attributeValue);
     attributeTypes  = new AttributeType[] { attributeType };
     attributeNames  = new String[] { attributeName };
     attributeValues = new ByteString[] { attributeValue };
-
-    numValues     = 1;
-    rdnString     = null;
-    normalizedRDN = null;
   }
 
 
@@ -141,10 +127,18 @@
    *                          have the same number of elements as the
    *                          {@code attributeTypes} argument.
    */
+  @SuppressWarnings("unchecked")
   public RDN(List<AttributeType> attributeTypes,
              List<String> attributeNames,
              List<ByteString> attributeValues)
   {
+    Reject.ifNull(attributeTypes, attributeNames, attributeValues);
+    Reject.ifTrue(attributeTypes.isEmpty(), "attributeTypes must not be empty");
+    Reject.ifFalse(attributeNames.size() == attributeTypes.size(),
+            "attributeNames must have the same number of elements than attributeTypes");
+    Reject.ifFalse(attributeValues.size() == attributeTypes.size(),
+            "attributeValues must have the same number of elements than attributeTypes");
+
     this.attributeTypes  = new AttributeType[attributeTypes.size()];
     this.attributeNames  = new String[attributeNames.size()];
     this.attributeValues = new ByteString[attributeValues.size()];
@@ -152,10 +146,6 @@
     attributeTypes.toArray(this.attributeTypes);
     attributeNames.toArray(this.attributeNames);
     attributeValues.toArray(this.attributeValues);
-
-    numValues     = attributeTypes.size();
-    rdnString     = null;
-    normalizedRDN = null;
   }
 
 
@@ -174,16 +164,19 @@
    *                          have the same number of elements as the
    *                          {@code attributeTypes} argument.
    */
-  public RDN(AttributeType[] attributeTypes, String[] attributeNames,
-             ByteString[] attributeValues)
+  @SuppressWarnings("unchecked")
+  public RDN(AttributeType[] attributeTypes, String[] attributeNames, ByteString[] attributeValues)
   {
-    this.numValues       = attributeTypes.length;
-    this.attributeTypes  = attributeTypes;
-    this.attributeNames  = attributeNames;
-    this.attributeValues = attributeValues;
+    Reject.ifNull(attributeTypes, attributeNames, attributeValues);
+    Reject.ifFalse(attributeTypes.length > 0, "attributeTypes must not be empty");
+    Reject.ifFalse(attributeNames.length == attributeTypes.length,
+        "attributeNames must have the same number of elements than attributeTypes");
+    Reject.ifFalse(attributeValues.length == attributeTypes.length,
+        "attributeValues must have the same number of elements than attributeTypes");
 
-    rdnString     = null;
-    normalizedRDN = null;
+    this.attributeTypes = attributeTypes;
+    this.attributeNames = attributeNames;
+    this.attributeValues = attributeValues;
   }
 
 
@@ -214,7 +207,7 @@
    */
   public int getNumValues()
   {
-    return numValues;
+    return attributeTypes.length;
   }
 
 
@@ -322,7 +315,7 @@
    */
   public ByteString getAttributeValue(AttributeType attributeType)
   {
-    for (int i=0; i < numValues; i++)
+    for (int i=0; i < attributeTypes.length; i++)
     {
       if (attributeTypes[i].equals(attributeType))
       {
@@ -360,7 +353,7 @@
    */
   public boolean isMultiValued()
   {
-    return numValues > 1;
+    return attributeTypes.length > 1;
   }
 
 
@@ -378,7 +371,7 @@
    */
   public boolean hasValue(AttributeType type, ByteString value)
   {
-    for (int i=0; i < numValues; i++)
+    for (int i=0; i < attributeTypes.length; i++)
     {
       if (attributeTypes[i].equals(type) &&
           attributeValues[i].equals(value))
@@ -406,6 +399,7 @@
    */
   boolean addValue(AttributeType type, String name, ByteString value)
   {
+    int numValues = attributeTypes.length;
     for (int i=0; i < numValues; i++)
     {
       if (attributeTypes[i].equals(type) &&
@@ -414,9 +408,7 @@
         return false;
       }
     }
-
     numValues++;
-
     AttributeType[] newTypes = new AttributeType[numValues];
     System.arraycopy(attributeTypes, 0, newTypes, 0, attributeTypes.length);
     newTypes[attributeTypes.length] = type;
@@ -432,9 +424,6 @@
     newValues[attributeValues.length] = value;
     attributeValues = newValues;
 
-    rdnString     = null;
-    normalizedRDN = null;
-
     return true;
   }
 
@@ -873,6 +862,7 @@
    */
   public RDN duplicate()
   {
+    int numValues = attributeTypes.length;
     AttributeType[] newTypes = new AttributeType[numValues];
     System.arraycopy(attributeTypes, 0, newTypes, 0, numValues);
 
@@ -908,7 +898,8 @@
     }
     if (o instanceof RDN)
     {
-      return compareTo((RDN) o) == 0;
+      RDN otherRDN = (RDN) o;
+      return toNormalizedByteString().equals(otherRDN.toNormalizedByteString());
     }
     return false;
   }
@@ -922,14 +913,7 @@
   @Override
   public int hashCode()
   {
-    // Avoid an algorithm that requires the AVAs to be sorted.
-    int hash = 0;
-
-    for (int i = 0; i < attributeNames.length; i++)
-    {
-      hash += attributeTypes[i].hashCode() * 31 + getEqualityNormalizedValue(i).hashCode();
-    }
-    return hash;
+    return toNormalizedByteString().hashCode();
   }
 
   /** Returns normalized value for attribute at provided position. */
@@ -962,29 +946,19 @@
   @Override
   public String toString()
   {
-    if (rdnString == null)
-    {
-      StringBuilder buffer = new StringBuilder();
-
-      buffer.append(attributeNames[0]);
-      buffer.append("=");
-      buffer.append(getDNValue(attributeValues[0]));
-
-      for (int i=1; i < numValues; i++)
-      {
-        buffer.append("+");
-        buffer.append(attributeNames[i]);
+        StringBuilder buffer = new StringBuilder();
+        buffer.append(attributeNames[0]);
         buffer.append("=");
-        buffer.append(getDNValue(attributeValues[i]));
-      }
-
-      rdnString = buffer.toString();
-    }
-    return rdnString;
+        buffer.append(getDNValue(attributeValues[0]));
+        for (int i = 1; i < attributeTypes.length; i++) {
+            buffer.append("+");
+            buffer.append(attributeNames[i]);
+            buffer.append("=");
+            buffer.append(getDNValue(attributeValues[i]));
+        }
+        return buffer.toString();
   }
 
-
-
   /**
    * Appends a string representation of this RDN to the provided
    * buffer.
@@ -997,43 +971,21 @@
     buffer.append(this);
   }
 
-
-
-  /**
-   * Retrieves a normalized string representation of this RDN.
-   *
-   * @return  A normalized string representation of this RDN.
-   */
-  public String toNormalizedString()
+ /**
+  * Retrieves a normalized string representation of this RDN.
+  * <p>
+  *
+  * This representation is safe to use in an URL or in a file name.
+  * However, it is not a valid RDN and can't be reverted to a valid RDN.
+  *
+  * @return  The normalized string representation of this RDN.
+  */
+  String toNormalizedUrlSafeString()
   {
-    if (normalizedRDN == null)
-    {
-      toNormalizedReadableString(new StringBuilder());
-    }
-    return normalizedRDN;
-  }
-
-
-
-  /**
-   * Appends a normalized string representation of this RDN to the
-   * provided buffer.
-   *
-   * @param  buffer  The buffer to which to append the information.
-   */
-  void toNormalizedReadableString(StringBuilder buffer)
-  {
-    if (normalizedRDN != null)
-    {
-      buffer.append(normalizedRDN);
-      return;
-    }
-
-    boolean providedBufferIsEmpty = (buffer.length() == 0);
-
+    final StringBuilder buffer = new StringBuilder();
     if (attributeNames.length == 1)
     {
-      normalizeAVAToReadableString(0, buffer);
+      normalizeAVAToUrlSafeString(0, buffer);
     }
     else
     {
@@ -1042,7 +994,7 @@
       for (int i=0; i < attributeNames.length; i++)
       {
         StringBuilder builder = new StringBuilder();
-        normalizeAVAToReadableString(i, builder);
+        normalizeAVAToUrlSafeString(i, builder);
         avaStrings.add(builder.toString());
       }
 
@@ -1054,15 +1006,19 @@
         buffer.append(iterator.next());
       }
     }
+    return buffer.toString();
+  }
 
-    if (providedBufferIsEmpty)
-    {
-      normalizedRDN = buffer.toString();
-    }
+  private ByteString toNormalizedByteString() {
+    return toNormalizedByteString(new ByteStringBuilder()).toByteString();
   }
 
   /**
    * Adds a normalized byte string representation of this RDN to the provided builder.
+   * <p>
+   * The representation is suitable for equality and comparisons, and for providing a
+   * natural hierarchical ordering.
+   * However, it is not a valid RDN and can't be reverted to a valid RDN.
    *
    * @param builder
    *           Builder to add this representation to.
@@ -1096,16 +1052,16 @@
   }
 
   /**
-   * Adds a normalized byte string representation of the AVA corresponding to provided position
-   * in this RDN to the provided builder.
+   * Adds a normalized byte string representation of the AVA corresponding
+   * to provided position in this RDN to the provided builder.
    *
    * @param position
-   *           Position of AVA in this RDN
+   *           Position of AVA in this RDN.
    * @param builder
    *           Builder to add the representation to.
    * @return the builder
    */
-  ByteStringBuilder normalizeAVAToByteString(int position, final ByteStringBuilder builder)
+  private ByteStringBuilder normalizeAVAToByteString(int position, final ByteStringBuilder builder)
   {
     builder.append(attributeTypes[position].getNormalizedPrimaryNameOrOID());
     builder.append("=");
@@ -1145,17 +1101,14 @@
 
   private boolean needEscaping(final ByteString value)
   {
-    boolean needEscaping = false;
     for (int i = 0; i < value.length(); i++)
     {
-      final byte b = value.byteAt(i);
-      if (isByteToEscape(b))
+      if (isByteToEscape(value.byteAt(i)))
       {
-        needEscaping = true;
-        break;
+        return true;
       }
     }
-    return needEscaping;
+    return false;
   }
 
   private boolean isByteToEscape(final byte b)
@@ -1173,7 +1126,7 @@
    * @param  builder  The buffer to which to append the information.
    * @return the builder
    */
-  private StringBuilder normalizeAVAToReadableString(int position, StringBuilder builder)
+  private StringBuilder normalizeAVAToUrlSafeString(int position, StringBuilder builder)
   {
       builder.append(attributeTypes[position].getNormalizedPrimaryNameOrOID());
       builder.append('=');
@@ -1219,8 +1172,8 @@
   }
 
   /**
-   * Compares this RDN with the provided RDN based on an alphabetic
-   * comparison of the attribute names and values.
+   * Compares this RDN with the provided RDN based on natural ordering defined
+   * by the toNormalizedByteString() method.
    *
    * @param  rdn  The RDN against which to compare this RDN.
    *
@@ -1232,122 +1185,7 @@
   @Override
   public int compareTo(RDN rdn)
   {
-    if (attributeTypes.length == 1 && rdn.attributeTypes.length == 1)
-    {
-      // fast path
-      AttributeType type = attributeTypes[0];
-      if (type.equals(rdn.attributeTypes[0]))
-      {
-        return compare(attributeValues[0], rdn.attributeValues[0], type);
-      }
-      else
-      {
-        String name1 = type.getNormalizedPrimaryNameOrOID();
-        String name2 = rdn.attributeTypes[0].getNormalizedPrimaryNameOrOID();
-        return name1.compareTo(name2);
-      }
-    }
-
-    TreeMap<String,AttributeType> typeMap1 =
-         new TreeMap<String,AttributeType>();
-    TreeMap<String, ByteString> valueMap1 = new TreeMap<String, ByteString>();
-    for (int i=0; i < attributeTypes.length; i++)
-    {
-      String lowerName = attributeTypes[i].getNormalizedPrimaryNameOrOID();
-      typeMap1.put(lowerName, attributeTypes[i]);
-      valueMap1.put(lowerName, attributeValues[i]);
-    }
-
-    TreeMap<String,AttributeType> typeMap2 =
-         new TreeMap<String,AttributeType>();
-    TreeMap<String, ByteString> valueMap2 = new TreeMap<String, ByteString>();
-    for (int i=0; i < rdn.attributeTypes.length; i++)
-    {
-      String lowerName = rdn.attributeTypes[i].getNormalizedPrimaryNameOrOID();
-      typeMap2.put(lowerName, rdn.attributeTypes[i]);
-      valueMap2.put(lowerName, rdn.attributeValues[i]);
-    }
-
-    Iterator<String> iterator1 = valueMap1.keySet().iterator();
-    Iterator<String> iterator2 = valueMap2.keySet().iterator();
-    String           name1     = iterator1.next();
-    String           name2     = iterator2.next();
-    AttributeType    type1     = typeMap1.get(name1);
-    AttributeType    type2     = typeMap2.get(name2);
-    ByteString       value1    = valueMap1.get(name1);
-    ByteString       value2    = valueMap2.get(name2);
-
-    while (true)
-    {
-      if (!type1.equals(type2))
-      {
-        // there is a difference => return result
-        return name1.compareTo(name2);
-      }
-
-      final int valueComparison = compare(value1, value2, type1);
-      if (valueComparison != 0)
-      {
-        // we found a difference => return result
-        return valueComparison;
-      }
-
-      if (!iterator1.hasNext())
-      {
-        if (iterator2.hasNext())
-        {
-          return -1;
-        }
-        return 0;
-      }
-      if (!iterator2.hasNext())
-      {
-        return 1;
-      }
-
-      name1  = iterator1.next();
-      name2  = iterator2.next();
-      type1  = typeMap1.get(name1);
-      type2  = typeMap2.get(name2);
-      value1 = valueMap1.get(name1);
-      value2 = valueMap2.get(name2);
-    }
+    return toNormalizedByteString().compareTo(rdn.toNormalizedByteString());
   }
 
-  /**
-   * Compares two attribute values by using the provided MatchingRule if
-   * it is not null, or relying on alphabetical ordering otherwise.
-   *
-   * @param value1
-   *          the first attribute value to compare
-   * @param value2
-   *          the second attribute value to compare
-   * @param type
-   *          the type whose MatchingRule is to be used for comparison
-   * @return A negative integer if this value1 should come before the value2, a
-   *         positive integer if value1 should come after value2, or zero if
-   *         there is no difference with regard to ordering.
-   */
-  private int compare(ByteString value1, ByteString value2, AttributeType type)
-  {
-    final MatchingRule orderingRule = type.getOrderingMatchingRule();
-    final MatchingRule rule = orderingRule != null ? orderingRule : type.getEqualityMatchingRule();
-
-    ByteString val1 = value1;
-    ByteString val2 = value2;
-    if (rule != null)
-    {
-      try
-      {
-        val1 = rule.normalizeAttributeValue(val1);
-        val2 = rule.normalizeAttributeValue(val2);
-        return val1.compareTo(val2);
-      }
-      catch (DecodeException e)
-      {
-        logger.traceException(e);
-      }
-    }
-    return val1.toString().compareTo(val2.toString());
-  }
 }
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestImportJob.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestImportJob.java
index 958d3ae..ee5fc86 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestImportJob.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestImportJob.java
@@ -242,7 +242,6 @@
 
     tempDir = TestCaseUtils.createTemporaryDirectory("jebimporttest");
     homeDirName = tempDir.getAbsolutePath();
-    System.out.println(homeDirName);
 
     EnvManager.createHomeDir(homeDirName);
 
@@ -289,10 +288,10 @@
   public void cleanUp() throws Exception
   {
     TestCaseUtils.disableBackend(backendID);
+    TestCaseUtils.deleteDirectory(tempDir);
   }
 
 
-
   @Test(enabled = true)
   public void testImportAll() throws Exception
   {
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestJebFormat.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestJebFormat.java
index df6a02d..7f704b1 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestJebFormat.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/jeb/TestJebFormat.java
@@ -431,7 +431,7 @@
    */
   @Test
   public void testEntryToAndFromDatabase() throws Exception {
-    ensureTheServerIsUpAndRunning();
+    ensureServerIsUpAndRunning();
 
     // Convert the test LDIF string to a byte array
     byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString);
@@ -502,7 +502,7 @@
    */
   @Test
   public void testEntryToAndFromDatabaseV1() throws Exception {
-    ensureTheServerIsUpAndRunning();
+    ensureServerIsUpAndRunning();
 
     // Convert the test LDIF string to a byte array
     byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString);
@@ -551,7 +551,7 @@
   @Test(dataProvider = "encodeConfigs")
   public void testEntryToAndFromDatabaseV2(EntryEncodeConfig config)
          throws Exception {
-    ensureTheServerIsUpAndRunning();
+    ensureServerIsUpAndRunning();
 
     // Convert the test LDIF string to a byte array
     byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString);
@@ -582,7 +582,7 @@
   @Test(dataProvider = "encodeConfigs")
   public void testEntryToAndFromDatabaseV3(EntryEncodeConfig config)
          throws Exception {
-    ensureTheServerIsUpAndRunning();
+    ensureServerIsUpAndRunning();
 
     // Convert the test LDIF string to a byte array
     byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString);
@@ -613,19 +613,18 @@
       { "dc=example", 0 },
       { "dc=example,dc=com", 7 },
       { "dc=example,dc=com\\,org", 11 },
-
     };
   }
 
   @Test(dataProvider="findDnKeyParentData")
   public void testFindDnKeyParent(String dn, int expectedLength) throws Exception
   {
-    ensureTheServerIsUpAndRunning();
+    ensureServerIsUpAndRunning();
     byte[] dnKey = dnToDNKey(DN.valueOf(dn), 0);
     assertThat(findDNKeyParent(dnKey)).isEqualTo(expectedLength);
   }
 
-  private void ensureTheServerIsUpAndRunning() throws Exception
+  private void ensureServerIsUpAndRunning() throws Exception
   {
     TestCaseUtils.startServer();
   }
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/TestJebFormat.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/TestJebFormat.java
index b7b9f4d..052ba7e 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/TestJebFormat.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/TestJebFormat.java
@@ -357,7 +357,7 @@
    */
   @Test
   public void testEntryToAndFromDatabase() throws Exception {
-    ensureTheServerIsUpAndRunning();
+    ensureServerIsUpAndRunning();
 
     // Convert the test LDIF string to a byte array
     byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString);
@@ -428,7 +428,7 @@
    */
   @Test
   public void testEntryToAndFromDatabaseV1() throws Exception {
-    ensureTheServerIsUpAndRunning();
+    ensureServerIsUpAndRunning();
 
     // Convert the test LDIF string to a byte array
     byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString);
@@ -477,7 +477,7 @@
   @Test(dataProvider = "encodeConfigs")
   public void testEntryToAndFromDatabaseV2(EntryEncodeConfig config)
          throws Exception {
-    ensureTheServerIsUpAndRunning();
+    ensureServerIsUpAndRunning();
 
     // Convert the test LDIF string to a byte array
     byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString);
@@ -508,7 +508,7 @@
   @Test(dataProvider = "encodeConfigs")
   public void testEntryToAndFromDatabaseV3(EntryEncodeConfig config)
          throws Exception {
-    ensureTheServerIsUpAndRunning();
+    ensureServerIsUpAndRunning();
 
     // Convert the test LDIF string to a byte array
     byte[] originalLDIFBytes = StaticUtils.getBytes(ldifString);
@@ -539,19 +539,18 @@
       { "dc=example", 0 },
       { "dc=example,dc=com", 7 },
       { "dc=example,dc=com\\,org", 11 },
-
     };
   }
 
   @Test(dataProvider="findDnKeyParentData")
   public void testFindDnKeyParent(String dn, int expectedLength) throws Exception
   {
-    ensureTheServerIsUpAndRunning();
+    ensureServerIsUpAndRunning();
     ByteString dnKey = JebFormat.dnToDNKey(DN.valueOf(dn), 0);
     assertThat(JebFormat.findDNKeyParent(dnKey)).isEqualTo(expectedLength);
   }
 
-  private void ensureTheServerIsUpAndRunning() throws Exception
+  private void ensureServerIsUpAndRunning() throws Exception
   {
     TestCaseUtils.startServer();
   }
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/core/BackendConfigManagerTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/core/BackendConfigManagerTestCase.java
index 82cbab3..39ab76c 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/core/BackendConfigManagerTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/core/BackendConfigManagerTestCase.java
@@ -587,7 +587,7 @@
         buffer.append("___");
       }
 
-      String ndn = dn.toIrreversibleReadableString();
+      String ndn = dn.toNormalizedUrlSafeString();
       for (int i=0; i < ndn.length(); i++)
       {
         char c = ndn.charAt(i);
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/extensions/EntryUUIDVirtualAttributeProviderTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/extensions/EntryUUIDVirtualAttributeProviderTestCase.java
index 813a5fa..8948cae 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/extensions/EntryUUIDVirtualAttributeProviderTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/extensions/EntryUUIDVirtualAttributeProviderTestCase.java
@@ -116,7 +116,7 @@
   public void testGetEntry(DN entryDN)
          throws Exception
   {
-    String uuidString = UUID.nameUUIDFromBytes(entryDN.toIrreversibleNormalizedByteString().toByteArray()).toString();
+    String uuidString = UUID.nameUUIDFromBytes(entryDN.toNormalizedByteString().toByteArray()).toString();
 
     Entry e = DirectoryServer.getEntry(entryDN);
     assertNotNull(e);
@@ -293,7 +293,7 @@
   public void testSearchEntryUUIDAttrInMatchingFilter(DN entryDN)
          throws Exception
   {
-    String uuidString = UUID.nameUUIDFromBytes(entryDN.toIrreversibleNormalizedByteString().toByteArray()).toString();
+    String uuidString = UUID.nameUUIDFromBytes(entryDN.toNormalizedByteString().toByteArray()).toString();
 
     final SearchRequest request = newSearchRequest(entryDN, SearchScope.BASE_OBJECT, "(entryUUID=" + uuidString + ")")
         .addAttribute("entryuuid");
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/TestBindResponseProtocolOp.java b/opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/TestBindResponseProtocolOp.java
index 9802b43..e22ce0c 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/TestBindResponseProtocolOp.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/TestBindResponseProtocolOp.java
@@ -118,8 +118,7 @@
       assertTrue(protocolOp instanceof BindResponseProtocolOp);
       BindResponseProtocolOp bindResponse = (BindResponseProtocolOp)protocolOp;
       assertTrue(bindResponse.getResultCode() == okCode.intValue());
-      assertTrue(bindResponse.getMatchedDN().toIrreversibleNormalizedByteString()
-          .equals(responseDn.toIrreversibleNormalizedByteString()));
+      assertTrue(bindResponse.getMatchedDN().equals(responseDn));
       assertTrue(bindResponse.getErrorMessage().toString().equals(message.toString()));
       assertNull(bindResponse.getReferralURLs());
       assertNull(bindResponse.getServerSASLCredentials());
@@ -166,8 +165,7 @@
       assertTrue(protocolOp instanceof BindResponseProtocolOp);
       BindResponseProtocolOp bindResponse = (BindResponseProtocolOp)protocolOp;
       assertTrue(bindResponse.getResultCode() == okCode.intValue());
-      assertTrue(bindResponse.getMatchedDN().toIrreversibleNormalizedByteString().equals(
-          responseDn.toIrreversibleNormalizedByteString()));
+      assertTrue(bindResponse.getMatchedDN().equals(responseDn));
       assertTrue(bindResponse.getErrorMessage().toString().equals(message.toString()));
       assertNull(bindResponse.getReferralURLs());
       assertNull(bindResponse.getServerSASLCredentials());
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/TestDeleteResponseProtocolOp.java b/opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/TestDeleteResponseProtocolOp.java
index 48371bc..c9094c4 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/TestDeleteResponseProtocolOp.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/TestDeleteResponseProtocolOp.java
@@ -342,6 +342,7 @@
         + "errorMessage=" + resultMsg + ", matchedDN=" + dn
         + ", " + "referralURLs={");
     join(key, referralURLs);
+    key.append("})");
     assertEquals(buffer.toString(), key.toString());
   }
 
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/types/TestDN.java b/opendj-server-legacy/src/test/java/org/opends/server/types/TestDN.java
index b866a04..e9b5cbd 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/types/TestDN.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/types/TestDN.java
@@ -51,8 +51,8 @@
    *
    * @return The array of test DN strings.
    */
-  @DataProvider(name = "testDNs")
-  public Object[][] createData() {
+  @DataProvider
+  public Object[][] testDNs() {
     return new Object[][] {
          // raw dn, irreversible normalized string representation, toString representation
         { "", "", "" },
@@ -136,8 +136,8 @@
    *
    * @return The array of illegal test DN strings.
    */
-  @DataProvider(name = "illegalDNs")
-  public Object[][] createIllegalData() {
+  @DataProvider
+  public Object[][] illegalDNs() {
     return new Object[][] { { "manager" }, { "manager " }, { "=Jim" },
         { " =Jim" }, { "= Jim" }, { " = Jim" }, { "cn+Jim" }, { "cn + Jim" },
         { "cn=Jim+" }, { "cn=Jim+manager" }, { "cn=Jim+manager " },
@@ -304,8 +304,7 @@
   public void testValueOf(String rawDN, String normDN, String unused) throws Exception {
     DN dn = DN.valueOf(rawDN);
     StringBuilder normalizedDnString = new StringBuilder(normDN);
-    //Platform.normalize(normalizedDnString);
-    assertEquals(dn.toIrreversibleReadableString(), normalizedDnString.toString());
+    assertEquals(dn.toNormalizedUrlSafeString(), normalizedDnString.toString());
   }
 
 
@@ -327,9 +326,8 @@
   public void testDecodeByteString(String rawDN, String normDN, String unused) throws Exception {
     DN dn = DN.decode(ByteString.valueOf(rawDN));
     StringBuilder normalizedDNString = new StringBuilder(normDN);
-    //Platform.normalize(normalizedDNString);
 
-    assertEquals(dn.toIrreversibleReadableString(), normalizedDNString.toString());
+    assertEquals(dn.toNormalizedUrlSafeString(), normalizedDNString.toString());
   }
 
 
@@ -364,10 +362,10 @@
   public void testToNormalizedString() throws Exception {
     DN dn = DN.valueOf("dc=example,dc=com");
 
-    assertEquals(dn.toIrreversibleNormalizedByteString(),
+    assertEquals(dn.toNormalizedByteString(),
         new ByteStringBuilder().append("dc=com").append(DN.NORMALIZED_RDN_SEPARATOR).append("dc=example")
         .toByteString());
-    assertEquals(dn.toIrreversibleReadableString(), "dc=example,dc=com");
+    assertEquals(dn.toNormalizedUrlSafeString(), "dc=example,dc=com");
   }
 
 
@@ -612,8 +610,8 @@
 
     assertEquals(p.size(), 3);
 
-    assertEquals(p.compareTo(c), -1);
-    assertEquals(c.compareTo(p), 1);
+    assertTrue(p.compareTo(c) < 0);
+    assertTrue(c.compareTo(p) > 0);
 
     assertTrue(p.isAncestorOf(c));
     assertFalse(c.isAncestorOf(p));
@@ -624,7 +622,7 @@
     assertEquals(p, e);
     assertEquals(p.hashCode(), e.hashCode());
 
-    assertEquals(p.toIrreversibleReadableString(), e.toIrreversibleReadableString());
+    assertEquals(p.toNormalizedUrlSafeString(), e.toNormalizedUrlSafeString());
     assertEquals(p.toString(), e.toString());
 
     assertEquals(p.rdn(), RDN.decode("dc=bar"));
@@ -826,8 +824,8 @@
 
     assertEquals(c.size(), 4);
 
-    assertEquals(c.compareTo(p), 1);
-    assertEquals(p.compareTo(c), -1);
+    assertTrue(c.compareTo(p) > 0);
+    assertTrue(p.compareTo(c) < 0);
 
     assertTrue(p.isAncestorOf(c));
     assertFalse(c.isAncestorOf(p));
@@ -838,7 +836,7 @@
     assertEquals(c, e);
     assertEquals(c.hashCode(), e.hashCode());
 
-    assertEquals(c.toIrreversibleReadableString(), e.toIrreversibleReadableString());
+    assertEquals(c.toNormalizedUrlSafeString(), e.toNormalizedUrlSafeString());
     assertEquals(c.toString(), e.toString());
 
     assertEquals(c.rdn(), RDN.decode("dc=foo"));
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/types/TestRDN.java b/opendj-server-legacy/src/test/java/org/opends/server/types/TestRDN.java
index 69c9e6d..988fd9a 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/types/TestRDN.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/types/TestRDN.java
@@ -248,7 +248,7 @@
     StringBuilder buffer = new StringBuilder();
     buffer.append(normRDN);
     Platform.normalize(buffer);
-    assertEquals(rdn.toNormalizedString(), buffer.toString());
+    assertEquals(rdn.toNormalizedUrlSafeString(), buffer.toString());
   }
 
 
@@ -317,10 +317,9 @@
    * @throws Exception
    *           If the test failed unexpectedly.
    */
-  @Test(expectedExceptions = IndexOutOfBoundsException.class)
+  @Test(expectedExceptions = IllegalArgumentException.class)
   public void testGetAttributeNameException() throws Exception {
     RDN rdn = new RDN(new AttributeType[0], new String[0], new ByteString[0]);
-    rdn.getAttributeName(1);
   }
 
 
@@ -352,14 +351,13 @@
    * @throws Exception
    *           If the test failed unexpectedly.
    */
-  @Test(expectedExceptions = IndexOutOfBoundsException.class)
+  @SuppressWarnings("unused")
+  @Test(expectedExceptions = IllegalArgumentException.class)
   public void testGetAttributeTypeException() throws Exception {
-    RDN rdn = new RDN(new AttributeType[0], new String[0], new ByteString[0]);
-    rdn.getAttributeType(1);
+    new RDN(new AttributeType[0], new String[0], new ByteString[0]);
   }
 
 
-
   /**
    * Test getAttributeValue.
    *
@@ -387,10 +385,10 @@
    * @throws Exception
    *           If the test failed unexpectedly.
    */
-  @Test(expectedExceptions = IndexOutOfBoundsException.class)
+  @SuppressWarnings("unused")
+  @Test(expectedExceptions = IllegalArgumentException.class)
   public void testGetAttributeValueException() throws Exception {
-    RDN rdn = new RDN(new AttributeType[0], new String[0], new ByteString[0]);
-    rdn.getAttributeValue(1);
+    new RDN(new AttributeType[0], new String[0], new ByteString[0]);
   }
 
 

--
Gitblit v1.10.0