1

I have established through another question that the problem I'm having with my JavaFX program is due to a bug in the JDK that is not going to be fixed anytime soon. I was even informed that the bug is in PrismTextLayout.

So having found the source code for this, how would I implement some kind of patch which would allow me to fix this bug for my application only. Obviously if I did fix the problem, I would contribute it back to a future JDK, but for now I just want a quick fix.

I thought a simple google search for patching the JDK, etc would turn up heaps of information, but actually, virutally nothing.

Can someone, if not explain how to patch, at least point me in the right direction for some documentation on this subject.

Grant Birchmeier
  • 17,809
  • 11
  • 63
  • 98
blissweb
  • 3,037
  • 3
  • 22
  • 33
  • Fix the bug, compile the class(es), replace it/them in the `rt.jar` file of you Java installation. Or see [here](http://stackoverflow.com/a/12119945/5221149) – Andreas Dec 31 '16 at 03:57
  • There are build instructions for openJFX [here](https://wiki.openjdk.java.net/display/OpenJFX/Building+OpenJFX): they (of course) vary by platform and if you want to distribute your application for multiple platforms, you will need to build a version for each. I do not know what licensing requirements there are on you if you distribute an application with a modified JFX base. – James_D Dec 31 '16 at 04:03
  • 2
    @Andreas You're wrong. JavaFX is not part of `rt.jar`, it is bundled with the Oracle Java distributions as a separate jar file. – James_D Dec 31 '16 at 04:04
  • 1
    To me this question feels like an off-topic question on StackOverflow. I will vote to close the question but not before passing some information to you. In order to build your own patch, you need to hack on the [OpenJFX](http://openjdk.java.net/projects/openjfx/) code base. Once, you are happy with the result, you can build the `jfxrt.jar` and replace it in your JDK. To [contribute back](http://openjdk.java.net/contribute/) to the OpenJDK, you need to follow a long process. You can with the [Adopt OpenJDK](https://java.net/projects/adoptopenjdk/pages/AdoptOpenJDK) program. – ItachiUchiha Dec 31 '16 at 04:08
  • 1
    @James_D You're right, of course. For JavaFX, replace class(es) in `.../lib/ext/jfxrt.jar`. – Andreas Dec 31 '16 at 04:09

1 Answers1

1

Patching a JavaFX class without actually building the whole JDK or JavaFX is quite easy. I did that for example for the class SVGPath some time ago.

  1. Extract the class source from the source zip which is distributed with the JDK and add it to your project in the correct folder according to its package name. In my case this would be javafx/scene/shape/SVGPath.java.
  2. Explicitly add ${JDK_HOME}/jre/lib/ext/jfxrt.jar to your classpath.
  3. Run your program with the java options "-Djava.ext.dirs=". This procedure is essential to be able to override the existing classes in jfxrt.jar.

That is it.

mipa
  • 10,369
  • 2
  • 16
  • 35
  • Another way would be to replace some code with ASM or BCEL before loading that classfile, then loading it into the classloader, but this has to be done before using that class. As the extension mechanism will [be dropped in JDK9](https://bugs.openjdk.java.net/browse/JDK-8065702), I would not suggest the usage of `-Djava.ext.dirs=`, see [JEP-220](http://openjdk.java.net/jeps/220) or [this blog-post](http://blog.codefx.org/java/dev/how-java-9-and-project-jigsaw-may-break-your-code/) – FibreFoX Jan 01 '17 at 12:58
  • My answer is valid up to verson 8 of Java. With Java 9 everything changes and this issue needs further investigation. – mipa Jan 01 '17 at 19:05