JDK9: An illegal reflective access operation has occurred. org.python.core.PySystemState

Viewed 101728

I'm trying to run DMelt programs (http://jwork.org/dmelt/) program using Java9 (JDK9), and it gives me errors such as:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/dmelt/jehep/lib/jython/jython.jar) to method java.io.Console.encoding()
WARNING: Please consider reporting this to the maintainers of org.python.core.PySystemState
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

How can I fix it? I was trying to add –illegal-access=permit to the last line of the script "dmelt.sh" (I'm using bash in Linux), but this did not solve this problem. I'm very frustrating with this. I was using this program very often, for very long time. Maybe I should never move to JDK9

9 Answers

Real issue is a problem in the JDK. There is actually no illegal access, but the JDK method trySetAccessible is misbehaving. This will hopefully be fixed in a future JDK version.

try solve below answer link

To avoid this error, you need to redefine maven-war-plugin to a newer one. For example:

<plugins>
    . . .
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.2</version>
    </plugin>
</plugins>

Works for jdk-12.

Since the Java update 9, the "illegal reflective access operation has occurred" warning occurs.

To remove the warning message. You can replace maven-compiler-plugin with maven-war-plugin and/or updating the maven-war-plugin with the latest version in your pom.xml. Following are 2 examples:

Change version from:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    ...
       
    ...
</plugin>

To:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.3.1</version>
    ...
     ...
</plugin>

Change the artifactId and version From:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>

TO:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.3.1</version>
        <executions>
            <execution>
                <id>prepare-war</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>exploded</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

When i re-run Maven Build or Maven Install, the "illegal reflective access operation has occurred" is gone.

Perhaps the fix below works for java 9 as well:

In my case the java open jdk version was 10.0.2 and got the same error (An illegal reflective access opeeration has occurred). I upgraded maven to version 3.6.0 on linux, and the problem was gone.

Came here while working on a Kotlin Spring project. Resolved the issue by:

cd /project/root/
touch .mvn/jvm.config
echo "--illegal-access=permit" >> .mvn/jvm.config

Some recent feedback.

as stated in the java error code

WARNING: All illegal access operations will be denied in a future release

This future release is JDK 17, where the launcher parameter --illegal-access will stop working.

More information direct from Oracle can be found here: JEP 403 link 1 and JEP 403 link 2

With this change, it will no longer be possible for end users to use the --illegal-access option to enable access to internal elements of the JDK. (A list of the packages affected is available here.) The sun.misc and sun.reflect packages will still be exported by the jdk.unsupported module, and will still be open so that code can access their non-public elements via reflection. No other JDK packages will be open in this way.

It will still be possible to use the --add-opens command-line option, or the Add-Opens JAR-file manifest attribute, to open specific packages.

So the solution --add-opens module/package=target-module(,target-module)* and the example --add-opens java.base/java.io=ALL-UNNAMED will keep working for JDK 17 and future releases but the --illegal-access will not.

Related