static initialisation of javafx.stage.Screen causing problems with clojure

Peter Levart peter.levart at
Mon Mar 25 15:41:23 UTC 2019

Hi Razvan,

I don't know Clojure but if this happens during compilation of Clojure 
source(s) (in clojure.lang.Compile), then the question is: Does Clojure 
compiler really need to execute static initializers of classes it is 
"resolving"? It seems it needs to load the classes (presumably because 
it is using Java reflection to introspect them), but does it really need 
to initialize the classes?

If it only needs to introspect the classes (but not execute constructors 
or methods in them or access fields), then it should be using the 3-arg 
Class.forName() method:

      public static Class<?> forName(String name, boolean initialize, 
ClassLoader loader)

...passing 'false' as the 2nd argument. That way the "resolved" classes 
would be loaded but not initialized. Clojure compiler could still 
introspect them, but no code in classes would be executed. This would be 
much safer.

Regards, Peter

On 3/24/19 3:16 PM, Răzvan Rotaru wrote:
> Hi,
> I am trying to use OpenJFX 11.0.2 (for Linux) with Clojure and
>, and stumbled upon a problem for which I
> would like to ask for advice here. The Problem occurs during compilation of
> some clojure code, which triggers class loading for javafx.stage.Screen,
> which fails with following stack trace (only the relevant part):
> java.lang.IllegalStateException: This operation is permitted on the event
> thread only; currentThread = main
>      at
>      at
>      at
>      at javafx.stage.Screen.<clinit>(
>      at java.base/java.lang.Class.forName0(Native Method)
>      at java.base/java.lang.Class.forName(
>      at clojure.lang.RT.classForName(
>      at clojure.lang.RT.classForName(
>      at clojure.lang.Compiler.resolveIn(
>      at clojure.lang.Compiler.resolve(
>      at clojure.lang.Compiler.analyzeSymbol(
>      at clojure.lang.Compiler.analyze(
>      at clojure.lang.Compiler.analyze(
>      at clojure.lang.Compiler$InvokeExpr.parse(
> Being only compilation, there should be no Toolkit initialisation, hence no
> event thread. Looking at the code it seems that the Screen class can only
> be loaded from the event thread. Is this a bug or the intended behaviour?
> Is there a way around this for my use case? How does OpenJFX ensure that
> Screen is always loaded on the correct thread?
> Related bug in fn-fx:
> Cheers,
> Răzvan

More information about the openjfx-dev mailing list