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

Bug 366992

Summary: ClasspathTypeProviderFactory may not use suitable ClassLoader
Product: [Modeling] TMF Reporter: Ed Willink <ed>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: christian.dietrich.opensource, moritz.eysholdt
Version: 2.2.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard:

Description Ed Willink CLA 2011-12-16 17:19:04 EST
JVMTypes are resolved by the ClasspathTypeProviderFactory using the ClassLoader of the non-ui Xtext plugin. This seems to work fine for editors and standalone JUnit tests.

However it fails for plugin JUnit tests that need to resolve a JVMType defined in the test plugin.

This can be worked around by a derived ClasspathTypeProviderFactory that uses the ResourceSet's class loader as the class loader. This could usefully be the standard functionality.

The workaround runs into problems with restricted access to ClasspathTypeProviderFactory  . Perhaps this could be relaxed.
Comment 1 Christian Dietrich CLA 2016-08-19 03:04:45 EDT
this can no longer be reproduced since the factory does the following now

public ClassLoader getClassLoader(ResourceSet resourceSet) {
		if (resourceSet instanceof XtextResourceSet) {
			XtextResourceSet xtextResourceSet = (XtextResourceSet) resourceSet;
			Object ctx = xtextResourceSet.getClasspathURIContext();
			if (ctx != null) {
		        if (ctx instanceof Class<?>) {
		            return ((Class<?>)ctx).getClassLoader();
		        }
		        if (!(ctx instanceof ClassLoader)) {
		        	return ctx.getClass().getClassLoader();
		        }
		        return (ClassLoader) ctx;
			}
		}
		return classLoader;
	}
Comment 2 Ed Willink CLA 2016-08-19 08:02:09 EDT
I think the limitation is still there, since your code snippet doesn't help for an ordinary ResourceSet.

However to ensure that JVMTypes are resolved in a worker thread, I had to rewrite anyway, so this problem no longer affects me.
Comment 3 Christian Dietrich CLA 2016-08-19 08:21:30 EDT
should think about this one more
Comment 4 Moritz Eysholdt CLA 2016-08-19 08:28:49 EDT
(In reply to Ed Willink from comment #2)
> I think the limitation is still there, since your code snippet doesn't help
> for an ordinary ResourceSet.

This argument turns the bug into a duplicate of bug#326407

*** This bug has been marked as a duplicate of bug 326407 ***