I'm a bit too rusty with Java classloaders to debug deep into this ATM, but when building the current version of Robocode from git, under a Debian + OpenJDK 11 environment, had a build failure related to JarJarTest. I can bypass the error it by running "./gradlew build --continue" and the rest builds fine. I can also confirm that Ahead.class exists, and other tests relying on it pass just fine.
java.lang.ClassNotFoundException: tested.robots.Ahead
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at net.sf.robocode.host.jarjar.JarJarTest.runClassLoader(JarJarTest.java:74)
If I find out more I'll comment further (or might even add a pull request if the cause/fix becomes obvious to me), but in the meantime thought I'd document this.
I am able to reproduce this as well on Ubuntu with adoptopenjdk-11-hotspot.
Thank you for reporting it. :-)
I will have a look into this issue.
This is due to the Java restrictions on using reflections. With Java 16+, lots of stuff with reflections cannot be used anymore, so I will try out compiling and running Robocode on newer Java versions.
... And it is reproducable under Windows as well.
Fixing this issue is not trivial.
Due to an old Sun bug with caching (Unix) file handles etc. with Jar connections that are never cleaned up, we created the URLJarCollector which uses Java Reflection for cleaning up the caches when running the Rumble with lots of robots starting and stopping in the same JVM.
I Java 16, we cannot use Deep Reflection anymore, and cannot use this fix anymore.
I am looking into a work-aound where we use newUrlNoCache(...) instead of 'new URL()':
But it might not work as expected for the Rumble.
I will try out some of the stuff mentioned here on the OpenJDK issues:
https://bugs.openjdk.java.net/browse/JDK-8239054
Related:
https://stackoverflow.com/questions/7071761/what-is-the-reason-that-setdefaultusecachesfalse-of-urlconnection-is-eagerly-c
Interesting. I'm a little surprised at caching and reflection behavior being related to the JarJarTest failure in OpenJDK 11. When building in OpenJDK 11 I did notice some warnings about reflection stuff that was deprecated and wouldn't work in the future, but the warnings gave the impression that such worked just fine in OpenJDK 11, which is not Java 16+ where the reflection stuff actually stops working, rather than just warning about it.
Normally Robocode is build and tested under JDK 8 meaning that there is a gurantee that it will work under Java 8. And hence, we don't get failing tests, warnings etc.
But Java is getting more and more restricted and getting rid of old stuff, e.g. Sun specific classes, and e.g. the Deep Reflection as well.
We can "easily" do a fix that will work under Java 11 - 15. But Deep Reflection will stop working under Java 16. Hence, I guess we need to find a solution for people running Robocode on Java 16+.
And that is not easy. I did some fixes locally, which fixed some of the broken test, but raised new issues. I expect there might come a lot of issues with all the many changes in Java these days, which is for sure not compatible with Java 8 anymore.