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

neil_a_wilson
21.28.2007 8213b81bb81d462f08ce9c429f3445f36b35fa16
Update the code to provide a convenience method for generating more
user-friendly error messages from exceptions. For exceptions generated within
the project, we'll just use the user-provided message and also display the
unique message ID. For null pointer exceptions, we'll display the fact that it
was a null pointer exception and the source file and line number on which it
occurred. For invocation target exceptions, we'll handle the wrapped
exception. For all other types of exceptions, we'll display the name of the
exception class and the message, or if there is no message the source file and
line number.
1 files added
28 files modified
311 ■■■■ changed files
opends/src/server/org/opends/server/authorization/dseecompat/AciException.java 5 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/backends/jeb/JebException.java 10 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/config/ConfigException.java 6 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/core/BindOperation.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/extensions/DigestMD5SASLMechanismHandler.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/extensions/GSSAPIStateInfo.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/protocols/asn1/ASN1Exception.java 6 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/protocols/ldap/LDAPException.java 3 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/schema/AuthPasswordExactEqualityMatchingRule.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/schema/GeneralizedTimeEqualityMatchingRule.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/schema/GeneralizedTimeOrderingMatchingRule.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/changelog/ChangelogDBException.java 8 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tasks/ImportTask.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tasks/InitializeTask.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tasks/RebuildTask.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tasks/RestoreTask.java 4 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/ClientException.java 6 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/makeldif/MakeLDIFException.java 6 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/types/CancelledOperationException.java 6 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/types/DirectoryException.java 8 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/types/IdentifiedException.java 97 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/types/InitializationException.java 5 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/types/MembershipException.java 7 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/types/Schema.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/LDIFException.java 10 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/StaticUtils.java 84 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/args/ArgumentException.java 6 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/types/DirectoryExceptionTestCase.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/authorization/dseecompat/AciException.java
@@ -26,6 +26,7 @@
 */
package org.opends.server.authorization.dseecompat;
import org.opends.server.types.IdentifiedException;
/**
 * The AciException class defines an exception that may be thrown
@@ -33,9 +34,7 @@
 * or during evaluation of an LDAP operation using a set of applicable
 * ACIs.
 */
public class AciException extends Exception {
public class AciException extends IdentifiedException {
  /**
   * The serial version identifier required to satisfy the compiler because this
   * class extends <CODE>java.lang.Exception</CODE>, which implements the
opends/src/server/org/opends/server/backends/jeb/JebException.java
@@ -26,15 +26,19 @@
 */
package org.opends.server.backends.jeb;
import org.opends.server.types.IdentifiedException;
/**
 * This class defines an exception that may be thrown if a problem occurs in the
 * JE backend database.
 */
public class JebException
     extends Exception
     extends IdentifiedException
{
  /**
   * The serial version identifier required to satisfy the compiler because this
   * class extends <CODE>java.lang.Exception</CODE>, which implements the
opends/src/server/org/opends/server/config/ConfigException.java
@@ -28,6 +28,7 @@
import org.opends.server.types.IdentifiedException;
@@ -36,11 +37,8 @@
 * interactions with the Directory Server configuration.
 */
public class ConfigException
       extends Exception
       extends IdentifiedException
{
  /**
   * The serial version identifier required to satisfy the compiler because this
   * class extends <CODE>java.lang.Exception</CODE>, which implements the
opends/src/server/org/opends/server/core/BindOperation.java
@@ -1034,7 +1034,7 @@
        }
        setResultCode(ResultCode.INVALID_CREDENTIALS);
        setAuthFailureReason(de.getErrorMessageID(), de.getErrorMessage());
        setAuthFailureReason(de.getMessageID(), de.getErrorMessage());
        break bindProcessing;
      }
@@ -1187,7 +1187,7 @@
              }
              setResultCode(ResultCode.INVALID_CREDENTIALS);
              setAuthFailureReason(de.getErrorMessageID(),
              setAuthFailureReason(de.getMessageID(),
                                   de.getErrorMessage());
              userEntry = null;
opends/src/server/org/opends/server/extensions/DigestMD5SASLMechanismHandler.java
@@ -432,7 +432,7 @@
      {
        // We couldn't parse the token value, so it must be malformed.
        bindOperation.setResultCode(ResultCode.INVALID_CREDENTIALS);
        bindOperation.setAuthFailureReason(de.getErrorMessageID(),
        bindOperation.setAuthFailureReason(de.getMessageID(),
                                           de.getErrorMessage());
        return;
      }
opends/src/server/org/opends/server/extensions/GSSAPIStateInfo.java
@@ -407,7 +407,7 @@
      }
      bindOperation.setResultCode(ResultCode.INVALID_CREDENTIALS);
      bindOperation.setAuthFailureReason(de.getErrorMessageID(),
      bindOperation.setAuthFailureReason(de.getMessageID(),
                                         de.getErrorMessage());
      clientConnection.setSASLAuthStateInfo(null);
      return false;
opends/src/server/org/opends/server/protocols/asn1/ASN1Exception.java
@@ -28,6 +28,7 @@
import org.opends.server.types.IdentifiedException;
@@ -36,11 +37,8 @@
 * interacting with an ASN.1 element.
 */
public class ASN1Exception
       extends Exception
       extends IdentifiedException
{
  /**
   * The serial version identifier required to satisfy the compiler because this
   * class extends <CODE>java.lang.Exception</CODE>, which implements the
opends/src/server/org/opends/server/protocols/ldap/LDAPException.java
@@ -29,6 +29,7 @@
import org.opends.server.types.DN;
import org.opends.server.types.IdentifiedException;
@@ -37,7 +38,7 @@
 * interacting with an LDAP protocol element.
 */
public class LDAPException
       extends Exception
       extends IdentifiedException
{
  /**
   * The serial version identifier required to satisfy the compiler because this
opends/src/server/org/opends/server/schema/AuthPasswordExactEqualityMatchingRule.java
@@ -188,7 +188,7 @@
          throw de;
        case WARN:
          logError(ErrorLogCategory.SCHEMA, ErrorLogSeverity.SEVERE_WARNING,
                   de.getErrorMessage(), de.getErrorMessageID());
                   de.getErrorMessage(), de.getMessageID());
          return new ASN1OctetString(value.stringValue());
        default:
          return new ASN1OctetString(value.stringValue());
opends/src/server/org/opends/server/schema/GeneralizedTimeEqualityMatchingRule.java
@@ -220,7 +220,7 @@
        case WARN:
          logError(ErrorLogCategory.SCHEMA, ErrorLogSeverity.SEVERE_WARNING,
                   de.getErrorMessage(), de.getErrorMessageID());
                   de.getErrorMessage(), de.getMessageID());
          return new ASN1OctetString(value.value());
        default:
opends/src/server/org/opends/server/schema/GeneralizedTimeOrderingMatchingRule.java
@@ -230,7 +230,7 @@
        case WARN:
          logError(ErrorLogCategory.SCHEMA, ErrorLogSeverity.SEVERE_WARNING,
                   de.getErrorMessage(), de.getErrorMessageID());
                   de.getErrorMessage(), de.getMessageID());
          return new ASN1OctetString(value.value());
        default:
opends/src/server/org/opends/server/synchronization/changelog/ChangelogDBException.java
@@ -26,12 +26,18 @@
 */
package org.opends.server.synchronization.changelog;
import org.opends.server.types.IdentifiedException;
/**
 * This class define an Exception that must be used when some error
 * condition was detected in the changelog database that cannot be recovered
 * automatically.
 */
public class ChangelogDBException extends Exception
public class ChangelogDBException extends IdentifiedException
{
  private int messageID;
opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java
@@ -962,7 +962,7 @@
            catch(DirectoryException de)
            {
              // Returns an error message to notify the sender
              int msgID = de.getErrorMessageID();
              int msgID = de.getMessageID();
              ErrorMessage errorMsg = new ErrorMessage(initMsg.getsenderID(),
                  msgID, de.getMessage());
              broker.publish(errorMsg);
@@ -980,7 +980,7 @@
            catch(DirectoryException de)
            {
              // Return an error message to notify the sender
              int msgID = de.getErrorMessageID();
              int msgID = de.getMessageID();
              ErrorMessage errorMsg = new ErrorMessage(initMsg.getsenderID(),
                  msgID, de.getMessage());
              log(getMessage(msgID, backend.getBackendID()) + de.getMessage());
opends/src/server/org/opends/server/tasks/ImportTask.java
@@ -491,7 +491,7 @@
      }
      logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
               e.getErrorMessage(), e.getErrorMessageID());
               e.getErrorMessage(), e.getMessageID());
      return TaskState.STOPPED_BY_ERROR;
    }
@@ -615,7 +615,7 @@
        }
        logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
                 e.getErrorMessage(), e.getErrorMessageID());
                 e.getErrorMessage(), e.getMessageID());
        return TaskState.STOPPED_BY_ERROR;
      }
      DirectoryServer.notifyImportEnded(backend, importConfig, true);
opends/src/server/org/opends/server/tasks/InitializeTask.java
@@ -153,7 +153,7 @@
    catch(InterruptedException ie) {}
    catch(DirectoryException de)
    {
      int msgID   = de.getErrorMessageID();
      int msgID   = de.getMessageID();
      String message = getMessage(msgID, de.getErrorMessage());
      logError(ErrorLogCategory.TASK, ErrorLogSeverity.SEVERE_ERROR,
               message, msgID);
@@ -180,7 +180,7 @@
    {
      if (de != null)
      {
        int msgID   = de.getErrorMessageID();
        int msgID   = de.getMessageID();
        String message = getMessage(msgID, de.getErrorMessage());
        logError(ErrorLogCategory.TASK, ErrorLogSeverity.SEVERE_ERROR,
                 message, msgID);
opends/src/server/org/opends/server/tasks/RebuildTask.java
@@ -208,7 +208,7 @@
        }
        logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
                 e.getErrorMessage(), e.getErrorMessageID());
                 e.getErrorMessage(), e.getMessageID());
        return TaskState.STOPPED_BY_ERROR;
      }
@@ -321,7 +321,7 @@
        }
        logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
                 e.getErrorMessage(), e.getErrorMessageID());
                 e.getErrorMessage(), e.getMessageID());
        return TaskState.STOPPED_BY_ERROR;
      }
    }
opends/src/server/org/opends/server/tasks/RestoreTask.java
@@ -308,7 +308,7 @@
      }
      logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
               e.getErrorMessage(), e.getErrorMessageID());
               e.getErrorMessage(), e.getMessageID());
      return TaskState.STOPPED_BY_ERROR;
    }
@@ -377,7 +377,7 @@
        }
        logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR,
                 e.getErrorMessage(), e.getErrorMessageID());
                 e.getErrorMessage(), e.getMessageID());
        errorsEncountered = true;
      }
      DirectoryServer.notifyRestoreEnded(backend, restoreConfig, true);
opends/src/server/org/opends/server/tools/ClientException.java
@@ -28,12 +28,16 @@
import org.opends.server.types.IdentifiedException;
/**
 * This class defines an exception that may be thrown if a local problem occurs
 * in a Directory Server client.
 */
public class ClientException
       extends Exception
       extends IdentifiedException
{
  /**
   * The serial version identifier required to satisfy the compiler because this
opends/src/server/org/opends/server/tools/makeldif/MakeLDIFException.java
@@ -28,12 +28,16 @@
import org.opends.server.types.IdentifiedException;
/**
 * This class defines an exception that can be thrown if a problem occurs during
 * MakeLDIF processing.
 */
public class MakeLDIFException
       extends Exception
       extends IdentifiedException
{
  /**
   * The serial version identifier required to satisfy the compiler because this
opends/src/server/org/opends/server/types/CancelledOperationException.java
@@ -27,17 +27,15 @@
package org.opends.server.types;
/**
 * This class defines an exception that may be thrown if the operation
 * being processed is cancelled for some reason (e.g., an abandon or
 * cancel request from the client).
 */
public class CancelledOperationException
       extends Exception
       extends IdentifiedException
{
  /**
   * The serial version identifier required to satisfy the compiler
   * because this class extends <CODE>java.lang.Exception</CODE>,
opends/src/server/org/opends/server/types/DirectoryException.java
@@ -32,17 +32,13 @@
/**
 * This class defines an exception that may be thrown if a problem
 * occurs in the Directory Server.
 */
public class DirectoryException
       extends Exception
       extends IdentifiedException
{
  /**
   * The serial version identifier required to satisfy the compiler
   * because this class extends <CODE>java.lang.Exception</CODE>,
@@ -214,7 +210,7 @@
   * @return  The unique ID for the error message associated with this
   *          directory exception.
   */
  public final int getErrorMessageID()
  public final int getMessageID()
  {
    return errorMessageID;
  }
opends/src/server/org/opends/server/types/IdentifiedException.java
New file
@@ -0,0 +1,97 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
 */
package org.opends.server.types;
/**
 * This class defines a base exception that should be extended by any
 * exception that exposes a unique identifier for the associated
 * message.
 */
public abstract class IdentifiedException
       extends Exception
{
  /**
   * Creates a new identified exception.
   */
  protected IdentifiedException()
  {
    super();
  }
  /**
   * Creates a new identified exception with the provided information.
   *
   * @param  message  The message that explains the problem that
   *                  occurred.
   */
  protected IdentifiedException(String message)
  {
    super(message);
  }
  /**
   * Creates a new identified exception with the provided information.
   *
   * @param  cause  The underlying cause that triggered this
   *                exception.
   */
  protected IdentifiedException(Throwable cause)
  {
    super(cause);
  }
  /**
   * Creates a new identified exception with the provided information.
   *
   * @param  message  The message that explains the problem that
   *                  occurred.
   * @param  cause    The underlying cause that triggered this
   *                  exception.
   */
  protected IdentifiedException(String message, Throwable cause)
  {
    super(message, cause);
  }
  /**
   * Retrieves the unique identifier for the associated message.
   *
   * @return  The unique identifier for the associated message.
   */
  public abstract int getMessageID();
}
opends/src/server/org/opends/server/types/InitializationException.java
@@ -32,11 +32,8 @@
 * occurs while trying to initialize a Directory Server component.
 */
public class InitializationException
       extends Exception
       extends IdentifiedException
{
  /**
   * The serial version identifier required to satisfy the compiler
   * because this class extends <CODE>java.lang.Exception</CODE>,
opends/src/server/org/opends/server/types/MembershipException.java
@@ -32,11 +32,8 @@
 * occurs while attempting to iterate across the members of a group.
 */
public class MembershipException
       extends Exception
       extends IdentifiedException
{
  /**
   * The serial version identifier required to satisfy the compiler
   * because this class extends <CODE>java.lang.Exception</CODE>,
@@ -126,7 +123,7 @@
   *
   * @return  The unique identifier for the error message.
   */
  public final int getErrorMessageID()
  public final int getMessageID()
  {
    return errorMessageID;
  }
opends/src/server/org/opends/server/types/Schema.java
@@ -2589,7 +2589,7 @@
      // If we got an error as a result of a circular reference, then
      // we want to make sure that the schema element we call out is
      // the one that is at the root of the problem.
      if (de.getErrorMessageID() ==
      if (de.getMessageID() ==
          MSGID_SCHEMA_CIRCULAR_DEPENDENCY_REFERENCE)
      {
        int    msgID   = MSGID_SCHEMA_CIRCULAR_DEPENDENCY_REFERENCE;
opends/src/server/org/opends/server/util/LDIFException.java
@@ -27,16 +27,18 @@
package org.opends.server.util;
import org.opends.server.types.IdentifiedException;
/**
 * This class defines an exception that may be thrown while attempting to parse
 * LDIF content.
 */
public final class LDIFException
       extends Exception
       extends IdentifiedException
{
  /**
   * The serial version identifier required to satisfy the compiler because this
   * class extends <CODE>java.lang.Exception</CODE>, which implements the
opends/src/server/org/opends/server/util/StaticUtils.java
@@ -51,6 +51,7 @@
import org.opends.server.types.AttributeValue;
import org.opends.server.types.DN;
import org.opends.server.types.Entry;
import org.opends.server.types.IdentifiedException;
import org.opends.server.types.ObjectClass;
import org.opends.server.types.RDN;
@@ -72,9 +73,6 @@
 */
public final class StaticUtils
{
  /**
   * Private constructor to prevent instantiation.
   */
@@ -1431,6 +1429,86 @@
    }
  }
  /**
   * Retrieves the best human-readable message for the provided exception.  For
   * exceptions defined in the OpenDS project, it will attempt to use the
   * message (combining it with the message ID if available).  For some
   * exceptions that use encapsulation (e.g., InvocationTargetException), it
   * will be unwrapped and the cause will be treated.  For all others, the
   *
   *
   * @param  t  The {@code Throwable} object for which to retrieve the message.
   *
   * @return  The human-readable message generated for the provided exception.
   */
  public static String getExceptionMessage(Throwable t)
  {
    if (t instanceof IdentifiedException)
    {
      IdentifiedException ie = (IdentifiedException) t;
      StringBuilder message = new StringBuilder();
      message.append(ie.getMessage());
      message.append(" (id=");
      message.append(ie.getMessageID());
      message.append(")");
      return message.toString();
    }
    else if (t instanceof NullPointerException)
    {
      StackTraceElement[] stackElements = t.getStackTrace();
      StringBuilder message = new StringBuilder();
      message.append("NullPointerException(");
      message.append(stackElements[0].getFileName());
      message.append(":");
      message.append(stackElements[0].getLineNumber());
      message.append(")");
      return message.toString();
    }
    else if ((t instanceof InvocationTargetException) &&
             (t.getCause() != null))
    {
      return getExceptionMessage(t.getCause());
    }
    else
    {
      StringBuilder message = new StringBuilder();
      String className = t.getClass().getName();
      int periodPos = className.lastIndexOf('.');
      if (periodPos > 0)
      {
        message.append(className.substring(periodPos+1));
      }
      else
      {
        message.append(className);
      }
      message.append("(");
      if (t.getMessage() == null)
      {
        StackTraceElement[] stackElements = t.getStackTrace();
        message.append(stackElements[0].getFileName());
        message.append(":");
        message.append(stackElements[0].getLineNumber());
      }
      else
      {
        message.append(t.getMessage());
      }
      message.append(")");
      return message.toString();
    }
  }
  /**
   * Retrieves a stack trace from the provided exception as a single-line
   * string.
opends/src/server/org/opends/server/util/args/ArgumentException.java
@@ -28,12 +28,16 @@
import org.opends.server.types.IdentifiedException;
/**
 * This class defines an exception that may be thrown if there is a problem with
 * an argument definition.
 */
public class ArgumentException
       extends Exception
       extends IdentifiedException
{
  /**
   * The serial version identifier required to satisfy the compiler because this
opends/tests/unit-tests-testng/src/server/org/opends/server/types/DirectoryExceptionTestCase.java
@@ -283,7 +283,7 @@
    assertNotNull(de.getResultCode());
    de.getErrorMessage();
    de.getErrorMessageID();
    de.getMessageID();
    de.getMatchedDN();
    de.getReferralURLs();
  }