Bug 505996: Improved diagnostics of adapter contract violations.
Change-Id: Ifbd741f86014edf44968a3db27fc5afc3f8d8dd9
Signed-off-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
diff --git a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/Adapters.java b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/Adapters.java
index 2035a9f..e3f78c8 100644
--- a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/Adapters.java
+++ b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/runtime/Adapters.java
@@ -59,7 +59,10 @@
Object result = adaptable.getAdapter(adapter);
if (result != null) {
// Sanity-check
- Assert.isTrue(adapter.isInstance(result));
+ if (!adapter.isInstance(result)) {
+ throw new AssertionFailedException(adaptable.getClass().getName() + ".getAdapter(" + adapter.getName() + ".class) returned " //$NON-NLS-1$//$NON-NLS-2$
+ + result.getClass().getName() + " that is not an instance the requested type"); //$NON-NLS-1$
+ }
return (T) result;
}
}
@@ -74,7 +77,11 @@
Object result = queryAdapterManager(sourceObject, adapterId, allowActivation);
if (result != null) {
// Sanity-check
- Assert.isTrue(adapter.isInstance(result));
+ if (!adapter.isInstance(result)) {
+ throw new AssertionFailedException("An adapter factory for " //$NON-NLS-1$
+ + sourceObject.getClass().getName() + " returned " + result.getClass().getName() //$NON-NLS-1$
+ + " that is not an instance of " + adapter.getName()); //$NON-NLS-1$
+ }
return (T) result;
}