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

[jvm] ExceptionInInitializerError #27

Closed
acarioni opened this issue May 23, 2023 · 9 comments
Closed

[jvm] ExceptionInInitializerError #27

acarioni opened this issue May 23, 2023 · 9 comments
Labels

Comments

@acarioni
Copy link

When I run my tests with haxe-concurrent 5.1.3 and haxe 4.3.1, I get the following error. However if I compile the same tests with haxe 4.3-rc.1, they work fine.
Unfortunately I am not able to reproduce the error by means of a simple test, but the basic execution flow is trivial: I create an instance of Executor in a static variable and, when I try to call the method submit on it from the method Test.delay, the exception ExceptionInInitializerError is thrown.

java.lang.ExceptionInInitializerError
          at utest.Test.delay(test-util/utest/Test.hx:152)
          at utest.Runner.runCurrent(test-util/utest/Runner.hx:129)
          at utest.Runner.gotoFirstTest(test-util/utest/Runner.hx:85)
          at utest.Runner$Closure_evtRun_0.invoke(test-util/utest/Runner.hx:60)
          at utest.Runner$Closure_evtRun_0.invoke(test-util/utest/Runner.hx)
          at hx.concurrent.lock.AbstractAcquirable.execute(/Users/acarioni/haxe/haxe_libraries/haxe-concurrent/5.1.3/haxelib/src/hx/concurrent/lock/Acquirable.hx:55)
          at utest.Runner.evtRun(test-util/utest/Runner.hx:55)
          at utest.Runner$Closure_run_0.invoke(test-util/utest/Runner.hx:52)
          at utest.Runner$Closure_run_0.invoke(test-util/utest/Runner.hx)
          at hx.concurrent.lock.AbstractAcquirable.execute(/Users/acarioni/haxe/haxe_libraries/haxe-concurrent/5.1.3/haxelib/src/hx/concurrent/lock/Acquirable.hx:55)
          at utest.Runner.run(test-util/utest/Runner.hx:50)
          at haxe.root.TestAll.main(test/TestAll.hx:93)
          at haxe.root.TestAll.main(test/TestAll.hx:1)
      Caused by: java.lang.ClassCastException: class hx.concurrent.thread.ThreadPool$Closure_onStart_0 cannot be cast to class java.lang.Runnable (hx.concurrent.thread.ThreadPool$Closure_onStart_0 is in unnamed module of loader 'app'; java.lang.Runnable is in module java.base of loader 'bootstrap')
          at sys.thread.Thread$NativeHaxeThread.<init>(/Users/acarioni/haxe/versions/4.3.1/std/java/_std/sys/thread/Thread.hx:160)
          at sys.thread.Thread$HaxeThread.create(/Users/acarioni/haxe/versions/4.3.1/std/java/_std/sys/thread/Thread.hx:104)
          at hx.concurrent.thread.ThreadPool.onStart(/Users/acarioni/haxe/haxe_libraries/haxe-concurrent/5.1.3/haxelib/src/hx/concurrent/thread/ThreadPool.hx:102)
          at hx.concurrent.ServiceBase$Closure_start_0.invoke(/Users/acarioni/haxe/haxe_libraries/haxe-concurrent/5.1.3/haxelib/src/hx/concurrent/Service.hx:65)
          at hx.concurrent.ServiceBase$Closure_start_0.invoke(/Users/acarioni/haxe/haxe_libraries/haxe-concurrent/5.1.3/haxelib/src/hx/concurrent/Service.hx)
          at hx.concurrent.lock.AbstractAcquirable.execute(/Users/acarioni/haxe/haxe_libraries/haxe-concurrent/5.1.3/haxelib/src/hx/concurrent/lock/Acquirable.hx:55)
          at hx.concurrent.ServiceBase.start(/Users/acarioni/haxe/haxe_libraries/haxe-concurrent/5.1.3/haxelib/src/hx/concurrent/Service.hx:58)
          at hx.concurrent.thread.ThreadPool.<init>(/Users/acarioni/haxe/haxe_libraries/haxe-concurrent/5.1.3/haxelib/src/hx/concurrent/thread/ThreadPool.hx:61)
          at hx.concurrent.executor.ThreadPoolExecutor.<init>(/Users/acarioni/haxe/haxe_libraries/haxe-concurrent/5.1.3/haxelib/src/hx/concurrent/executor/ThreadPoolExecutor.hx:41)
          at hx.concurrent.executor.Executor.create(/Users/acarioni/haxe/haxe_libraries/haxe-concurrent/5.1.3/haxelib/src/hx/concurrent/executor/Executor.hx:36)
          at utest.Test$Test_Fields_.<clinit>(test-util/utest/Test.hx:10)
          ... 13 more
@sebthom
Copy link
Member

sebthom commented May 23, 2023

This looks like a bug in the JVM target itself and you would need to report it directly at https://github.com/HaxeFoundation/haxe/issues. Does it work with the Java target?

@acarioni
Copy link
Author

The java target is deprecated and my project can't compile with it.

@acarioni
Copy link
Author

This is the issue that I opened on the haxe project.

@sebthom
Copy link
Member

sebthom commented Jul 31, 2023

@acarioni can you give me a code example where the compilation fails. I am somehow not able to reproduce it.

The following compiles fine for me when using the jvm target.

import hx.concurrent.executor.Executor;

class Test {

   static final executor = Executor.create(2);

   public static function main() {
      executor.submit(function() {
         trace("hi");
      }, FIXED_RATE(100));
   }
}

@acarioni
Copy link
Author

acarioni commented Aug 1, 2023

I tried hard to reproduce the issue by means of a simple example but unfortunately I wasn’t able. However I can reproduce it systematically when I compile my open source project.
In order to compile my project, you need to install a few tools (like Ant), but I can assist you if you need help.
You can find some other details in the issue thread on the haxe project.

@sebthom
Copy link
Member

sebthom commented Aug 1, 2023

If you locally modify the ThreadPool.hx file and replace the occurrences of (function() { with (function():Void {, does it then work?

@acarioni
Copy link
Author

acarioni commented Aug 1, 2023

I replaced the (only) occurrence of Threads.spawn(function() { with Threads.spawn(function(): Void { but I have the same error (I use hx.concurrent 5.1.3).

@sebthom
Copy link
Member

sebthom commented Aug 1, 2023

Ok, then I am out of ideas. I hoped by adding the return type explicitly it may help the Haxe compiler to generate code that is compatible with the java Runnable interface. Then we have to wait that the upstream issue you reported gets resolved directly by the haxe team

Copy link

stale bot commented Nov 30, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If the issue is still valid, please add a respective comment to prevent this issue from being closed automatically. Thank you for your contributions.

@stale stale bot added the wontfix label Nov 30, 2023
@stale stale bot closed this as completed Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants