Blog

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).

Jevgeni Kabanov

Jevgeni Kabanov is the founder and CEO of ZeroTurnaround (www.zeroturnaround.com), a development tools company that focuses on productivity. Jevgeni has been speaking at international conferences for over 5 years, including JavaPolis/Devoxx, JavaZone, JAOO, QCon, TSSJS, JFokus and so on. He also has an active research interest in programming languages, types and virtual machines, publishing several papers on topics ranging from category theoretical notions to typesafe Java DSLs. You can follow Jevgeni on Twitter as @ekabanov.

More PostsWebsiteTwitter

Join the Rebellion Facebook Twitter RSS feed