aivarannamaa / yakindu-statecharts

Fork of YAKINDU Statechart Tools (http://www.statecharts.org)
Eclipse Public License 1.0
0 stars 0 forks source link

ClassCastException when generating code artifacts #1

Open aivarannamaa opened 9 months ago

aivarannamaa commented 9 months ago

The models open fine, but Java code generation gives following error:

Generating 'exampleStatechart' to target project 'example-project' ...
java.lang.ClassCastException: class org.yakindu.sct.model.sexec.impl.ExecutionStateImpl cannot be cast to class java.lang.Comparable (org.yakindu.sct.model.sexec.impl.ExecutionStateImpl is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @559d5a7; java.lang.Comparable is in module java.base of loader 'bootstrap')
    at java.base/java.util.ComparableTimSort.countRunAndMakeAscending(ComparableTimSort.java:320)
    at java.base/java.util.ComparableTimSort.sort(ComparableTimSort.java:188)
    at java.base/java.util.Arrays.sort(Arrays.java:1107)
    at java.base/java.util.Arrays.sort(Arrays.java:1301)
    at java.base/java.util.ArrayList.sort(ArrayList.java:1721)
    at java.base/java.util.Collections.sort(Collections.java:179)
    at org.eclipse.xtext.xbase.lib.ListExtensions.sortInplace(ListExtensions.java:64)
    at org.eclipse.xtext.xbase.lib.IterableExtensions.sortWith(IterableExtensions.java:775)
    at org.yakindu.sct.model.sexec.naming.DefaultNamingService.addShortStateNames(DefaultNamingService.java:216)
    at org.yakindu.sct.model.sexec.naming.DefaultNamingService.createShortNameMap(DefaultNamingService.java:208)
    at org.yakindu.sct.model.sexec.naming.DefaultNamingService.initializeNamingService(DefaultNamingService.java:130)
    at org.yakindu.sct.generator.java.JavaGenerator.generate(JavaGenerator.java:103)
    at org.yakindu.sct.generator.core.execution.SExecGeneratorEntryExecutor.execute(SExecGeneratorEntryExecutor.java:54)
    at org.yakindu.sct.generator.core.execution.AbstractGeneratorEntryExecutor.execute(AbstractGeneratorEntryExecutor.java:64)
    at org.yakindu.sct.generator.core.execution.GeneratorExecutorLookup.execute(GeneratorExecutorLookup.java:57)
    at org.yakindu.sct.generator.builder.EclipseContextGeneratorExecutorLookup$1.run(EclipseContextGeneratorExecutorLookup.java:43)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
exampleStatechart done.

Tried Yakindu 3.5.5 and 3.5.13. Tried various versions of Eclipse Java IDE-s. -- 2023-09, 2022-03, 2020-12, 2020-06 and 2019-06. Generation succeeded only with 2019-06, but not with models saved in with later versions of Eclipse (with xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.3/notation" in the sct file, see #2).

With other Eclipse versions requiring at least Java 8, the Yakindu plug-in didn't even install correctly with Java 8 (the settings page missed sub-pages and the sct and sgen files were note recognized). Running the same IDE with Java 11 fixed these problems but gave the error above.

The weirdest thing -- it used to work properly with 2022-03 on the same computer. It stopped working after I installed plugin development features to this Eclipse. Then removed Eclipse, together with ~/.p2 and ~/.eclipse folders, installed fresh Java IDE 2022-03 and Yakindu 3.5.5 (later tried also 3.5.13), but no luck anymore.

aivarannamaa commented 9 months ago

Googling suggests that the error is caused by stricter classloading checks introduced in Java 9. I'm assuming the error says that something loaded java.long.Comparable with bootstrap classloader before Equinox loader got to it.

Tried adding Eclipse-BuddyPolicy: boot and Eclipse-BuddyPolicy: global to Yakindu's MANIFEST.MF files (as suggested by https://bugs.eclipse.org/bugs/show_bug.cgi?id=575868), but it did not help.

aivarannamaa commented 9 months ago

Got generation working by using Eclipse Platform (see the section "Platform Runtime Binary" at https://archive.eclipse.org/eclipse/downloads/drops4/R-4.23-202203080310/) instead of Eclipse Java IDE 2022-03. Eclipse SDK may work as well (don't remember for sure, which version of SDK did I test, but I remember having some kind of success with it).

Not closing the issue, because it's a work-around, not a real solution.