Skip to main content



      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 11:06 Go to next message
Eclipse UserFriend
Hi,

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 https://blog.hargrave.io/2007/09/classforname-caches-defined-class-in.html) 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?

Regards,

Hallvard
Re: [Xbase] Classloading in XbaseInterpreter [message #1804225 is a reply to message #1804214] Wed, 20 March 2019 13:38 Go to previous messageGo to next message
Eclipse UserFriend
Hey Hallvard,

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

Best
Sebastian
Re: [Xbase] Classloading in XbaseInterpreter [message #1804309 is a reply to message #1804225] Fri, 22 March 2019 04:43 Go to previous message
Eclipse UserFriend
@Hallvard, we could change the code as follows: https://github.com/eclipse/xtext-extras/pull/393
would that help for easier subclassing?
Previous Topic:Referenced versions in xtext-dev-bom
Next Topic:Security Exception when building Projects with Xtend
Goto Forum:
  


Current Time: Sat Jul 05 01:58:32 EDT 2025

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

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

Back to the top