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
| | |
| | | */ |
| | | package org.opends.server.authorization.dseecompat; |
| | | |
| | | import org.opends.server.types.IdentifiedException; |
| | | |
| | | /** |
| | | * The AciException class defines an exception that may be thrown |
| | |
| | | * 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 |
| | |
| | | */ |
| | | 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 |
| | |
| | | |
| | | |
| | | |
| | | import org.opends.server.types.IdentifiedException; |
| | | |
| | | |
| | | |
| | |
| | | * 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 |
| | |
| | | } |
| | | |
| | | setResultCode(ResultCode.INVALID_CREDENTIALS); |
| | | setAuthFailureReason(de.getErrorMessageID(), de.getErrorMessage()); |
| | | setAuthFailureReason(de.getMessageID(), de.getErrorMessage()); |
| | | break bindProcessing; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | setResultCode(ResultCode.INVALID_CREDENTIALS); |
| | | setAuthFailureReason(de.getErrorMessageID(), |
| | | setAuthFailureReason(de.getMessageID(), |
| | | de.getErrorMessage()); |
| | | |
| | | userEntry = null; |
| | |
| | | { |
| | | // 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; |
| | | } |
| | |
| | | } |
| | | |
| | | bindOperation.setResultCode(ResultCode.INVALID_CREDENTIALS); |
| | | bindOperation.setAuthFailureReason(de.getErrorMessageID(), |
| | | bindOperation.setAuthFailureReason(de.getMessageID(), |
| | | de.getErrorMessage()); |
| | | clientConnection.setSASLAuthStateInfo(null); |
| | | return false; |
| | |
| | | |
| | | |
| | | |
| | | import org.opends.server.types.IdentifiedException; |
| | | |
| | | |
| | | |
| | |
| | | * 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 |
| | |
| | | |
| | | |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.IdentifiedException; |
| | | |
| | | |
| | | |
| | |
| | | * interacting with an LDAP protocol element. |
| | | */ |
| | | public class LDAPException |
| | | extends Exception |
| | | extends IdentifiedException |
| | | { |
| | | /** |
| | | * The serial version identifier required to satisfy the compiler because this |
| | |
| | | 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()); |
| | |
| | | |
| | | case WARN: |
| | | logError(ErrorLogCategory.SCHEMA, ErrorLogSeverity.SEVERE_WARNING, |
| | | de.getErrorMessage(), de.getErrorMessageID()); |
| | | de.getErrorMessage(), de.getMessageID()); |
| | | return new ASN1OctetString(value.value()); |
| | | |
| | | default: |
| | |
| | | |
| | | case WARN: |
| | | logError(ErrorLogCategory.SCHEMA, ErrorLogSeverity.SEVERE_WARNING, |
| | | de.getErrorMessage(), de.getErrorMessageID()); |
| | | de.getErrorMessage(), de.getMessageID()); |
| | | return new ASN1OctetString(value.value()); |
| | | |
| | | default: |
| | |
| | | */ |
| | | 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; |
| | | |
| | |
| | | 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); |
| | |
| | | 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()); |
| | |
| | | } |
| | | |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, |
| | | e.getErrorMessage(), e.getErrorMessageID()); |
| | | e.getErrorMessage(), e.getMessageID()); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, |
| | | e.getErrorMessage(), e.getErrorMessageID()); |
| | | e.getErrorMessage(), e.getMessageID()); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | | } |
| | | DirectoryServer.notifyImportEnded(backend, importConfig, true); |
| | |
| | | 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); |
| | |
| | | { |
| | | 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); |
| | |
| | | } |
| | | |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, |
| | | e.getErrorMessage(), e.getErrorMessageID()); |
| | | e.getErrorMessage(), e.getMessageID()); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, |
| | | e.getErrorMessage(), e.getErrorMessageID()); |
| | | e.getErrorMessage(), e.getMessageID()); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, |
| | | e.getErrorMessage(), e.getErrorMessageID()); |
| | | e.getErrorMessage(), e.getMessageID()); |
| | | return TaskState.STOPPED_BY_ERROR; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, |
| | | e.getErrorMessage(), e.getErrorMessageID()); |
| | | e.getErrorMessage(), e.getMessageID()); |
| | | errorsEncountered = true; |
| | | } |
| | | DirectoryServer.notifyRestoreEnded(backend, restoreConfig, true); |
| | |
| | | |
| | | |
| | | |
| | | 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 |
| | |
| | | |
| | | |
| | | |
| | | 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 |
| | |
| | | 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>, |
| | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 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>, |
| | |
| | | * @return The unique ID for the error message associated with this |
| | | * directory exception. |
| | | */ |
| | | public final int getErrorMessageID() |
| | | public final int getMessageID() |
| | | { |
| | | return errorMessageID; |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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(); |
| | | } |
| | | |
| | |
| | | * 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>, |
| | |
| | | * 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>, |
| | |
| | | * |
| | | * @return The unique identifier for the error message. |
| | | */ |
| | | public final int getErrorMessageID() |
| | | public final int getMessageID() |
| | | { |
| | | return errorMessageID; |
| | | } |
| | |
| | | // 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; |
| | |
| | | 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 |
| | |
| | | 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; |
| | | |
| | |
| | | */ |
| | | public final class StaticUtils |
| | | { |
| | | |
| | | |
| | | |
| | | /** |
| | | * Private constructor to prevent instantiation. |
| | | */ |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 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. |
| | |
| | | |
| | | |
| | | |
| | | 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 |
| | |
| | | assertNotNull(de.getResultCode()); |
| | | |
| | | de.getErrorMessage(); |
| | | de.getErrorMessageID(); |
| | | de.getMessageID(); |
| | | de.getMatchedDN(); |
| | | de.getReferralURLs(); |
| | | } |