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
459 stars 21 forks source link

Assertion error followed by `Uncaught (in promise) <empty string>` #156

Closed patrick96 closed 1 year ago

patrick96 commented 1 year ago

I ran into some issues when compiling and running an existing program, I was able to reduce it to the following program:

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello World");
        new Main().test();
    }

    private void test() {
        System.out.println("HERE");
        System.out.println("HERE");
    }
}

If I compile and cheerpjfy this and run it in a browser (happens in both Firefox and Chrome), the dev tools break on an assertion error:

2023-01-23-174000_1183x770_scrot

Stack Trace:

assert@https://cjrtnc.leaningtech.com/2.3/loader.js:1145:3
runContinuationStack@https://cjrtnc.leaningtech.com/2.3/loader.js:501:10
cheerpjSchedule@https://cjrtnc.leaningtech.com/2.3/loader.js:1271:25
cheerpjRunStaticMethod@https://cjrtnc.leaningtech.com/2.3/loader.js:685:2
cheerpjRunMain/<@https://cjrtnc.leaningtech.com/2.3/loader.js:2446:11
promise callback*cheerpjRunMain@https://cjrtnc.leaningtech.com/2.3/loader.js:2432:140
@http://localhost:8000/:14:21

If I let the program continue, it throws an uncaught exception:

Uncaught (in promise) <empty string> loader.js:2447:45
    cheerpjRunMain https://cjrtnc.leaningtech.com/2.3/loader.js:2447
    (Async: promise callback)
    cheerpjRunMain https://cjrtnc.leaningtech.com/2.3/loader.js:2447
    <anonymous> http://localhost:8000/:14

This all happens before the first print in the test method happens (likely happens during the invoke).

Steps To Reproduce

I downloaded a fresh copy of cheerpj_2.3 and compiled the entire program like this:

javac Main.java
jar cfe main.jar Main Main.class

./cheerpj_2.3/cheerpjfy.py main.jar

I used the following HTML skeleton:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>CheerpJ test</title>
    <script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
  </head>
  <body>
  </body>
  <script>
      cheerpjInit();
      cheerpjCreateDisplay(800,600);
      // main.jar is in the same folder as html
      cheerpjRunMain("Main", "/app/main.jar"); 
  </script>
</html>

Compiled files:

Additional Context

The Hello World printing is not necessary for this crash, it is just here to show that the crash happens in the middle of the user program.

The test method requires both print calls, otherwise no crash happens because the test method is inlined.

This happens on Linux on both Firefox 109 and Chrome 109.0.5414.74

The java files were compiled with JDK17

saarikoski-jules commented 1 year ago

Unfortunately at the moment CheerpJ only supports Java 8. We are working on supporting multiple versions in the future.