Imagine a bacon-wrapped Ferrari. Still not better than our free technical reports.

Testing JavaRebel

Quite a few of our users have contributed small pieces of code that test reloading of some parts of Java classes. Some of them have discovered genuine bugs and we are working on fixing them. However there was also some confusion that we want to clear up.

If you want to write a small test for JavaRebel you have to be aware of the two following things:

  • JavaRebel will not reload code of currently running method. All new invocations of the method (even concurrent ones) will get reloaded, but the code in a running method will not reload. This means that if you have a method with while (true) {/*body*/} the body will never reload since you never leave the method. This is not a restriction in any real application, but this does show up in the small tests.
  • The second issue is more particular to JavaRebel — if all running methods are of the same class they might not get reloaded (this does not always apply, but may compromise your test). This issue may come if you have only one class (e.g. Main) and try to change a method inside the same class.

The recommended way to test JavaRebel is to make a separate Launcher class with a while loop and call a method test() in another class (e.g. Test) with it. If you want to test concurrency make a separate class for threads (inner or anonymous will be enough).

  • Suraj BN

    Thank You. Those lines were really helpful =)