16

There is a bug in JFX which often manifests when calculating screen co-ordinates https://bugs.openjdk.java.net/browse/JDK-8194727 and https://bugs.openjdk.java.net/browse/JDK-8190400

I've tracked the problem down to the implementation of GeneralTransform3D, which is part of the javajfx runtime.

I've submitted a bug report to Oracle, but until it is accepted, fixed, and makes it to a release, I need a way of fixing my application.

In java 8 i was able to create a jar containing a fixed version of the class and install it in the lib/ext folder. This seemed to work and the JFX implementation used my impl over its own.

In java 10 the extension mechanism has been removed. Adding the patch jar to the classpath doesn't work as it is too late in the classloading process.

Is there a way to override/patch an implementation of the core java classes in Java 10?

Note that i'm not using this class directly, it is used by the framework

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
jambit
  • 313
  • 1
  • 8
  • If it is available then you could modify the framework so that all references to the broken core java classes will instead use your correct class..... But that is a very messy solution. – sorifiend Jun 13 '18 at 01:05
  • 2
    Did you happen to explore the [patch module content](http://openjdk.java.net/jeps/261#Patching-module-content) option? – Naman Jun 13 '18 at 01:44
  • thanks @nullpointer [patch module](http://openjdk.java.net/jeps/261#Patching-module-content) looks interesting, but i have a solution working using java agents. I do note that they say _The --patch-module option is intended only for testing and debugging. Its use in production settings is strongly discouraged_. But they'd probably also say that about what i am doing with the java agent – jambit Jun 13 '18 at 19:55
  • 6
    `--patch-module javafx.runtime=patch.jar` is the right way to override classes in this module. Using agents is a bit crazy in this case. BTW: Using the ext directory with JDK 8 was fragile in this case because it was random if the JAR file with the patches is located first. – Alan Bateman Jun 14 '18 at 04:52

3 Answers3

5

Once again, Alan gives the best answer as a comment. :) Quote:

--patch-module javafx.runtime=patch.jar is the right way to override classes in this module

If you need to "override" a class in a platform module, use --patch-module to do that. If that drags in additional dependencies, make sure to make them readable with --add-reads.

Nicolai Parlog
  • 47,972
  • 24
  • 125
  • 255
  • 1
    i'll go with this as my solution since it was recommended by [Alan Bateman](https://stackoverflow.com/users/7463126/alan-bateman) and is definitely easier than the java agent solution that i had. I should note that i had to use `javafx.graphics` rather than `javafx.runtime`. I'm on java 10 if that makes a difference. – jambit Jun 17 '18 at 22:13
2

I needed to do this but I was launching Java from C through the JNI interface (instead of the command line). Just transposing the command line args to JavaVMOptions didn't work. Instead it all goes in one arg as follows:

JavaVMOption options[N_ARGS] = { 0 };
options[0].optionString = "--patch-module=javafx.runtime=patch.jar";

It took a lot of digging to figure this out, so hope it saves someone else some time.

theothertom
  • 141
  • 2
  • 3
1

Looks like a solution is possible using java agents, as per this question

Replace a class within the Java class library with a custom version

jambit
  • 313
  • 1
  • 8