Skip to content
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

Fails with java 19 #29

Closed
vscaemh opened this issue Jan 5, 2024 · 12 comments · Fixed by #31 or #30
Closed

Fails with java 19 #29

vscaemh opened this issue Jan 5, 2024 · 12 comments · Fixed by #31 or #30

Comments

@vscaemh
Copy link

vscaemh commented Jan 5, 2024

Hi Nick :)

Hope all is well!

I just tried vdmcheck and it fails for java 19. It works with java 17.
In java 19 I get this error:

$ java -jar vdmcheck2.jar ~/source/bitbucket_ts/appfmu/appfmu/modelDescription.xml
Checking XML
Exception in thread "main" java.lang.IncompatibleClassChangeError: class com.fujitsu.vdmj.scheduler.SchedulableThread overrides final method java.lang.Thread.isVirtual()Z
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        at com.fujitsu.vdmj.VDMSL.getInterpreter(VDMSL.java:318)
        at com.fujitsu.vdmj.VDMSL.interpret(VDMSL.java:228)
        at com.fujitsu.vdmj.VDMJ.main(VDMJ.java:429)

The vdmcheck2.sh script does not seem to work in general.
For java 19:

./VDMCheck2.sh ~/source/bitbucket_ts/appfmu/appfmu/modelDescription.xml
Checking XML
Error: Could not find or load main class com.fujitsu.vdmj.VDMJ
Caused by: java.lang.ClassNotFoundException: com.fujitsu.vdmj.VDMJ

For java 17:

./VDMCheck2.sh ~/source/bitbucket_ts/appfmu/appfmu/modelDescription.xml
Checking XML
Error: Could not find or load main class com.fujitsu.vdmj.VDMJ
Caused by: java.lang.ClassNotFoundException: com.fujitsu.vdmj.VDMJ

Cheers,
Casper

@nickbattle
Copy link
Collaborator

Yes, this is a known issue caused by Java 19. See overturetool/vdm-vscode#196. It should be fine with later version of VDMJ or earlier versions of Java :)

I'll look at changing the VDMCheck build to use a later VDMJ - but that would have to be a snapshot version.

@nickbattle
Copy link
Collaborator

It looks like @lausdahl has made some changes in the VDMCheck development branch already, so it's possible that we can tweak the VDMJ version(s) from 4.4.6 to 4.5.0-SNAPSHOT and try it. There is a version of that snapshot in Maven Central (uploaded Nov 24th), which should contain the fix.

@nickbattle
Copy link
Collaborator

This didn't quite work because there is a local version of the ClassMapper (long story). But I've just pushed a tweak to that class and the top level POM to change the VDMJ versions. The package does now build. I'll try to attach a ZIP.

FMI2-vdmcheck-1.1.3-SNAPSHOT-distribution.zip

Can you try that?

@lausdahl
Copy link
Contributor

lausdahl commented Jan 5, 2024

Once a new snapshot of vdmj is pushed it should be possible to test with the repo. The local version of the class mapper is now removed

@vscaemh
Copy link
Author

vscaemh commented Jan 5, 2024

Hi.
Awesome @nickbattle @lausdahl - quick reaction as always ;)
vdmcheck2.jar works on java 19 now.

same story with the shell script:

Checking XML
Error: Could not find or load main class com.fujitsu.vdmj.VDMJ
Caused by: java.lang.ClassNotFoundException: com.fujitsu.vdmj.VDMJ

Can you make a version that fixes my modelDescription file as well? :D

@nickbattle
Copy link
Collaborator

A new snapshot has now been deployed to Maven Central for VDMJ.

Regarding the script, it still works fine here, for FMUs or XML files. How are you calling it? What OS are you using?

For me on Linux, I unzip the distribution ZIP somewhere, add that folder to my $PATH and then cd to somewhere that has an *.fmu or *.xml file. So which VDMCheck2.sh will show the path to where I unzipped it. Your error suggests it's somehow confused about where the jars are located or the file permissions prevent it (hence can't load the VDMJ class).

If this doesn't explain it, can you run VDMCheck with "bash -x" so we can see what it's doing? The important part is:

Checking XML
++ which VDMCheck2.sh
+ path=/home/nick/vdmcheck-1.1.3-SNAPSHOT/VDMCheck2.sh
++ dirname /home/nick/vdmcheck-1.1.3-SNAPSHOT/VDMCheck2.sh
+ dir=/home/nick/vdmcheck-1.1.3-SNAPSHOT
+ cd /home/nick/vdmcheck-1.1.3-SNAPSHOT
+ VAR=model7843
+ INXSD=schema/fmi2.xsd
+ type java
+ java -jar xsd2vdm.jar -xsd schema/fmi2.xsd -xml /tmp/xml7843.xml -name model7843 -vdm /tmp/vdm7843.vdmsl -nowarn
++ basename /tmp/xml7843.xml
+ BASE=xml7843.xml
+ sed -i -e s+xml7843.xml+XML+g /tmp/vdm7843.vdmsl
+ java -Xmx1g -cp vdmj.jar:annotations.jar com.fujitsu.vdmj.VDMJ -vdmsl -q -annotations -e 'isValidFMIConfiguration(model7843)' model /tmp/vdm7843.vdmsl

@vscaemh
Copy link
Author

vscaemh commented Jan 5, 2024

Windows and a single xml file.

Firstly, I forgot to pass -x. But I have corrected that.

Mime-type is lost
These lines https://github.com/INTO-CPS-Association/FMI-VDM-Model/blob/development/fmi2/vdmcheck/src/main/scripts/VDMCheck2.sh#L69-L71
makes the mime type of INXML text/plain.
The original mime type of my file is text/xml.

Makes a file with mime type text/plain.

I wrestled with it a bit, and I end up with the same error:

Checking XML
++ which ./VDMCheck2.sh
+ path=/c/Users/caemh/Downloads/vdmcheck-1.1.3-SNAPSHOT/VDMCheck2.sh
++ dirname /c/Users/caemh/Downloads/vdmcheck-1.1.3-SNAPSHOT/VDMCheck2.sh
+ dir=/c/Users/caemh/Downloads/vdmcheck-1.1.3-SNAPSHOT
+ cd /c/Users/caemh/Downloads/vdmcheck-1.1.3-SNAPSHOT
+ VAR=model2205
+ INXSD=schema/fmi2.xsd
+ type java
+ java -jar xsd2vdm.jar -xsd schema/fmi2.xsd -xml /tmp/xml2205.xml -name model2205 -vdm /tmp/vdm2205.vdmsl -nowarn
++ basename /tmp/xml2205.xml
+ BASE=xml2205.xml
+ sed -i -e s+xml2205.xml+XML+g /tmp/vdm2205.vdmsl
+ java -Xmx1g -cp vdmj.jar:annotations.jar com.fujitsu.vdmj.VDMJ -vdmsl -q -annotations -e 'isValidFMIConfiguration(model2205)' model /tmp/vdm2205.vdmsl
+ awk '/^true$/{ print "No errors found."; exit 0 };/^false$/{ print "Errors found."; exit 1 };{ print }'
Error: Could not find or load main class com.fujitsu.vdmj.VDMJ
Caused by: java.lang.ClassNotFoundException: com.fujitsu.vdmj.VDMJ
+ RET=0
+ '[' '' ']'
+ return 0
+ check /tmp/modelDescription2205.xml modelDescription.xml
+ '[' '!' -e /tmp/modelDescription2205.xml ']'
+ return 0
+ check /tmp/buildDescription2205.xml source/buildDescription.xml
+ '[' '!' -e /tmp/buildDescription2205.xml ']'
+ return 0
+ check /tmp/terminalsAndIcons2205.xml icon/terminalsAndIcons.xml
+ '[' '!' -e /tmp/terminalsAndIcons2205.xml ']'
+ return 0
+ exit 0
+ rm -f /tmp/modelDescription2205.xml /tmp/buildDescription2205.xml /tmp/terminalsAndIcons2205.xml /tmp/xml2205.xml /tmp/vdm2205.vdmsl

@nickbattle
Copy link
Collaborator

Okay, I think I can see what's happening. But it will help to understand some of the history...

I usually work with Java on Linux and I don't have any Windows systems to test with. I can do a certain amount by running the JUnit test suite on a Windows platform via GitHub "Actions", but that's the limit. We created a Powershell script for VDMCheck originally, but it was hard to maintain because I couldn't run it easily. So for Windows users, we created the java -jar vdmcheck.jar ... route, to keep everything in Java - that works on other platforms too.

The vdmcheck.jar tests the input by firstly trying to unzip it, and then secondly trying to parse it as XML.

For Linux/Mac users, the VDMCheck2.sh bash script uses the file command to test the input type, and unzips the ZIP if needed. As you discovered, it appears that Microsoft's file command has different --mime-type processing, which causes a problem.

But there is also a problem with the classpath in the java command line call. The bash script uses colons, but on Windows, the java executable is expecting semi-colons (because colons can be used in filenames, like c:/users/nick/... and we also have an issue with forward/backward slashes sometimes).

So I think the -cp vdmj.jar:annotations.jar option is being interpreted as a single (non-existent) file, hence it can't find the main VDMJ class.

Can you try tweaking the script to use a semi-colon separator here?

I assume you're using WSL on Windows to run bash? So if the above explains the problems, you can see that although WSL is a "bash environment", it isn't a Linux environment exactly: there are differences, which can easily cause problems.

@rudi
Copy link

rudi commented Jan 6, 2024

It sounds like you might want to distribute vdmcheck as a "fat jar" (as produced e.g. by https://github.com/johnrengelman/shadow); I use this plugin to produce jars that include all library dependencies into their single jar file.

@nickbattle
Copy link
Collaborator

I'll take a look, Rudi.

@CThuleHansen
Copy link
Contributor

Good idea Rudi. I have used that before as well. I will take a look Nick.

@CThuleHansen
Copy link
Contributor

CThuleHansen commented Jan 6, 2024

I send two pull-requests your way @nickbattle .
I was too fast with correcting myself with the -x argument, the mime-type was not the issue after all...

I have fixed it for msys.
I think a case for cygwin might be necessary as well, but I do not have a cygwin to try it out... So I will just leave it at msys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants