Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 511841

Summary: [registry] AdapterManager.getAdapter can return wrong type
Product: [Eclipse Project] Equinox Reporter: Andrey Loskutov <loskutov>
Component: ComponentsAssignee: Andrey Loskutov <loskutov>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: tjwatson
Version: 4.6.0 Neon   
Target Milestone: Oxygen M6   
Hardware: All   
OS: All   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=511743
https://git.eclipse.org/r/90539
https://git.eclipse.org/r/90540
https://bugs.eclipse.org/bugs/show_bug.cgi?id=505996
https://git.eclipse.org/c/equinox/rt.equinox.bundles.git/commit/?id=d071f6db6f8663fe86b9a372def46efc5b0bfeb8
https://git.eclipse.org/c/platform/eclipse.platform.runtime.git/commit/?id=b0e749f8616d5e3880299764c9a7cda6ee410667
Whiteboard:

Description Andrey Loskutov CLA 2017-02-07 09:15:22 EST
Follow up on bug 511743. Thanks to generics there is a possibility that AdapterManager::<T> T getAdapter(Object adaptable, Class<T> adapterType) does not return instance of T type but just an arbitrary type, violating the contract of the interface.

The original problem is that the code doesn't check the type returned by the IAdapterFactory, if there is some registered for T.

The real problem is then to find out WHICH factory returned wrong adapter, because the clients will just see "java.lang.ClassCastException: java.lang.Boolean cannot be cast to org.eclipse.debug.core.model.IDebugTarget".

I think I have an acceptable patch, with test, but the test are in the different git repo, so therw will be two gerrits.
Comment 1 Eclipse Genie CLA 2017-02-07 09:21:33 EST
New Gerrit change created: https://git.eclipse.org/r/90539
Comment 2 Eclipse Genie CLA 2017-02-07 09:23:18 EST
New Gerrit change created: https://git.eclipse.org/r/90540
Comment 4 Andrey Loskutov CLA 2017-02-07 11:03:51 EST
Thanks Thomas! I will wait a day for next equinox build to be able to merge the new test.