From 8213b81bb81d462f08ce9c429f3445f36b35fa16 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Fri, 20 Apr 2007 23:28:00 +0000
Subject: [PATCH] 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.
---
opends/src/server/org/opends/server/authorization/dseecompat/AciException.java | 5
opends/src/server/org/opends/server/protocols/ldap/LDAPException.java | 3
opends/src/server/org/opends/server/tasks/InitializeTask.java | 4
opends/src/server/org/opends/server/types/DirectoryException.java | 8 -
opends/tests/unit-tests-testng/src/server/org/opends/server/types/DirectoryExceptionTestCase.java | 2
opends/src/server/org/opends/server/schema/AuthPasswordExactEqualityMatchingRule.java | 2
opends/src/server/org/opends/server/protocols/asn1/ASN1Exception.java | 6
opends/src/server/org/opends/server/tasks/RebuildTask.java | 4
opends/src/server/org/opends/server/schema/GeneralizedTimeOrderingMatchingRule.java | 2
opends/src/server/org/opends/server/schema/GeneralizedTimeEqualityMatchingRule.java | 2
opends/src/server/org/opends/server/types/InitializationException.java | 5
opends/src/server/org/opends/server/core/BindOperation.java | 4
opends/src/server/org/opends/server/tasks/RestoreTask.java | 4
opends/src/server/org/opends/server/util/LDIFException.java | 10 +
opends/src/server/org/opends/server/tasks/ImportTask.java | 4
opends/src/server/org/opends/server/types/CancelledOperationException.java | 6
opends/src/server/org/opends/server/util/StaticUtils.java | 84 +++++++++++++
opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java | 4
opends/src/server/org/opends/server/tools/makeldif/MakeLDIFException.java | 6
opends/src/server/org/opends/server/synchronization/changelog/ChangelogDBException.java | 8 +
opends/src/server/org/opends/server/config/ConfigException.java | 6
opends/src/server/org/opends/server/extensions/DigestMD5SASLMechanismHandler.java | 2
opends/src/server/org/opends/server/types/Schema.java | 2
opends/src/server/org/opends/server/types/MembershipException.java | 7
opends/src/server/org/opends/server/extensions/GSSAPIStateInfo.java | 2
opends/src/server/org/opends/server/tools/ClientException.java | 6
opends/src/server/org/opends/server/types/IdentifiedException.java | 97 ++++++++++++++++
opends/src/server/org/opends/server/backends/jeb/JebException.java | 10 +
opends/src/server/org/opends/server/util/args/ArgumentException.java | 6
29 files changed, 247 insertions(+), 64 deletions(-)
diff --git a/opends/src/server/org/opends/server/authorization/dseecompat/AciException.java b/opends/src/server/org/opends/server/authorization/dseecompat/AciException.java
index 924a960..da74266 100644
--- a/opends/src/server/org/opends/server/authorization/dseecompat/AciException.java
+++ b/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
diff --git a/opends/src/server/org/opends/server/backends/jeb/JebException.java b/opends/src/server/org/opends/server/backends/jeb/JebException.java
index 5c7320c..c969249 100644
--- a/opends/src/server/org/opends/server/backends/jeb/JebException.java
+++ b/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
diff --git a/opends/src/server/org/opends/server/config/ConfigException.java b/opends/src/server/org/opends/server/config/ConfigException.java
index 91e5b3f..24e33ad 100644
--- a/opends/src/server/org/opends/server/config/ConfigException.java
+++ b/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
diff --git a/opends/src/server/org/opends/server/core/BindOperation.java b/opends/src/server/org/opends/server/core/BindOperation.java
index e269787..ac70224 100644
--- a/opends/src/server/org/opends/server/core/BindOperation.java
+++ b/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;
diff --git a/opends/src/server/org/opends/server/extensions/DigestMD5SASLMechanismHandler.java b/opends/src/server/org/opends/server/extensions/DigestMD5SASLMechanismHandler.java
index 8b67146..a8ccc93 100644
--- a/opends/src/server/org/opends/server/extensions/DigestMD5SASLMechanismHandler.java
+++ b/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;
}
diff --git a/opends/src/server/org/opends/server/extensions/GSSAPIStateInfo.java b/opends/src/server/org/opends/server/extensions/GSSAPIStateInfo.java
index e975ac6..d157766 100644
--- a/opends/src/server/org/opends/server/extensions/GSSAPIStateInfo.java
+++ b/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;
diff --git a/opends/src/server/org/opends/server/protocols/asn1/ASN1Exception.java b/opends/src/server/org/opends/server/protocols/asn1/ASN1Exception.java
index 53a9f38..1edd006 100644
--- a/opends/src/server/org/opends/server/protocols/asn1/ASN1Exception.java
+++ b/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
diff --git a/opends/src/server/org/opends/server/protocols/ldap/LDAPException.java b/opends/src/server/org/opends/server/protocols/ldap/LDAPException.java
index 2adf8a2..931244d 100644
--- a/opends/src/server/org/opends/server/protocols/ldap/LDAPException.java
+++ b/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
diff --git a/opends/src/server/org/opends/server/schema/AuthPasswordExactEqualityMatchingRule.java b/opends/src/server/org/opends/server/schema/AuthPasswordExactEqualityMatchingRule.java
index 79f7c53..ff7b6ea 100644
--- a/opends/src/server/org/opends/server/schema/AuthPasswordExactEqualityMatchingRule.java
+++ b/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());
diff --git a/opends/src/server/org/opends/server/schema/GeneralizedTimeEqualityMatchingRule.java b/opends/src/server/org/opends/server/schema/GeneralizedTimeEqualityMatchingRule.java
index be01196..0f6e7af 100644
--- a/opends/src/server/org/opends/server/schema/GeneralizedTimeEqualityMatchingRule.java
+++ b/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:
diff --git a/opends/src/server/org/opends/server/schema/GeneralizedTimeOrderingMatchingRule.java b/opends/src/server/org/opends/server/schema/GeneralizedTimeOrderingMatchingRule.java
index e99d558..6f75eae 100644
--- a/opends/src/server/org/opends/server/schema/GeneralizedTimeOrderingMatchingRule.java
+++ b/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:
diff --git a/opends/src/server/org/opends/server/synchronization/changelog/ChangelogDBException.java b/opends/src/server/org/opends/server/synchronization/changelog/ChangelogDBException.java
index 72e6783..542688c 100644
--- a/opends/src/server/org/opends/server/synchronization/changelog/ChangelogDBException.java
+++ b/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;
diff --git a/opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java b/opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java
index 728fecf..743d24d 100644
--- a/opends/src/server/org/opends/server/synchronization/plugin/SynchronizationDomain.java
+++ b/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());
diff --git a/opends/src/server/org/opends/server/tasks/ImportTask.java b/opends/src/server/org/opends/server/tasks/ImportTask.java
index 826ac4f..0290422 100644
--- a/opends/src/server/org/opends/server/tasks/ImportTask.java
+++ b/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);
diff --git a/opends/src/server/org/opends/server/tasks/InitializeTask.java b/opends/src/server/org/opends/server/tasks/InitializeTask.java
index f96235b..84c63c8 100644
--- a/opends/src/server/org/opends/server/tasks/InitializeTask.java
+++ b/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);
diff --git a/opends/src/server/org/opends/server/tasks/RebuildTask.java b/opends/src/server/org/opends/server/tasks/RebuildTask.java
index 262b1f3..19f3d6a 100644
--- a/opends/src/server/org/opends/server/tasks/RebuildTask.java
+++ b/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;
}
}
diff --git a/opends/src/server/org/opends/server/tasks/RestoreTask.java b/opends/src/server/org/opends/server/tasks/RestoreTask.java
index 8082c1c..3046de2 100644
--- a/opends/src/server/org/opends/server/tasks/RestoreTask.java
+++ b/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);
diff --git a/opends/src/server/org/opends/server/tools/ClientException.java b/opends/src/server/org/opends/server/tools/ClientException.java
index 9b2d4fe..b42cedf 100644
--- a/opends/src/server/org/opends/server/tools/ClientException.java
+++ b/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
diff --git a/opends/src/server/org/opends/server/tools/makeldif/MakeLDIFException.java b/opends/src/server/org/opends/server/tools/makeldif/MakeLDIFException.java
index e3a5b9a..9a9b3a0 100644
--- a/opends/src/server/org/opends/server/tools/makeldif/MakeLDIFException.java
+++ b/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
diff --git a/opends/src/server/org/opends/server/types/CancelledOperationException.java b/opends/src/server/org/opends/server/types/CancelledOperationException.java
index 6a8b5bc..a7e114d 100644
--- a/opends/src/server/org/opends/server/types/CancelledOperationException.java
+++ b/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>,
diff --git a/opends/src/server/org/opends/server/types/DirectoryException.java b/opends/src/server/org/opends/server/types/DirectoryException.java
index 09a4d3a..638c694 100644
--- a/opends/src/server/org/opends/server/types/DirectoryException.java
+++ b/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;
}
diff --git a/opends/src/server/org/opends/server/types/IdentifiedException.java b/opends/src/server/org/opends/server/types/IdentifiedException.java
new file mode 100644
index 0000000..9b1df50
--- /dev/null
+++ b/opends/src/server/org/opends/server/types/IdentifiedException.java
@@ -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();
+}
+
diff --git a/opends/src/server/org/opends/server/types/InitializationException.java b/opends/src/server/org/opends/server/types/InitializationException.java
index 1788022..24e2e59 100644
--- a/opends/src/server/org/opends/server/types/InitializationException.java
+++ b/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>,
diff --git a/opends/src/server/org/opends/server/types/MembershipException.java b/opends/src/server/org/opends/server/types/MembershipException.java
index ee838fa..2665e40 100644
--- a/opends/src/server/org/opends/server/types/MembershipException.java
+++ b/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;
}
diff --git a/opends/src/server/org/opends/server/types/Schema.java b/opends/src/server/org/opends/server/types/Schema.java
index ecbe0b6..17fcf91 100644
--- a/opends/src/server/org/opends/server/types/Schema.java
+++ b/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;
diff --git a/opends/src/server/org/opends/server/util/LDIFException.java b/opends/src/server/org/opends/server/util/LDIFException.java
index 788a566..85794ee 100644
--- a/opends/src/server/org/opends/server/util/LDIFException.java
+++ b/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
diff --git a/opends/src/server/org/opends/server/util/StaticUtils.java b/opends/src/server/org/opends/server/util/StaticUtils.java
index 4bde017..b45bbe7 100644
--- a/opends/src/server/org/opends/server/util/StaticUtils.java
+++ b/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.
diff --git a/opends/src/server/org/opends/server/util/args/ArgumentException.java b/opends/src/server/org/opends/server/util/args/ArgumentException.java
index e72297e..1ae1af6 100644
--- a/opends/src/server/org/opends/server/util/args/ArgumentException.java
+++ b/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
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/types/DirectoryExceptionTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/types/DirectoryExceptionTestCase.java
index 05644a6..9b66635 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/types/DirectoryExceptionTestCase.java
+++ b/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();
}
--
Gitblit v1.10.0