Menu

#391 Fix for "Illegal reflective access"

1.9.3.0
closed
None
1
2017-10-17
2017-10-07
No

Running Robocode on Java 9 prints this message:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by net.sf.robocode.io.URLJarCollector (file:/C:/robocode/libs/robocode.core-1.9.3..jar) to field sun.net.www.protocol.jar.JarFileFactory.fileCache
WARNING: Please consider reporting this to the maintainers of net.sf.robocode.io.URLJarCollector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

All of these messages can be silenced by passing these command-line arguments:

java --add-opens java.base/sun.net.www.protocol.jar=ALL-UNNAMED
     --add-opens java.base/java.lang.reflect=ALL-UNNAMED
     --add-opens java.desktop/sun.awt=ALL-UNNAMED

I believe this fixes #386.

Discussion

  • Flemming N. Larsen

    • status: open --> pending
    • assigned_to: Flemming N. Larsen
    • Group: 1.9.2.6 --> 1.9.3.0
     
  • Flemming N. Larsen

    Fixed. The installer of Robocode will add the "--add-opens" options for Java 9, which does not work with Java 8.

     
  • MultiplyByZer0

    MultiplyByZer0 - 2017-10-08

    Alternatively, you can use -XX:+IgnoreUnrecognizedVMOptions, which has existed since Java 6, which will cause the JVM to ignore unknown flags. So (note the quotes around add-opens):

    java -XX:+IgnoreUnrecognizedVMOptions
        "--add-opens=java.base/sun.net.www.protocol.jar=ALL-UNNAMED"
        "--add-opens java.base/java.lang.reflect=ALL-UNNAMED"
        "--add-opens=java.desktop/sun.awt=ALL-UNNAMED"
        ...
    

    This will allow users to upgrade to Java 9 without having to reinstall Robocode.

    Tested on both Java 8 and 9 on Robocode 1.9.3.0 Alpha on Windows 10.

     
  • Flemming N. Larsen

    Thanks for the tip. That is a nice feature. I was not aware of this feature. :-)
    I will change it, so the -XX:+IgnoreUnrecognizedVMOptions is used.

    It might be deprecated in the future though:
    https://bugs.openjdk.java.net/browse/JDK-6788376

     
  • MultiplyByZer0

    MultiplyByZer0 - 2017-10-08

    The new fix works for me.

     
  • MultiplyByZer0

    MultiplyByZer0 - 2017-10-09

    Oops. I made a typo in the last suggestion, which got into the release and breaks it, and I didn't notice because I didn't test it nearly enough.

    Instead of:

    "--add-opens java.base/java.lang.reflect=ALL-UNNAMED"
    

    Use (with the equal sign):

    "--add-opens=java.base/java.lang.reflect=ALL-UNNAMED"
    

    Apologies for that mistake, and it should work after correcting it.

     
  • Flemming N. Larsen

    No harm done. I have replaced the string in all the .bat, .sh, .command files, where I added the --add-opens lines.

     
  • Flemming N. Larsen

    • status: pending --> closed
     

Log in to post a comment.