Author Topic: Java Modules, Java FX, and Live Errors  (Read 249 times)

rygaard

  • Community Member
  • Posts: 44
  • Hero Points: 0
Java Modules, Java FX, and Live Errors
« on: September 12, 2022, 10:51:30 pm »
I'm having difficulty with Java 17's modules, FX, and SlickEdit's live errors.

I'm building an application that uses Java FX extensively in Java 17.  In order to compile FX code, the options

   --module-path "C:\Program Files\Java\javafx-jmods-17.0.2" --add-modules javafx.controls,javafx.web,javafx.swing

must be included on the javac command line.  I have added these command-line options to the Build -> Java Options -> Compiler -> Other Options text field, and I am able to compile within SlickEdit.  However, I seem to be having difficulty getting Live Errors to use these options:
  • If I select the Build -> Java Options -> Live Errors -> Use "Other Options" from Compiler Tab checkbox, then Live Errors quits working, and I can't find any indication of why.
  • If I deselect the Build -> Java Options -> Live Errors -> Use "Other Options" from Compiler Tab checkbox, then Live Errors flags every reference to FX classes as "Symbol not found" or "Package does not exist".  This is the behavior I would expect if the command-line options are not included.

My code compiles okay outside of SlickEdit, so I don't think it is a coding error.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1742
  • Hero Points: 147
Re: Java Modules, Java FX, and Live Errors
« Reply #1 on: September 13, 2022, 03:22:55 pm »
It should log an error in Message List if something has gone wrong.  But looking at the code that calls the compiler, I did find one place where errors that are not standard diagnostics would not be sent back to the editor, which isn't right.  I've attached an updated class that fixes that.  To apply it:

1) Exit SlickEdit
2) copy the attached RTECompiler.class file to YOUR_INSTALL_DIR\toolconfig\rte, overwriting the file that's already there.
3) Restart SlickEdit.

Go ahead and restart your project.  Give it a few seconds, and then check the Message List tool window for a error message.   (the message will very likely not be associated with a source file, so you have to look in the tool window rather than look for highlights in the source files).

Hopefully there will be an error message, and it will give us a direction to go in.


patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1742
  • Hero Points: 147
Re: Java Modules, Java FX, and Live Errors
« Reply #2 on: September 13, 2022, 04:07:27 pm »
Update: I found one more place where an error can't be communicated, when an option isn't recognized by the compiler.   I found this by having the wrong JDK level for my Live Errors setup.

Attached is updated RTECompiler.class.

I made a quick project with JavaFX and openjdk 17, and I can get Live errors to resolve the module packages, so it can work.  There's just some problem that isn't being reported by the original RTECompiler.class.





rygaard

  • Community Member
  • Posts: 44
  • Hero Points: 0
Re: Java Modules, Java FX, and Live Errors
« Reply #3 on: September 17, 2022, 03:32:11 am »
You gave me some hints about where to look, and this is what I found:
  • The Build->Java Options->Compiler->Other options field has --module-path "C:\Program Files\Java\javafx-jmods-17.0.2" --add-modules javafx.controls,javafx.web,javafx.swing
  • When I select Build->Java Options->Compiler->Live Errors->Use "Other Options" from Compiler Tab check box, the Message List window has only one error:  Unrecognized option: Files\Java\javafx-jmods-17.0.2"

So it looks like some process is not handling quoted options properly.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1742
  • Hero Points: 147
Re: Java Modules, Java FX, and Live Errors
« Reply #4 on: September 17, 2022, 04:12:19 pm »
Oddly enough, the arguments are getting to the compiler harness intact, but the code there is not honoring any quotes put around the path with the spaces in it when breaking the arguments down for the compiler API.   I'll post an updated RTECompiler.class when I've fixed it.


patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1742
  • Hero Points: 147
Re: Java Modules, Java FX, and Live Errors
« Reply #5 on: September 17, 2022, 05:29:24 pm »
Fixed, it will parse quoted paths with spaces in them correctly now for the "Other Options" entries.  It seems to have only been a problem with the Other Options entries.

I've attached a updated RTECompiler.class

rygaard

  • Community Member
  • Posts: 44
  • Hero Points: 0
Re: Java Modules, Java FX, and Live Errors
« Reply #6 on: September 19, 2022, 11:41:37 pm »
Woo hoo!   ;D

That worked like a charm.

rygaard

  • Community Member
  • Posts: 44
  • Hero Points: 0
Re: Java Modules, Java FX, and Live Errors
« Reply #7 on: September 23, 2022, 03:59:04 am »
Well, I celebrated too soon...  It appears that with Live Errors, the compile process proceeds part way, and then errors out.

To review:
  • In Build->Java Options->Compiler->Other Options, I am using these options:
       --module-path "C:\Program Files\Java\javafx-sdk-17.0.2\lib" --add-modules javafx.controls,javafx.web,javafx.swing
  • In Build->Java Options->Live Errors, I have selected the Use "Other Options" from Compiler Tab check box.
  • I'm having difficulty with Live Errors

With the above setup, certain types of errors are being highlighted by Live Errors, but not all.  For example:
  • If I type gibberish text, it will get flagged
  • Most syntax errors get flagged
  • If I don't declare a variable type, it will not get flagged
  • If I don't declare a thrown exception, it will not get flagged
The Java compiler is a multi-pass compiler, so I am guessing that the early passes are working normally, but a later pass fails.

When I activate Live Errors (e.g. type a character and delete it), (a) the Output tab shows nothing, and (b) my Message List tab might have some legitimately flagged errors, but these are always the last three errors:
  • module not found: javafx.swing
  • module not found: javafx.controls
  • module not found: javafx.web

I've spent a lot of time checking the options I put into Build->Java Options->Compiler->Other Options, and comparing them to what I use successfully when I use javac on the command line, so I don't think that is the problem.

I tried a couple of experiments at the system command line:
Quote
C:\Directory\to\Project\and\module>javac --module-path "C:\Program Files\Java\javafx-sdk-17.0.2\lib" --add-modules javafx.controls,javafx.web,javafx.swing KnownGoodCode.java

C:\Directory\to\Project\and\module>javac --module-path "C:\Program Files\Java\javafx-sdk-17.0.2\libx" --add-modules javafx.controls,javafx.web,javafx.swing KnownGoodCode.java
error: module not found: javafx.swing
error: module not found: javafx.controls
error: module not found: javafx.web
3 errors

C:\Directory\to\Project\and\module>
(Notice the bogus path in the second command issued)

I don't have much visibility into the issue, so I can't give you much more help.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1742
  • Hero Points: 147
Re: Java Modules, Java FX, and Live Errors
« Reply #8 on: September 23, 2022, 01:12:41 pm »
For the unflagged errors, you are right, those are errors happening in a later pass that isn't being reached because of the module errors.  (I tried it here with bad module names to verify). Syntax and lexical problems tend to always get caught as they are the first stages before any semantic work gets done.

For the modules not found, I'm not 100% sure, but I found a bug in the last fix I made that's probably the culprit.   Try the RTECompiler class attached to this reply, and let me know if it works.    (that bug was a helpful reminder that it's been quite a while since I did real Java programming).



rygaard

  • Community Member
  • Posts: 44
  • Hero Points: 0
Re: Java Modules, Java FX, and Live Errors
« Reply #9 on: September 23, 2022, 02:31:18 pm »
I'm working with it now.  It looks promising :D

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1742
  • Hero Points: 147
Re: Java Modules, Java FX, and Live Errors
« Reply #10 on: September 23, 2022, 05:19:24 pm »
Good. I've made some additional changes to clean up the handling and add some logging for "should not happen" cases, which I'm testing.  I'll post the updated version when it's ready.  What you're using is fine for your "other options" list, so there's no rush for you to update once I do post it.