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

Matthew Swift
19.25.2012 a9c66cf2e6902b49f691ae06d74ab4525509e6fa
Fix OPENDJ-623: Import and rebuild should not call System.exit()

It's hard to know what do in some cases: the best we can do is log something and rethrow as a runtime exception. We certainly should not be touching the application wide default uncaught exception handler.
2 files modified
37 ■■■■■ changed files
opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java 33 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/backends/jeb/importLDIF/IndexInputBuffer.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
@@ -30,13 +30,11 @@
import static org.opends.messages.JebMessages.*;
import static org.opends.server.loggers.ErrorLogger.logError;
import static org.opends.server.loggers.debug.DebugLogger.debugEnabled;
import static org.opends.server.loggers.debug.DebugLogger.getTracer;
import static org.opends.server.util.DynamicConstants.BUILD_ID;
import static org.opends.server.util.DynamicConstants.REVISION_NUMBER;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.getFileForPath;
import static org.opends.server.util.StaticUtils.stackTraceToString;
import java.io.*;
import java.nio.ByteBuffer;
@@ -2158,8 +2156,6 @@
    @Override
    public Void call() throws Exception
    {
      Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler());
      ByteBuffer key = null;
      ImportIDSet insertIDSet = null;
      ImportIDSet deleteIDSet = null;
@@ -2270,15 +2266,11 @@
        Message message = ERR_JEB_IMPORT_LDIF_INDEX_WRITE_DB_ERR.get(
            indexMgr.getBufferFileName(), e.getMessage());
        logError(message);
        e.printStackTrace();
        throw e;
      }
      finally
      {
        endWriteTask();
        // Clear the default exception handler.
        Thread.setDefaultUncaughtExceptionHandler(null);
      }
      return null;
    }
@@ -5044,31 +5036,6 @@
    }
  }
  /**
   * Uncaught exception handler. Try and catch any uncaught exceptions, log
   * them and print a stack trace.
   */
  private class DefaultExceptionHandler
      implements Thread.UncaughtExceptionHandler {
    /**
     * {@inheritDoc}
     */
    @Override
    public void uncaughtException(Thread t, Throwable e) {
      if (debugEnabled())
      {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
      }
      Message message =
        ERR_JEB_IMPORT_UNCAUGHT_EXCEPTION.get(stackTraceToString(e));
      logError(message);
      System.exit(1);
    }
  }
  /**
   * {@inheritDoc}
   */
opends/src/server/org/opends/server/backends/jeb/importLDIF/IndexInputBuffer.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2010 Sun Microsystems, Inc.
 *      Portions copyright 2012 ForgeRock AS.
 */
package org.opends.server.backends.jeb.importLDIF;
@@ -196,8 +197,7 @@
        Message message = ERR_JEB_IMPORT_BUFFER_IO_ERROR.get(indexMgr
            .getBufferFileName());
        logError(message);
        ex.printStackTrace();
        System.exit(1);
        throw new RuntimeException(ex);
      }
    }
    return indexID;