Author Topic: Java Live Errors refuses to recognize some classes  (Read 2444 times)

rygaard

  • Community Member
  • Posts: 63
  • Hero Points: 1
Java Live Errors refuses to recognize some classes
« on: November 04, 2022, 08:47:08 PM »
I'm having difficulty with Java Live Errors incorrectly flagging references to certain classes as "not found".

In particular, I cannot coax Live Errors to recognize the classes in Log4J 2, and in the org.json.* package.  I suspect I have some misconfiguration, but I can't find it.  I don't have much visibility into how Live Errors works, so I'm not sure where to look.

I ran several experiments while trying to diagnose the problem with Log4J 2 on Windows using SlickEdit 27, including:
  • I included log4j-api-1.19.0.jar and log4j-core-2.19.0.jar in my CLASSPATH system environment variable, and included %(CLASSPATH) in my SlickEdit class path.  When I do this, I'm able to compile classes that reference Log4J 2 in SlickEdit using project-compile command (invoked via a keyboard shortcut) just fine.  However, all references to any class in the Log4J2 library are flagged by Live Errors.
  • I removed log4j-api-1.19.0.jar and log4j-core-2.19.0.jar from my CLASSPATH system environment variable, but I left %(CLASSPATH) in my SlickEdit class path.  I added log4j-api-1.19.0.jar and log4j-core-2.19.0.jar to the SlickEdit class path.    When I do this, I'm able to compile classes that reference Log4J 2 in SlickEdit using project-compile command (invoked via a keyboard shortcut) just fine.  However, all references to any class in the Log4J2 library are flagged by Live Errors.
  • I extracted the Log4J2 source code to a temporary directory, I removed log4j-api-1.19.0.jar and log4j-core-2.19.0.jar from my CLASSPATH system environment variable, I added the temporary directory to my CLASSPATH system environment variable, and I included %(CLASSPATH) in my SlickEdit class path.  When I do this, I'm able to compile classes that reference Log4J 2 in SlickEdit using project-compile command (invoked via a keyboard shortcut) just fine.  However, all references to any class in the Log4J2 library are flagged by Live Errors.
  • I extracted the Log4J2 source code to a temporary directory, I removed log4j-api-1.19.0.jar and log4j-core-2.19.0.jar from my CLASSPATH system environment variable, I removed the temporary directory from my CLASSPATH system environment variable, but I still included %(CLASSPATH) in my SlickEdit class path.  I added the temporary directory to my SlickEdit project.  When I do this, I'm able to compile classes that reference Log4J 2 in SlickEdit using project-compile command (invoked via a keyboard shortcut) just fine.  However, all references to any class in the Log4J2 library are flagged by Live Errors.
  • I extracted the Log4J2 source code to a temporary directory, I added log4j-api-1.19.0.jar and log4j-core-2.19.0.jar to my CLASSPATH system environment variable, I added the temporary directory to my CLASSPATH system environment variable, I included %(CLASSPATH) in my SlickEdit class path, and I added the temporary directory to my SlickEdit project.  When I do this, I'm able to compile classes that reference Log4J 2 in SlickEdit using project-compile command (invoked via a keyboard shortcut) just fine.  However, all references to any class in the Log4J2 library are flagged by Live Errors.

Any ideas?  In particular, I would like to get some visibility into what Live Errors is doing so I can better understand what is happening.  Perhaps there is some setting or feature of which I am not aware.

(edit)  I extracted the source code for Log4J 2, and created a SlickEdit tag file from it.  When I did that, SlickEdit was not able to automatically add imports for classes in the Log4J 2 library, and I was not able to navigate ( alt + . ) to the Log4J 2 source code.
« Last Edit: November 04, 2022, 09:03:25 PM by rygaard »

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Java Live Errors refuses to recognize some classes
« Reply #1 on: November 07, 2022, 04:06:53 PM »
You're probably not missing anything.  Barring bugs, Live Errors should use the exact same classpath that is used for compiling.  There is one difference in that it's not passing the classpath on the command line to the compiler, so it doesn't have to use the jar mechanism used for regular compiling to avoid command line length limits for very long classpaths.   

Since you compile fine, the only setting I can think of for you to check is the compiler being used by Live Errors, and make sure it's the same compiler being used when you compile.  An old one like 1.7 wouldn't work for log4j2 > 2.12.4.  And would probably give you other problems if it could get past that.  Look under Build -> Java Options, go to the Live Errors tab, and check the "Path to JDK 6 or later" field and make sure it's the right compiler.   

If that's not it, we'll probably have to get an idea of what options are actually making it to the compiler and see if something is not right there.


rygaard

  • Community Member
  • Posts: 63
  • Hero Points: 1
Re: Java Live Errors refuses to recognize some classes
« Reply #2 on: November 07, 2022, 05:04:13 PM »
I checked Build -> Java Options -> Live Errors -> Path to JDK 6 or later and confirmed that it is configured correctly.  I alse checked (in multiple ways) to ensure that the only Java I am using is JDK 17.

Is there some option in SlickEdit to give me more visibility into what Live Errors is doing?  I suspect I could get a good idea of what is going wrong if I knew what Live Errors is doing.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Java Live Errors refuses to recognize some classes
« Reply #3 on: November 07, 2022, 09:36:38 PM »
Live Errors keeps a JVM running (to avoid startup costs), and invokes methods on a class SlickEdit provides to kick off compilation when a syntax check needs to be done.  It gets the classpath from the same source the build tool does, so barring bugs in our environment handling, it should be the same in both cases.  It does take a separate path, so perhaps something in the Live Errors path is mangling something.
 
So we need to compare the classpath used for compilation with the classpath sent to the compiler for Live Errors.   The first we can see with the "verbose" setting in the project properties for the Build tool, but the latter I don't see a way to enable with a setting.

I've made an updated RTECompiler.class which logs all of the options sent to the Live Errors compiler to a file, including the classpath option.  I'm testing it now, and chasing down one strange thing I've seen with a -d option on one of my projects.  Once I understand why that looks different than what I expected, I'll send you the debug class with instructions on how to use it.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Java Live Errors refuses to recognize some classes
« Reply #4 on: November 07, 2022, 10:55:08 PM »
After tracing the weird paths on my windows system, I think I'm going to put in a fix for what I've found before I send you the debug class.  Seems like an odd bug that probably could only happen on windows.   I'll have to send you an updated DLL for the fix, as it's not hot-fixable.   I'll update when the DLL is ready.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Java Live Errors refuses to recognize some classes
« Reply #5 on: November 08, 2022, 02:58:16 PM »
Ok, so I fixed the path problem I noticed with logging last night.  I suspect it's not the cause of your problem, so I've also attached an updated RTECompiler.class to do extra logging for _all_ of the flags we pass to the compiler, right before Live Errors performs the compile.  So that should capture any problems with the classpath that might have been introduced on the Live Errors code path.

For the vsRTE.dll:
1) Exit SlickEdit if it is running.
2) Go to your SlickEdit install directory, go to the win directory, and rename/backup the existing vsRTE.dll
3) Copy in the vsRTE.dll that's attached to this post.
4) Restart.  See if Live Errors still complains about your Log4j2 classes.

If it does still have problems:
1) Exit SlickEdit.
2) Go to the SlickEdit install directory, and from there go to the toolconfig\rte directory.  Rename/backup the existing RTECompiler.class, and then copy in the RTECompiler.class that's attached to this post.
3) Restart SlickEdit.

Now, whenever Live Errors is triggered by an edit, the full set of compiler flags will be appended to %TEMP%\CompilerFlags.txt.   There will be one argument per line. 

I'd look at that first and check to see if the log4j2 entries are correct, and there aren't any mangled paths or odd looking compiler flags being sent.  (note: the options in the file will not include the path to the source file of the buffer it's doing a check on, like you would do running a "javac" from the command line.  We pass the buffer contents directly into the compiler API, so it doesn't appear with the other options).

Hopefully, that shows something wrong, because the alternatives are probably going to be harder to track down.   Let me know what you see, and we'll go from there.





rygaard

  • Community Member
  • Posts: 63
  • Hero Points: 1
Re: Java Live Errors refuses to recognize some classes
« Reply #6 on: November 09, 2022, 05:06:15 PM »
Patrick,

I tried the new vsRTE.dll, and it did not resolve the issue (as you suspected).

I loaded the new RTECompiler.class and reviewed the options passed to Live Errors.  I can't find anything wrong there.

My gut feeling is this is not a SlickEdit problem.  I suspect I am doing something odd without knowing it.  I'm not certain of this hypothesis because it does not explain the differences between project-compile and Live Errors.

I need to pursue this because logging calls are sprinkled through almost all of my classes, and this is negating all advantages of Live Errors.

For now, the ball is in my court.  I'll try to reproduce this in a simple project, and I'll let you know what I learn from that.

rygaard

  • Community Member
  • Posts: 63
  • Hero Points: 1
Re: Java Live Errors refuses to recognize some classes
« Reply #7 on: November 09, 2022, 08:01:59 PM »
A colleague seems to have resolved the problem.  The fix was:
  • Select the Options->Languages->Application Languages->Java->Live Error Profiles->Enable (override java compiler integration) check box,
  • Click "Apply" and "OK" to close the Options dialog box,
  • Deselect the Options->Languages->Application Languages->Java->Live Error Profiles->Enable (override java compiler integration) check box, then
  • Click "Apply" and "OK" to close the Options dialog box.

???

When I built a simple project with just one Java source file, the problem did not occur.  I built this simple project from scratch.

My gut tells me that some configuration (I have no idea what) was fouled in SlickEdit, and toggling the flag described above caused SlickEdit to re-read its configuration, thereby resolving the problem.  The fact that the problem did not recur when I built a project from scratch supports this hypothesis.
« Last Edit: November 09, 2022, 08:06:00 PM by rygaard »

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Java Live Errors refuses to recognize some classes
« Reply #8 on: November 09, 2022, 08:47:55 PM »
Hmm, I'm not sure.  Toggling that would make it re-read some of the configuration as the Java Live Error thread is stopped and started, but that would also happen on when exiting and restarting the editor.  I didn't think it worked for you after the editor was restarted.

I'll double check what the code does with that switch though, maybe there's some initialization detail I'm forgetting.

rygaard

  • Community Member
  • Posts: 63
  • Hero Points: 1
Re: Java Live Errors refuses to recognize some classes
« Reply #9 on: January 02, 2023, 06:55:15 PM »
For some reason, this problem returned.  This time, I can't get it repaired.

Any suggestions would be most appreciated.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Java Live Errors refuses to recognize some classes
« Reply #10 on: January 02, 2023, 08:03:54 PM »
If you've updated to 27.0.1, you can turn on the live errors logging by running "rte-enable-logging" at the SlickEdit command line.  Once you've done that, open the project and edit a file that has one of the classes that the java compiler is complaining about not finding. 

The log file will under your Configuration Directory, logs/rte.log.  Help About will show you where your Configuration Directory is on your system.  Bring up that log file.  There will be a line that has "java compiler options", below that will be all of the options passed to java compiler.  Take a look at that, and see if any options are missing, or if the classpath doesn't have correct paths for whatever jar contains the classes that aren't being found. 

rygaard

  • Community Member
  • Posts: 63
  • Hero Points: 1
Re: Java Live Errors refuses to recognize some classes
« Reply #11 on: January 13, 2023, 07:19:08 PM »
First:  Thanks for adding the logging flag to the product!   ;D

Second:  I reviewed the logs and noticed something interesting in the class path used for live errors.

In my system CLASSPATH environment variable, I list the log4j libraries with a fully qualified path and a wildcard, e.g. ...;C:\MyProject\oss\log4j\*;...

In the logs, this is expanded to, e.g., ...;oss\log4j\log4j-api-2.19.0.jar;oss\log4j\log4j-core-2.19.0.jar;oss\log4j\log4j-jul-2.19.0.jar;...

It appears that SlickEdit has changed it from an absolute path (C:\MyProject\oss\log4j\) to a relative path (oss\log4j\).  If SlickEdit does not run the javac command from my project root directory, then these relative paths would be a problem.  Could this explain what I am seeing?

BTW, I would prefer SlickEdit didn't munge my classpath this way (I understand that some changes are needed to address command length issues, but this particular change seems unnecessary and possibly problematic).

Third:  Is there a command to turn off Live Errors logging?

rygaard

  • Community Member
  • Posts: 63
  • Hero Points: 1
Re: Java Live Errors refuses to recognize some classes
« Reply #12 on: January 14, 2023, 08:58:56 AM »
Some additional information:  This bug seems to come and go at random times.  Everything will be fine for a while, then for no apparent reason, this bug will re-appear.  I'll continue editing for a while with the bug (at a significantly reduced pace), and then the bug will disappear, again for no apparent reason.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Java Live Errors refuses to recognize some classes
« Reply #13 on: January 16, 2023, 02:48:40 PM »
I'll look at the expansion to see about the relative paths there later today - I suspect there's a bug where it's doing that wrongly in this case, as the relative path is only on requirement in the dependency jar case.  Definitely not needed for Live Errors.  In fact, it's probably incorrect to give it relative paths, as Live Errors isn't in a position where it can freely mess around with the CWD.   

When you get the error, is it for classes contained by one of these jars that's in your CLASSPATH variable?   

rygaard

  • Community Member
  • Posts: 63
  • Hero Points: 1
Re: Java Live Errors refuses to recognize some classes
« Reply #14 on: January 18, 2023, 09:04:03 PM »
@patrick:

Yes.  Live Errors is flagging classes in Log4J as unknown, and the Log4J JARs are the ones whose paths are converted to relative.  I should have said that in my post.