Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xbase] Classloading in XbaseInterpreter(Updating XbaseInterpreter's classloader doesn't work)
[Xbase] Classloading in XbaseInterpreter [message #1804214] Wed, 20 March 2019 15:06 Go to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 672
Registered: July 2009
Location: Trondheim, Norway
Senior Member

I'm writing an interpreter for an Xbase-based DSL and would like to support loading classes from the same Java project as the DSL file. That way I can mix Java code and DSL code. I have a ClassLoader that uses the classpath entries of the Java project and it works fine. The next step is to react to changes to Java project classes and re-instantiate the classloader, so the interpreter doesn't use old classes. This also works in principle, however, some class caching mechanism prevents it from working properly. Even though my classloader correctly reloads changed classes, Xtext's ClassFinder class (as used by XbaseInterpreter and JavaReflectAccess) uses Class.forName(String, boolean, ClassLoader) and it apparently (according to has its own caching that reuses obsolete classes.

I've been able to replace JavaReflectAccess with my own class (since it is injected I can override it in my Guice module) and make it use a custom ClassFinder that uses ClassLoader.loadClass directly (instead of Class.forName), but XbaseInterpreter has another instance of ClassFinder that cannot easily be replaced, since it is not injected, but created using new, is private and accessed directly in many methods. So although my approach seems to work, now XbaseInterpreter uses (directly and indirectly through JavaReflectAccess) two ClassFinder instances with different class loading logic and that seems wrong, so I wonder what to do. The best would be to have the XbaseInterpreter use the same instance as JavaReflectAccess, or allow the creation of the its own ClassFinder instance to be customised (e.g. in an overridable getClassFinder method, like JavaReflectAccess does).

Any suggestions?


Re: [Xbase] Classloading in XbaseInterpreter [message #1804225 is a reply to message #1804214] Wed, 20 March 2019 17:38 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3108
Registered: July 2009
Senior Member
Hey Hallvard,

overriding org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.setClassLoader(ClassLoader) and initializing the necessary fields reflectively should work.

Re: [Xbase] Classloading in XbaseInterpreter [message #1804309 is a reply to message #1804225] Fri, 22 March 2019 08:43 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13513
Registered: July 2009
Senior Member
@Hallvard, we could change the code as follows:
would that help for easier subclassing?

Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :
Previous Topic:Referenced versions in xtext-dev-bom
Next Topic:Security Exception when building Projects with Xtend
Goto Forum:

Current Time: Tue Aug 04 14:57:29 GMT 2020

Powered by FUDForum. Page generated in 0.02022 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top