-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make RichTextFX work on Java 9 #270
Comments
http://blog.codefx.org/java/dev/javafx-project-jigsaw-jep-253/ tl; dr; Should be possible, but not without refactoring and releasing new major version of RichTextFX. |
Aye, and a new release for all of its dependencies: Flowless, ReactFX, UndoFX, WellBehavedFX. |
I have started a Java9 branch at https://github.com/afester/RichTextFX/tree/Java9. This branch contains the required changes to make the code compilable with Due to the enhanced jigsaw authorization mechanisms at runtime, the following command line parameters are currently required to launch the demo applications (I only tried the JavaKeywords demo so far):
Without these, the application will throw The demo can then be launched, but there is still a rendering issue - the rich text is only partially rendered in the view. When clicking into a particular line, that line is then properly rendered. This might also be an issue of the FlowLess or other component - I have NOT recompiled any other dependency with Java 9 so far. |
I'll probably be looking into this more as we get closer to Java 9's release. |
Here's something to think about: how should this project be modulated? How many modules should there be and what components should be within each one? Which ones will be required and which are optional? |
Could anyone say if richtextfx can be used on Java 9? I cloned master branch but can't build it as I get |
RichTextFX does not work on Java 9 yet. We're 1 issue away from releasing the |
@JordanMartinez Thank you very much for the information. Can you say when approximately RichTextFX will be ready for Java 9? |
@PashaTurok I'd like to have it done within two weeks at the very latest, but it depends. I hope to follow the same approach I used in TestFX (see #593 where I mention it there), so that we can share the code base as much as possible between the two different versions of Java. I'm not sure how easy/hard that will be. |
I've been thinking more about this. When I initially submitted my PR to TestFX to make it support Java 9, we didn't know that the Java release cycle would increased in speed to only 6 months ish. Now that we do know that, I wonder if Java 8 people will be forced to upgrade sooner (in a few months) rather than later (in a few years), making the dual support for both versions somewhat pointless after a while. My idea is not to ignore Java 8 completely. Rather, I think we should duplicate our current project and then modify the duplicate to work on Java 9. I know it will take longer to submit PRs if we want to change a single thing in the project, but it does allow immediate trouble-free access to Java 9 support. My only question is how to distinguish the release versions from a Java 8 and 9 build. Thoughts? |
@JordanMartinez Could you explain what you mean |
@PashaTurok See this blog post "Moving Java Forward Faster" by Mark Reinhold the Chief Architect of the Java Platform Group at Oracle where he specifically talks about this. |
@JordanMartinez I would not duplicate the project. I would propose
Probably not. Not sure who uses RichTextFX besides the projects listed on the wiki, but often enough people still use older versions for a rather long time, probably even through special maintenance agreements. Then, there are also long term support releases. See also |
Good point. In that case, we'll stick with the adapter approach. I think I was focusing too much on how to support Java 9 quickly (i.e. duplicate code, merge #593, we're done) rather than thoughtfully. When I started to work through how the codebase would need to be split up to support 8 and 9 at once, it required three different modules due to |
I basically second @afester 's proposal as well, with the following notes for the second option: I think its possible to compile both the Java 8 and 9 code together (modules aren't needed at first), and to then package them together in a single multi-release jar. This can be done by putting the Java 9 code into its own folder say "java9" (inside "richtextfx/src" or "main" ?) It'll have its own appropriate build.gradle file with for example sourceCompatibility = '1.9' (or 9?) and no jar entry. The 'Multi-Release': true attribute needs to be added to the richtextfx jar { manifest section, as well as any needed 'Add-Opens' attribute entries such as 'java.base/java.lang'. Then somehow the Java 9 classes need to be included in the jar file under META-INF/versions/9 Not sure if this will help but here is a maven example. |
Why no use reflection to fix the JavaFX incompatibilities in RichTextFX? This does not require any change to the structure of the code base or to the build system and results in a single JAR that works with Java 8 and 9+. Personally, I use some kind of "compatibility" classes (e.g. class JavaFXCompatibility
{
/**
* Java 8: javafx.scene.layout.GridPane.impl_getCellBounds( int columnIndex, int rowIndex )
* Java 9+: javafx.scene.layout.GridPane.getCellBounds( int columnIndex, int rowIndex )
*/
static Bounds GridPane_getCellBounds( GridPane gridPane, int columnIndex, int rowIndex ) {
try {
if( mGridPane_getCellBounds == null ) {
mGridPane_getCellBounds = GridPane.class.getMethod(
JavaVersion.IS_JAVA_9_OR_LATER ? "getCellBounds" : "impl_getCellBounds",
int.class, int.class );
}
return (Bounds) mGridPane_getCellBounds.invoke( gridPane, columnIndex, rowIndex );
} catch( NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex ) {
throw new Error(ex);
}
}
private static Method mGridPane_getCellBounds;
} I compiled RichTextFX core (without demos and tests) with Java 9 and found out that there are 3 kinds of incompatibilities:
1st and 2nd could be solved with reflection (similar to above example). For 3rd, the solution in #593 for JavaFX 9 could be adapted so that it also works for JavaFX 8. #593 uses some new JavaFX 9 methods in |
@Jugen Thanks for your input. I've been waiting for The Java Module System to release a chapter on multi-release JARs. I'll look at your example when I have time (hopefully later this week). @JFormDesigner Good points, too. What are the down sides to using reflection as opposed to accessing things directly? We currently use reflection to get the Otherwise, it seems that this questions has become: "Do we use a 3-module project structure to build a Java 8 and 9 version of the code? Or just reflection + #593? What are the pros/cons of each and which is the best direction for this project?" |
BTW (for those that may not know :) the module system and multi-release jar files are two separate things that are mostly independent of one another. Multi-Release JAR Files are really very simple requiring only two steps:
Multi-release jar files are backwards compatible so any previous JRE will have no trouble with them :-) |
Historically reflection is regarded as a last resort if there is no other way for two reasons:
There are I think two advantages for going the reflection route:
All that being said though if it cannot ALL be done with reflection then imho it shouldn't be done at all, and the three classes mentioned by @JFormDesigner should be duplicated and every method in the Java 8 class documented to YELL that there's a Java 9 copy and its location :-) |
😭 I didn't know! lol!
If we won't be releasing a multi-release jar, then how should a Java 8 release differ from a Java 9 release? In other words, how will the release versions be different? Will it be "Major.Minor.Patch-Java8" and its 9 counterpart?
In that case, would someone be willing to submit a PR using the reflection approach? I still plan to release the |
Since I suggested reflection, I think I have to do it.. Have already rebased Mario's commit from #593 to current master and will continue there... Here is the branch: |
If the reflection route works then there'll only be one release, compiled with Java 8 but it'll also work in Java 9 :-) |
Really? How then do you deal with the |
Yip, Java 9 does not enforce the use of modules yet, it's optional :-), so the Any access right runtime flags will only be needed if API is being used that is not visible by default, in which case the 'flags' can be included in the main executable jar file without Java 8 complaining. There are two (flags) attributes:
The value of each attribute is a space-separated list of slash-separated module-name/package-name pairs. |
Good to know. And it's also important to highlight the word yet.
So, if I build a Java 9 library and it uses a reflection-based compiled RTFX as its dependency, which won't have its own I appreciate the PR you've submitted and the work you've done. I think the reflection approach is the easiest and fastest way to add support for Java 9 in a short time. However, I don't think it's the best long-term approach. Eventually, it seems that we will need to either migrate it to a more modular approach like what I did in TestFX (if we want to continue supporting Java 8) or continue with @afester's first approach (freezing the Java 8 branch and including development on Java 9 only). Regardless, I don't want you to feel like you went through all that work for nothing. I realize that the migration to Java 9 will be itself a process, not an immediate step. So, part of me does want to "please you" by saying, "let's just use the reflection approach because it adds support for Java 9 so quickly (all we need to do is merge your PR and make a new release)." However, acknowledging that temptation within myself, I also realize that this approach, if taken, probably won't be the one we end with. I acknowledge that that is ok, since the migration will be a process. Still, if that's the case, I must ask, "Should it still be the route we take?" While we could use @afester's first approach, the flaw there (as already stated) is the fact that some people who won't or can't upgrade may still need Java 8 support and additional bug fixes / enhancements. If we use the approach I did in TestFX, it requires messing with the build file for a bit and modulating the code across multiple (dare I say "boilerplate?") directories. To summarize the pros and cons, let's use this table. If you find there are things missing, things that need to be corrected, or it doesn't fairly represent each route, please make note of it, so I can fix it. Considering the below, which route does the community want to go?
Personally, I'm favoring a "Use the reflection approach now just to add Java 9 support and migrate to the 'boilerplate' approach later on." |
No, you only need the flags at runtime and it seems only when accessing the API directly but not when it's via reflection. (So the table above can be updated accordingly ;-) Ok, so there's good news and then there's bad news ..... The good news first is that as you've probably seen @JFormDesigner's reflection PR is working :-). The JRE just writes a warning message to the console (but otherwise there's no Exceptions or misbehavior):
More good news is that Now the BAD news is that TextFlowExt depends heavily on the offending TextLayout which it has ALWAYS obtained through reflection because BTW the reflection that is being done via JavaFXCompatibility are none issues, because they are accessing public API, so Java 9 doesn't get indigestion from it. |
What do I update? When I looked at the table, I realize that I forgot to add the
I'm assuming this is in regard to Java make a new release, correct? Yes, we have yet to see whether they hold true to their 6-month cycle update or whether it's just words again.
Thanks for the clarification. Since I see that the table comment above got 3 likes and no one else has said anything in regards to not using the "reflection + multi-release jar" approach, am I correct in understanding that this is the direction we wish to go, at least for now? |
I think just change to may Yip, it seems like just using reflection for now and then maybe later on if needed use multi-release jars. |
Done. |
As noted in TestFX/TestFX#433's comment, a person is discouraging the usage of multi-release jars. I've opened an issue in that repo: melix/mrjar-gradle#1 |
Just FYI. Someone extended the experimental Java 9 plugin for Gradle via Chainsaw |
@JordanMartinez Hello dear friends , i am in love with this RichTextFX and i am using it on my projects , now i have passed most of them to Java 9 and the only problem i have is with RichTextFX . Please how i can help on fixing that ? Is there any solution . I have read most of the posts you have in this page . JFoenix and ControlsFX have elegantly released versions for both Java 9 and Java 8. Waiting for response :) Java 10 is about to be released . |
There shouldn't be any problem using RTFX in / with Java 9. It just complains about the illegal reflection but otherwise should work. If you are having a problem please open an issue detailing the problem you are having, and hopefully somebody will be able to help / guide you. We don't currently have a solution for the use of |
@goxr3plus What specifically is the problem you are experiencing? AFAIK, RichTextFX will stop working in JDK 10 because the reflection approach we're using will no longer be allowed. (I could be wrong about that.) I haven't submitted a fix to OpenJFX to expose what we need as public (or whatever other API changes that are needed) because they're still figuring out a better way to streamline changes on the openjfx-dev mailing list (see the threads by month: Feb, March). |
@Jugen @JordanMartinez Yes you are right :) . I was doing something wrong in other classes i just figured it out now . The whole project runs well except these warning as you mentioned . I hope we can move RichTextFX successfully to Java 10 and beyond :) WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.fxmisc.richtext.TextFlowExt (file:/C:/Users/GOXR3PLUSSTUDIO/.m2/repository/org/fxmisc/richtext/richtextfx/0.8.2/richtextfx-0.8.2.jar) to method javafx.scene.text.TextFlow.getTextLayout()
WARNING: Please consider reporting this to the maintainers of org.fxmisc.richtext.TextFlowExt
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release |
Since we might need this sooner rather than later with Java 10 almost upon us (and 11 is scheduled for later this year !?) I've almost finished a Java 9 and up only version of Just have to do the |
@Jugen I'd like to respond to your comment, but it's getting outside of the scope of this issue. Can you repost what you've written here in a new issue with something like "Make RichTextFX work on Java 10" or something? RichTextFX does work on Java 9, so this issue is closed. |
Since RichTextFX seems to work on Java 10, my version isn't needed yet, so I'm shelving it for now and will check again for Java 11. |
Oh, it does work on 10? That's good to hear. Perhaps by Java 11 the OpenJFX process will be figured out and the accessibility of TextLayout-related things will be resolved. |
Now can I use RichTextFX on Java 9 without any problems? With ignore the warning? |
@saifalmutory Yes, it does work on Java 9. You'll need to pass some runtime args though. If you examine the |
Given that RichTextFX uses private APIs in JavaFX 8, will the current functionality provided by RichTextFX be possible under JavaFX 9?
The text was updated successfully, but these errors were encountered: