Menu

Generating battle with Robocode engine, security error

Help
Giu
2016-09-26
2016-09-26
  • Giu

    Giu - 2016-09-26

    Hello there,

    Thanks in advance for helping.

    I installed Robocode on Ubuntu 16.04. The installation process sends automatically Robocode to the root folder. Given that i needed to add external Jar libraries(linked to the Robocode folder in the root) to Eclipse, i have to run Eclipse as administrator (using sudo) to be able to have acces to such libraries.

    I followed the tutorials and all looked good. Given that i would like to apply AI tools to Robocode i need to run the battles from code, i then used the example where the Robocode engine is used to generate a battle for two players.

    I run in the following exception:

    Exception in thread "Application Thread" java.lang.ClassCircularityError: net/sf/robocode/host/security/RobocodeSecurityPolicy$2
    at net.sf.robocode.host.security.RobocodeSecurityPolicy.implies(RobocodeSecurityPolicy.java:101)
    at java.security.ProtectionDomain.implies(ProtectionDomain.java:281)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:450)
    at java.security.AccessController.checkPermission(AccessController.java:884)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.System.setProperty(System.java:792)
    at net.sf.robocode.ui.WindowManager.setEnableGUI(WindowManager.java:104)
    at net.sf.robocode.ui.WindowManager.setVisibleForRobotEngine(WindowManager.java:621)
    at robocode.control.RobocodeEngine.setVisible(RobocodeEngine.java:207)
    at robot.battle.main(battle.java:18)

    Any help?

     
  • Giu

    Giu - 2016-09-26

    After some debuggings the errors shows up at
    engine.setVisible(true);

     
    • Flemming N. Larsen

      Hi Giu,

      The issue seems to be related to using the GUI of Robocode. Do you intent
      to run the RobocodeEngine with or without a GUI?
      If you want to train you AI, you don't need a GUI. But it makes it easier
      to watch the robot behavior while the AI is being trained, of course.
      If you don't need the GUI, we should disable in order to work-around this
      issue.

      Do you run your application with the NOSECURITY system property set to
      true? Normally, when running Robocode, this setting is set with
      -DNOSECURITY=true, and you could do something similar when running your
      application (running the RobocodeEngine). The NOSECURITY disables some
      parts of the RobocodeSecurityManager, so that you can read from access
      external libraries etc. Normally, Robocode is running in a "sandbox" where
      robots have limited access to the resources on the host computer - for
      security reasons and to prevent robots from cheating in the game itself.

      Is it possible to run Robocode independently with the GUI on your system?
      Are you able to run Robocode without root access, e.g. from your own user?

      Best regards,

      • Flemming

      man. 26. sep. 2016 kl. 22.27 skrev Giu funwai@users.sf.net:

      After some debuggings the errors shows up at
      engine.setVisible(true);


      Generating battle with Robocode engine, security error
      https://sourceforge.net/p/robocode/discussion/116459/thread/e1415f29/?limit=25#c55e


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/robocode/discussion/116459/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       
      • Flemming N. Larsen

        Just a follow-up...

        You could try to grant permissions to your Java application (running the
        RobocodeEngine) by adding this command-line option:

        -Djava.security.policy=my_robocode.policy

        Where 'my_robocode.policy' is a file of yours. You could initialize this
        one to include this:

        grant {
        permission java.security.AllPermission;};

        This way all permissions are granted to your application. If this works,
        you could narrow the security settings afterwards - meaning that you don't
        grant ALL permission, but only some - enough to get rid of the
        ClassCircularityError.

        I expect that you need to grant these:

        java.io.FilePermission
        java.lang.RuntimePermission "accessClassInPackage"
        java.lang.RuntimePermission "defineClassInPackage"

        The details for each permission is available here:
        http://docs.oracle.com/javase/7/docs/technotes/guides/security/permissions.html

        An example regarding the File Permission is here:
        http://stackoverflow.com/questions/9111381/how-to-give-grant-to-a-jar-file-to-execute-an-another-jar-file

        I hope this can give a clue of how to solve the issue?

        Cheers,

        • Flemming

        man. 26. sep. 2016 kl. 22.58 skrev Flemming N. Larsen flemming.n.larsen@gmail.com:

        Hi Giu,

        The issue seems to be related to using the GUI of Robocode. Do you intent
        to run the RobocodeEngine with or without a GUI?
        If you want to train you AI, you don't need a GUI. But it makes it easier
        to watch the robot behavior while the AI is being trained, of course.
        If you don't need the GUI, we should disable in order to work-around this
        issue.

        Do you run your application with the NOSECURITY system property set to
        true? Normally, when running Robocode, this setting is set with
        -DNOSECURITY=true, and you could do something similar when running your
        application (running the RobocodeEngine). The NOSECURITY disables some
        parts of the RobocodeSecurityManager, so that you can read from access
        external libraries etc. Normally, Robocode is running in a "sandbox" where
        robots have limited access to the resources on the host computer - for
        security reasons and to prevent robots from cheating in the game itself.

        Is it possible to run Robocode independently with the GUI on your system?
        Are you able to run Robocode without root access, e.g. from your own user?

        Best regards,
        - Flemming

        man. 26. sep. 2016 kl. 22.27 skrev Giu funwai@users.sf.net:

        After some debuggings the errors shows up at
        engine.setVisible(true);


        Generating battle with Robocode engine, security error
        https://sourceforge.net/p/robocode/discussion/116459/thread/e1415f29/?limit=25#c55e


        Sent from sourceforge.net because you indicated interest in
        https://sourceforge.net/p/robocode/discussion/116459/

        To unsubscribe from further messages, please visit
        https://sourceforge.net/auth/subscriptions/

         
  • Giu

    Giu - 2016-09-26

    Hello and thanks a lot for your help.

    Wow that's a lot of information,..unfortunately i am new to robocode i haven't really got everything you said.

    I'll try to answetr your question one by one..

    I actualy tired to set the visible field to (FALSE) but i got another error, probably connected to the robots..i think it cannot find the robots that he is trying to usae for the competition. Following the error i get:

    Exception in thread "Application Thread" java.lang.ClassCircularityError: net/sf/robocode/host/security/RobocodeSecurityPolicy$2
    at net.sf.robocode.host.security.RobocodeSecurityPolicy.implies(RobocodeSecurityPolicy.java:101)
    at java.security.ProtectionDomain.implies(ProtectionDomain.java:281)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:450)
    at java.security.AccessController.checkPermission(AccessController.java:884)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1294)
    at java.lang.System.getProperty(System.java:717)
    at net.sf.robocode.io.FileUtil.getRobotsDir(FileUtil.java:209)
    at net.sf.robocode.repository.RepositoryManager.getRobotsDirectory(RepositoryManager.java:62)
    at net.sf.robocode.repository.RepositoryManager.refresh(RepositoryManager.java:91)
    at net.sf.robocode.repository.RepositoryManager.refresh(RepositoryManager.java:87)
    at robocode.control.RobocodeEngine.getLocalRepository(RobocodeEngine.java:231)
    at robot.battle.main(battle.java:26)

    No, i cannot run robocode as NON-root. The installation sends all the folders to the root, and i can only access that with Sudo. What i can do is to change the installaiton folder. During the installation a pop up window asks if it's ok to install Robocode in the root folder, i can answer no and change folder. But i do not know if that will open up other problems.

    Regarding all the other things related to SECURITY...i have no idea, it is actually the first time i get to see this security issue. I did not set any configuration, i just copied the code and runned. When i just created a robot, i did the whole "new run configuration" thing, where i set-up -Xmx512M -Dsun.io.useCanonCaches=false -Ddebug=true as argument..and it works fine. But i need to have control of the whole environment to evolve my player.

    Thank you

     
    • Flemming N. Larsen

      Okay. You could try to add -DNOSECURITY=true to the command-line options,
      where you have '-Xmx512M -Dsun.io.useCanonCaches=false -Ddebug=true' as the
      first thing, and see if this works first of all.

      man. 26. sep. 2016 kl. 23.44 skrev Giu funwai@users.sf.net:

      Hello and thanks a lot for your help.

      Wow that's a lot of information,..unfortunately i am new to robocode i
      haven't really got everything you said.

      I'll try to answetr your question one by one..

      I actualy tired to set the visible field to (FALSE) but i got another
      error, probably connected to the robots..i think it cannot find the robots
      that he is trying to usae for the competition. Following the error i get:

      Exception in thread "Application Thread" java.lang.ClassCircularityError:
      net/sf/robocode/host/security/RobocodeSecurityPolicy$2
      at
      net.sf.robocode.host.security.RobocodeSecurityPolicy.implies(RobocodeSecurityPolicy.java:101)
      at java.security.ProtectionDomain.implies(ProtectionDomain.java:281)
      at
      java.security.AccessControlContext.checkPermission(AccessControlContext.java:450)
      at
      java.security.AccessController.checkPermission(AccessController.java:884)
      at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)

      at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1294)
      at java.lang.System.getProperty(System.java:717)
      at net.sf.robocode.io.FileUtil.getRobotsDir(FileUtil.java:209)
      at
      net.sf.robocode.repository.RepositoryManager.getRobotsDirectory(RepositoryManager.java:62)
      at
      net.sf.robocode.repository.RepositoryManager.refresh(RepositoryManager.java:91)
      at
      net.sf.robocode.repository.RepositoryManager.refresh(RepositoryManager.java:87)
      at
      robocode.control.RobocodeEngine.getLocalRepository(RobocodeEngine.java:231)
      at robot.battle.main(battle.java:26)

      No, i cannot run robocode as NON-root. The installation sends all the
      folders to the root, and i can only access that with Sudo. What i can do is
      to change the installaiton folder. During the installation a pop up window
      asks if it's ok to install Robocode in the root folder, i can answer no and
      change folder. But i do not know if that will open up other problems.

      Regarding all the other things related to SECURITY...i have no idea, it is
      actually the first time i get to see this security issue. I did not set any
      configuration, i just copied the code and runned. When i just created a
      robot, i did the whole "new run configuration" thing, where i set-up
      -Xmx512M -Dsun.io.useCanonCaches=false -Ddebug=true as argument..and it
      works fine. But i need to have control of the whole environment to evolve
      my player.

      Thank you

      Generating battle with Robocode engine, security error
      https://sourceforge.net/p/robocode/discussion/116459/thread/e1415f29/?limit=25#6221


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/robocode/discussion/116459/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       
  • Giu

    Giu - 2016-09-26

    Sorry but i do not really understand.

    Right now i have two files. First file is a simple robot. In order to run Robocode from this file i made a "new run configuration" set-up (where i added -Xmx512M -Dsun.io.useCanonCaches=false -Ddebug=true) and robocode.Robocode as main file.

    Second file, is a file called "battle", which is the example project to run a battle from code. To run this one, i did not create a "new run configuration", i just run it normally. Do i need to create a "new run configuration" for this one as well and add "-Xmx512M -Dsun.io.useCanonCaches=false -Ddebug=true" and "-DNOSECURITY=true" as arguments and "robocode.Robocode" as main file?? (which seems weird to me since the main file is actually the one i use to create the battle)

     
    • Flemming N. Larsen

      Yes, you should edit your Run Configuration in Eclipse for running Robocode
      with:

      -Xmx512M -Dsun.io.useCanonCaches=false -Ddebug=true -DNOSECURITY=true

      However, I recommend that you only write:

      -Xmx512M -DNOSECURITY=true

      The -Dsun.io.useCanonCaches=false is automatically being set internally in
      Robocode, and the -Ddebug=true should only be used for debugging robots -
      e.g. single-stepping each line of code in a robot.

      The arguments "-Xmx512M -DNOSECURITY=true" means: Use up to max. 512 MB
      heap memory and disable the Robocode security manager

      However, disabling the security manager with the -DNOSECURITY=true argument
      might not solve your problem.

      The ClassCircularityError exception thrown from the stack trace from your
      first post indicates that there is some kind of circular reference to at
      least one class being loaded into Robocode by the Java virtual machine.
      This could mean that classes are being used by the robot(s) running in
      Robocode that conflicts with the libraries (JAR files) of Robocode.

      If you still got problems after adding the -DNOSECURITY=true argument when
      running Robocode, then please send the robot including library files to
      fnl(at)sourceforge.net and I will try to run it from my environment.

      Cheers,

      • Flemming

      man. 26. sep. 2016 kl. 23.57 skrev Giu funwai@users.sf.net:

      Sorry but i do not really understand.

      Right now i have two files. First file is a simple robot. In order to run
      Robocode from this file i made a "new run configuration" set-up (where i
      added -Xmx512M -Dsun.io.useCanonCaches=false -Ddebug=true) and
      robocode.Robocode as main file.

      Second file, is a file called "battle", which is the example project to
      run a battle from code. To run this one, i did not create a "new run
      configuration", i just run it normally. Do i need to create a "new run
      configuration" for this one as well and add "-Xmx512M
      -Dsun.io.useCanonCaches=false -Ddebug=true" and "-DNOSECURITY=true" as
      arguments and "robocode.Robocode" as main file?? (which seems weird to me
      since the main file is actually the one i use to create the battle)


      Generating battle with Robocode engine, security error
      https://sourceforge.net/p/robocode/discussion/116459/thread/e1415f29/?limit=25#6d84


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/robocode/discussion/116459/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       
  • Giu

    Giu - 2016-09-26

    Thanks a lot.

    Ok this is the situation now.

    I have a project called testForRobot, which i linked to the libraries in robocode (in /root/robocode),

    This project contains only one file BattleRunJava, which i guess was written by you.

    In project->Run as->properties->configurations i set:

    main class: Robocode.Control.RobocodeEngine

    arguments: -Xmx512M -DNOSECURITY=true

    i get the following error:
    Error: Could not find or load main class Robocode.Control.RobocodeEngine

    i woud love to send you the code, but i would just send you the code you uploaded on the wiki...

     
  • Giu

    Giu - 2016-09-26

    Hi,

    Yes i followed both guides and it is working fine. I can run the robot example, i can call robocode from eclipse and everything wors fine. Problems show up when i use the BattleRunner example

     
  • Giu

    Giu - 2016-09-26

    In the guides you say that the main class should be robocode.Robocode but when you explain the BattleRunner example you write:

    The main entry class is the Robocode.Control.RobocodeEngine class, which must be instantiated by the application controlling Robocode.

    I get a bit confused

     
    • Flemming N. Larsen

      When using the RobocodeEngine, you instatiate (new operator) it from an
      standard Java application with a main method. You can call this application
      whatever you want, e.g. MyApp. In this case, you need to point your Eclipse
      Run Configuration to this main class (MyApp) and provide the same arguments
      as the Robocode application itself.

      Den tir. 27. sep. 2016 01.03 skrev Giu funwai@users.sf.net:

      In the guides you say that the main class should be robocode.Robocode but
      when you explain the BattleRunner example you write:

      The main entry class is the Robocode.Control.RobocodeEngine class, which
      must be instantiated by the application controlling Robocode.

      I get a bit confused

      Generating battle with Robocode engine, security error
      https://sourceforge.net/p/robocode/discussion/116459/thread/e1415f29/?limit=25#4565


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/robocode/discussion/116459/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       
      • Flemming N. Larsen

        Heh... our posts crossed each other. :-)

        Den tir. 27. sep. 2016 01.10 skrev Flemming N. Larsen flemming.n.larsen@gmail.com:

        When using the RobocodeEngine, you instatiate (new operator) it from an
        standard Java application with a main method. You can call this application
        whatever you want, e.g. MyApp. In this case, you need to point your Eclipse
        Run Configuration to this main class (MyApp) and provide the same arguments
        as the Robocode application itself.

        Den tir. 27. sep. 2016 01.03 skrev Giu funwai@users.sf.net:

        In the guides you say that the main class should be robocode.Robocode but
        when you explain the BattleRunner example you write:

        The main entry class is the Robocode.Control.RobocodeEngine class, which
        must be instantiated by the application controlling Robocode.

        I get a bit confused

        Generating battle with Robocode engine, security error
        https://sourceforge.net/p/robocode/discussion/116459/thread/e1415f29/?limit=25#4565


        Sent from sourceforge.net because you indicated interest in
        https://sourceforge.net/p/robocode/discussion/116459/

        To unsubscribe from further messages, please visit
        https://sourceforge.net/auth/subscriptions/

         
  • Giu

    Giu - 2016-09-26

    Ok i fixed it : )

    The second arguments you suggested me to add made the job. I used as main class robocode.Robocode. Thanks a lot

    I have another question (way easier), but i wll post that tomorrow!

    Thank you very much and sorry for waisting your time

     

Log in to post a comment.