A possible case of binary incompatibility with Java

Please see the attached doc for well formatted version with screenshots.

Perhaps it’s not a goal or priority to support such level of interoperability with Java as in my case, but I want to report it.

Comsol multiphysics

<image>

has a convenient feature of exporting  your model to Java source code

<image>

This generates a single java file that contains a sequence of calls against the Comsol API. All the calls just reproduce what the user did in GUI while building his model. After compiling the source with Java 1.6, you get a *.class file that you can load back into Comsol. Comsol “replays” all commands and builds the model.

<image>

I hoped to use Kotlin instead of Java to algorithmically generate complex periodic geometrical structures in my model.

Java file that Comsol generates, has standard public static void main() method that directly or indirectly calls COMSOL API. I was able to use Kotlin package-level functions  to call COMSOL API , and to call Kotlin package level functions from Java’s main. This way Comsol loaded model successfully. Whenever the call hierarchy starting at public static void main() contains instantiation of any Kotlin class , COMSOL fails to load the generated class-file

<image>

The error message is everything that COMSOL shows, no more logs or information AFAIK.

I can run generated files from command line, but they fail to load in COMSOL.  



[A possible case of binary incompatibility with Java.docx|attachment](upload://js4nq94OMZSzoeQxyrdJhm6n281.docx) (164 KB)

Are you sure that Comsol can run multiple class files?

In COMSOL open dialog, we choose just one file. It’s expected to have public static main(). Also Java 1.6 is required. I don’t know other limitations. For example, I had projects where the main() method referenced other *class files in other packages, and only those classes were calling COMSOL API. Comsol finds all such additional classes and loads them too.

This looks like some issue with class loaders. Perhaps COMSOL uses a custom class loader and here something breaks. COMSOL is built on top of Eclipse. I have CLASSPATH that includes Kotlin library path. This way the main class-file can be launched from command line. I also tried to use class file with Kotlin main() , but this gives the same error message.

Unfortunately, I can't think of any other reason why this doesn't work. In principle, one could debug COMSOL and find out what the problem is, or at least get a more comprehencible error message, but we'd need your help to do this.

Another option would be to ask COMSOL customer support to troubleshoot this issue...