mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Violette Roche-Montane
10.46.2013 75a710630a2d6271231a31eed5fa72fccfcb8723
CR-1816 OPENDJ-940 Import-ldif NPE if base entry contains invalid attribute values and skipDNValidation is set
- Removed NullPointerException message and it sends now a DirectoryException.
6 files modified
82 ■■■■ changed files
opendj-sdk/opends/src/messages/messages/jeb.properties 1 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/messages/messages/tools.properties 4 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/backends/jeb/BackendImpl.java 11 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java 36 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tasks/ImportTask.java 15 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tools/ImportLDIF.java 15 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/messages/messages/jeb.properties
@@ -453,3 +453,4 @@
 with %d total entries to process
NOTICE_JEB_REBUILD_CLEARDEGRADEDSTATE_FINAL_STATUS_232=Degraded state of \
index(es) %s has been cleared
SEVERE_ERR_PARENT_ENTRY_IS_MISSING_233=Parent entry is missing
opendj-sdk/opends/src/messages/messages/tools.properties
@@ -198,6 +198,10 @@
 trying to open the rejects file %s for writing:  %s
SEVERE_ERR_LDIFIMPORT_ERROR_DURING_IMPORT_96=An error occurred while \
 attempting to process the LDIF import:  %s
SEVERE_ERR_LDIFIMPORT_ERROR_CONSTRAINT_VIOLATION_97=One or more DN \
indexes could not be built due to invalid DNs or missing parent entries. \
Please re-import the data without the --skipDNValidation option in order \
to determine the exact cause
INFO_PROCESSING_OPERATION_104=Processing %s request for %s
INFO_OPERATION_FAILED_105=%s operation failed
INFO_OPERATION_SUCCESSFUL_106=%s operation successful for DN %s
opendj-sdk/opends/src/server/org/opends/server/backends/jeb/BackendImpl.java
@@ -1158,9 +1158,16 @@
      {
        TRACER.debugCaught(DebugLogLevel.ERROR, execEx);
      }
      if (execEx.getCause() instanceof DirectoryException)
      {
        throw ((DirectoryException) execEx.getCause());
      }
      else
      {
      Message message = ERR_EXECUTION_ERROR.get(execEx.getMessage());
      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
              message);
        throw new DirectoryException(
            DirectoryServer.getServerErrorResultCode(), message);
      }
    }
    catch (InterruptedException intEx)
    {
opendj-sdk/opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
@@ -2091,7 +2091,7 @@
     * {@inheritDoc}
     */
    @Override
    public Void call() throws Exception
    public Void call() throws Exception, DirectoryException
    {
      ByteBuffer key = null;
      ImportIDSet insertIDSet = null;
@@ -2214,7 +2214,7 @@
    }
    private void addToDB(ImportIDSet insertSet, ImportIDSet deleteSet,
        int indexID)
        int indexID) throws DirectoryException
    {
      if (!indexMgr.isDN2ID())
      {
@@ -2249,6 +2249,7 @@
    }
    private void addDN2ID(ImportIDSet record, Integer indexID)
        throws DirectoryException
    {
      DNState dnState;
      if (!dnStateMap.containsKey(indexID))
@@ -2430,9 +2431,11 @@
        return true;
      }
      private void id2child(EntryID childID)
      private void id2child(EntryID childID) throws DirectoryException
      {
        ImportIDSet idSet;
        if (parentID != null)
        {
        if (!id2childTree.containsKey(parentID.getDatabaseEntry().getData()))
        {
          idSet = new ImportIDSet(1, childLimit, childDoCount);
@@ -2448,6 +2451,12 @@
          flushMapToDB(id2childTree, entryContainer.getID2Children(), true);
        }
      }
        else
        {
          throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
              ERR_PARENT_ENTRY_IS_MISSING.get());
        }
      }
      private EntryID getParentID(ByteBuffer dn) throws DatabaseException
      {
@@ -2479,10 +2488,13 @@
        return nodeID;
      }
      private void id2SubTree(EntryID childID)
      private void id2SubTree(EntryID childID) throws DirectoryException
      {
        if (parentID != null)
      {
        ImportIDSet idSet;
        if (!id2subtreeTree.containsKey(parentID.getDatabaseEntry().getData()))
          if (!id2subtreeTree
              .containsKey(parentID.getDatabaseEntry().getData()))
        {
          idSet = new ImportIDSet(1, subTreeLimit, subTreeDoCount);
          id2subtreeTree.put(parentID.getDatabaseEntry().getData(), idSet);
@@ -2493,7 +2505,8 @@
        }
        idSet.addEntryID(childID);
        // TODO:
        //  Instead of doing this, we can just walk to parent cache if available
          // Instead of doing this,
          // we can just walk to parent cache if available
        for (ByteBuffer dn = getParent(parentDN); dn != null; dn =
            getParent(dn))
        {
@@ -2504,7 +2517,8 @@
            // Just ignore.
            break;
          }
          if (!id2subtreeTree.containsKey(nodeID.getDatabaseEntry().getData()))
            if (!id2subtreeTree
                .containsKey(nodeID.getDatabaseEntry().getData()))
          {
            idSet = new ImportIDSet(1, subTreeLimit, subTreeDoCount);
            id2subtreeTree.put(nodeID.getDatabaseEntry().getData(), idSet);
@@ -2520,8 +2534,14 @@
          flushMapToDB(id2subtreeTree, entryContainer.getID2Subtree(), true);
        }
      }
        else
        {
          throw new DirectoryException(ResultCode.CONSTRAINT_VIOLATION,
              ERR_PARENT_ENTRY_IS_MISSING.get());
        }
      }
      public void writeToDB()
      public void writeToDB() throws DirectoryException
      {
        entryContainer.getDN2ID().put(null, dnKey, dnValue);
        indexMgr.addTotDNCount(1);
opendj-sdk/opends/src/server/org/opends/server/tasks/ImportTask.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2013 ForgeRock AS
 */
package org.opends.server.tasks;
import org.opends.messages.Message;
@@ -1023,8 +1024,18 @@
        }
        DirectoryServer.notifyImportEnded(backend, importConfig, false);
        Message message =
            ERR_LDIFIMPORT_ERROR_DURING_IMPORT.get(de.getMessageObject());
        Message message = null;
        if (de.getResultCode() == ResultCode.CONSTRAINT_VIOLATION)
        {
          message =
              ERR_LDIFIMPORT_ERROR_DURING_IMPORT
                  .get(ERR_LDIFIMPORT_ERROR_CONSTRAINT_VIOLATION.get());
        }
        else
        {
          message = ERR_LDIFIMPORT_ERROR_DURING_IMPORT.get(
              de.getMessageObject());
        }
        logError(message);
        return TaskState.STOPPED_BY_ERROR;
      }
opendj-sdk/opends/src/server/org/opends/server/tools/ImportLDIF.java
@@ -72,6 +72,7 @@
import org.opends.server.types.LDIFImportResult;
import org.opends.server.types.NullOutputStream;
import org.opends.server.types.RawAttribute;
import org.opends.server.types.ResultCode;
import org.opends.server.types.SearchFilter;
import org.opends.server.util.BuildVersion;
import org.opends.server.util.args.ArgumentException;
@@ -1540,8 +1541,17 @@
    }
    catch (DirectoryException de)
    {
      Message message =
          ERR_LDIFIMPORT_ERROR_DURING_IMPORT.get(de.getMessageObject());
      Message message = null;
      if (de.getResultCode() == ResultCode.CONSTRAINT_VIOLATION)
      {
        message =
            ERR_LDIFIMPORT_ERROR_DURING_IMPORT
                .get(ERR_LDIFIMPORT_ERROR_CONSTRAINT_VIOLATION.get());
      }
      else
      {
        message = ERR_LDIFIMPORT_ERROR_DURING_IMPORT.get(de.getMessageObject());
      }
      logError(message);
      retCode = 1;
    }
@@ -1550,7 +1560,6 @@
      Message message =
          ERR_LDIFIMPORT_ERROR_DURING_IMPORT.get(getExceptionMessage(e));
      logError(message);
e.printStackTrace();
      retCode = 1;
    }