Menu

#37 Robot imported based on a jar file cannot run due to error: loader constraint violation

none
open
nobody
None
1
2023-10-24
2023-10-19
darren
No

Hi team,

I am trying to build a robot based on diamond and the code works when running using the .class file, but not work when I am trying to start a battle with a robot imported by the jar file built on the same source file.
Could you help take a look at this issue?

voidious.Diamond 1.0: Throwable: java.lang.LinkageError: loader constraint violation: when resolving method 'java.awt.geom.Point2D$Double voidious.utils.MovementPredictor.nextLocation(voidious.Diamond)' the class loader net.sf.robocode.host.security.RobotClassLoader @37d889de of the current class, voidious/radar/DiamondEyes, and the class loader 'app' for the method's defining class, voidious/utils/MovementPredictor, have different Class objects for the type voidious/Diamond used in the signature (voidious.radar.DiamondEyes is in unnamed module of loader net.sf.robocode.host.security.RobotClassLoader @37d889de, parent loader 'app'; voidious.utils.MovementPredictor is in unnamed module of loader 'app')

Discussion

  • darren

    darren - 2023-10-19

    Why there are two class loader for same class?
    (RoboCode 1.9.5.1 and java 11)

     

    Last edit: darren 2023-10-19
  • Flemming N. Larsen

    Why there are two class loader for same class?

    Robocode is using its own class loader due to security reasons as it needs to put security restrictions on robots running within the same JVM.

    Regarding the import error. Did you use the Robot/team packager of Robocode? f not, make sure to use it:

    Call the packager from the menu:
    Robot -> Package robot or team

    If you did use the packager, I expect this to be a problem with never versions of Java making use of modules and putting more restrictions on Java Reflection. So you could try to run Robocode on an older version of Java e.g. version 8 or 11?

     
    • darren

      darren - 2023-10-19

      Hi Flemming,
      Yes I packed the jar file using "Robot/Package robot or team" menu.
      OK, let me try with java 8, thanks!

       
  • darren

    darren - 2023-10-19

    Hi @fnl, help!
    The problem still there, jdk 8, could you help take a look?
    voidious.Diamond 1.0: Throwable: java.lang.LinkageError: loader constraint violation: when resolving method "voidious.utils.MovementPredictor.nextLocation(Lvoidious/Diamond;)Ljava/awt/geom/Point2D$Double;" the class loader (instance of net/sf/robocode/host/security/RobotClassLoader) of the current class, voidious/radar/DiamondEyes, and the class loader (instance of sun/misc/Launcher$AppClassLoader) for the method's defining class, voidious/utils/MovementPredictor, have different Class objects for the type voidious/Diamond used in the signature

     

    Last edit: darren 2023-10-19
    • Flemming N. Larsen

      OK. I will have a look and see if I can reproduce it. And if so, I will figure out how it can be solved. 👍

       
    • Flemming N. Larsen

      I can reproduce the problem, and trying to find a prober fix for it.

       
      ❤️
      1
      • darren

        darren - 2023-10-23

        @fnl Thanks you, looking forward your answer.

         
    • Flemming N. Larsen

      For now, a temporary fix is to set the -DNOSECURITY=true option on the command line. That is, put this line in the java command in the robocode.bat or robocode.sh file.
      This disables the security manager and changes the way the classes are loaded.

      I still work on a real fix. But it is not an easy one, and could take some time.

       
      👍
      1
    • Flemming N. Larsen

      @darren
      I have made a fix in the RobotClassLoader that works on my system, and I should like you to try it out with an alpha version of the next version 1.9.5.2:
      https://robocode.sourceforge.io/files/robocode-1.9.5.2-alfa-setup.jar

      If it works, I will make a release soon.

       

      Last edit: Flemming N. Larsen 2023-10-23
  • darren

    darren - 2023-10-24

    @fnl Thank you for your quick response.
    I tried with the new alfa version and it works for me, when can we get the release version of 1.9.5.2?

     

    Last edit: darren 2023-10-24

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.