Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/AdapterManager.java20
-rw-r--r--bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/adapter/AdapterFactoryProxy.java14
2 files changed, 30 insertions, 4 deletions
diff --git a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/AdapterManager.java b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/AdapterManager.java
index 07909a1b..ba4a053c 100644
--- a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/AdapterManager.java
+++ b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/AdapterManager.java
@@ -288,13 +288,25 @@ public final class AdapterManager implements IAdapterManager {
public <T> T getAdapter(Object adaptable, Class<T> adapterType) {
Assert.isNotNull(adaptable);
Assert.isNotNull(adapterType);
- IAdapterFactory factory = getFactories(adaptable.getClass()).get(adapterType.getName());
+ String adapterTypeName = adapterType.getName();
+ IAdapterFactory factory = getFactories(adaptable.getClass()).get(adapterTypeName);
T result = null;
- if (factory != null)
+ if (factory != null) {
result = factory.getAdapter(adaptable, adapterType);
- if (result == null && adapterType.isInstance(adaptable))
+ }
+ if (result == null && adapterType.isInstance(adaptable)) {
return (T) adaptable;
- return result;
+ }
+ if (result == null || adapterType.isInstance(result)) {
+ return result;
+ }
+ // Here we have a result which does not match the expected type.
+ // Throwing an exception here allows us to identify the violating factory.
+ // If we don't do this, clients will just see CCE without any idea who
+ // supplied the wrong adapter
+ throw new AssertionFailedException("Adapter factory " //$NON-NLS-1$
+ + factory + " returned " + result.getClass().getName() //$NON-NLS-1$
+ + " that is not an instance of " + adapterTypeName); //$NON-NLS-1$
}
@Override
diff --git a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/adapter/AdapterFactoryProxy.java b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/adapter/AdapterFactoryProxy.java
index bcee1f66..6ba89e75 100644
--- a/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/adapter/AdapterFactoryProxy.java
+++ b/bundles/org.eclipse.equinox.registry/src/org/eclipse/core/internal/adapter/AdapterFactoryProxy.java
@@ -151,4 +151,18 @@ class AdapterFactoryProxy implements IAdapterFactory, IAdapterFactoryExt {
String msg = NLS.bind(RegistryMessages.adapters_badAdapterFactory, element.getContributor().getName());
RuntimeLog.log(new Status(IStatus.ERROR, RegistryMessages.OWNER_NAME, 0, msg, null));
}
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("AdapterFactoryProxy [contributor: "); //$NON-NLS-1$
+ sb.append(element.getContributor());
+ sb.append(", adaptableType: "); //$NON-NLS-1$
+ sb.append(getAdaptableType());
+ if (factory != null) {
+ sb.append(", factory: "); //$NON-NLS-1$
+ sb.append(factory);
+ }
+ sb.append("]"); //$NON-NLS-1$
+ return sb.toString();
+ }
}

Back to the top