Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.common')
-rw-r--r--bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/AdapterManager.java20
1 files changed, 16 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

Back to the top