leaningtech / cheerpj-meta

Run Java 8 applications, libraries, applets, Java Web Start, and Oracle Forms on the web without legacy plugins.
https://labs.leaningtech.com/cheerpj
434 stars 21 forks source link

Getting error calling Class.forName. #169

Closed matthewfl closed 5 months ago

matthewfl commented 1 year ago

I am trying to load an application that has some of its parts written in Clojure. Trying to load the Clojure runtime, I get the following error. It seems that that Clojure is internally using Class.forName to load some stuff and that is resulting in the following exception when it internally attempts to use Unsafe.

I would have assumed that because this is running entirely compiled to webassembly, it should be possible for it to use unsafe internally.

java.lang.SecurityException: Unsafejava.lang.SecurityException: Unsafe
    at sun.misc.Unsafe.getUnsafe(Unknown Source)
    at java.net.InetAddress(Unknown Source)
    at internal.internal(Unknown Source)
    at internal.internal(Unknown Source)
    at java.lang.Class.forName0(Unknown Source)
    at clojure.lang.RT.classForName(Unknown Source)
    at clojure.core.server$loading__6789__auto____8961.invoke(Unknown Source)
    at clojure.core.server__init.load(Unknown Source)
    at clojure.core.server__init(Unknown Source)
    at internal.internal(Unknown Source)
    at internal.internal(Unknown Source)
    at java.lang.Class.forName0(Unknown Source)
    at clojure.lang.RT.classForName(Unknown Source)
    at clojure.lang.RT.loadClassForName(Unknown Source)
    at clojure.lang.RT.load(Unknown Source)
    at clojure.core$load$fn__6908.invoke(Unknown Source)
    at clojure.core$load.invokeStatic(Unknown Source)
    at clojure.core$load.doInvoke(Unknown Source)
    at clojure.core$load_one.invokeStatic(Unknown Source)
    at clojure.core$load_lib$fn__6850.invoke(Unknown Source)
    at clojure.core$load_lib.invokeStatic(Unknown Source)
    at clojure.core$load_lib.doInvoke(Unknown Source)
    at clojure.core$load_libs.invokeStatic(Unknown Source)
    at clojure.core$load_libs.doInvoke(Unknown Source)
    at clojure.lang.RT.doInit(Unknown Source)
alexp-sssup commented 1 year ago

This is likely to be caused by the incomplete support for class loaders in CheerpJ 2.x. This whole class of problems will be solved with the new CheerpJ 3.x architecture that is currently under development.

Please provide a self-contained JAR that demonstrate the problem, so that we can use it as a test case.

matthewfl commented 1 year ago

@alexp-sssup I have created a simple self-contained jar that launches clojure and causes this issue. I also included a demo page that generates the stack trace.

https://www.dropbox.com/s/pok26fyiw9v860g/cheerpj-clojure.zip?dl=1

alexp-sssup commented 5 months ago

This problem is fixed with the new CheerpJ 3.0 architecture. Please try this build: https://cjrtnc.leaningtech.com/3_20240122_347/cj3loader.js

Since cjCall has been replaced with the new "library mode", you'll need update your code. See here for more information: https://labs.leaningtech.com/cheerpj3/guides/library-mode