Fork me on GitHub
#clojure-dev
<
2017-07-21
>
cfleming04:07:42

Am I correct in thinking that if I load Clojure from Java, by loading a class which requires RT, then clojure.core will always be loaded from the TCCL via RT.baseLoader()?

cfleming04:07:26

I can’t set Compiler.LOADER or RT.USE_CONTEXT_CLASSLOADER, since manipulation either of them will cause RT to be loaded, which will try to use the TCCL to load clojure.core.

hiredman04:07:41

in whatever version of clojure I have checked out it looks like RT.USE_CONTEXT_CLASSLOADER defaults to true

cfleming04:07:05

Yeah, it does.

cfleming04:07:59

I can’t see any other way to influence the classloader that’s used.

cfleming04:07:19

Or to control the initial values of those vars via a system property or whatever.

hiredman04:07:48

could you x = getContextClassLoader() try { setContextClassLoader(null); loadClojure(); } finally { setContextClassLoader(x); } or whatever?

cfleming04:07:09

I can’t do that unfortunately. I’m trying to use Clojure-compiled classes in IntelliJ. The classes are instantiated by IntelliJ, and I can’t set the TCCL when that happens. If a class that IntelliJ wants is compiled by Clojure and thus has an implicit RT dependency, and Clojure hasn’t been loaded yet, then I get an ExceptionInInitializerException and the class can’t load.

hiredman04:07:36

I suppose this is an effort to replace a java stub class with one generated by clojure, so suggesting a java stub class isn't going to help

cfleming04:07:45

I can do that, yes, it’s more or less what I’m doing at the moment. It’s fairly awful though, I basically end up writing manual gen-class-like classes in Java.

cfleming04:07:30

And I have to write a lot of them. I’m running a fork of Clojure, so I think I’ll just modify baseLoader()

hiredman04:07:47

you could do a custom gen-class macro too (but I bet the baseloader mod is less work)

cfleming04:07:57

Yes, no doubt.

hiredman04:07:53

on the other end of the work spectrum you could patch the class file's static initializer to do the tccl dance

cfleming04:07:51

Right, or modify my fork to change how https://dev.clojure.org/jira/browse/CLJ-1208 works. But that’s still going to be a nasty hack, and more invasive than just fixing baseLoader() I think.