An internal exception occurred address themida ошибка

At execution of any arbitrary mvn command I get following warnings at the beginning of the logs:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
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

Unfortunately, these warnings sometimes lead to errors at runtime and break my maven command execution. Does anyone know how to address this and get rid of these warnings?

My maven version:

Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 11.0.2, vendor: Azul Systems, Inc.
Java home: /usr/lib/jvm/zulu-11-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-47-generic", arch: "amd64", family: "unix"

asked Apr 3, 2019 at 10:02

wero026's user avatar

wero026wero026

1,1872 gold badges11 silver badges23 bronze badges

0

My best guess: your guice version is not compatible with Java 11.

answered Apr 3, 2019 at 11:00

J Fabian Meier's user avatar

J Fabian MeierJ Fabian Meier

33.7k10 gold badges66 silver badges142 bronze badges

1

I am using Debian and the commands below removed this warning for me.
I am also using OpenJDK 11.

# Download maven 3.6.3
wget https://www.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp

# Untar downloaded file to /opt
sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt

# Install the alternative version for the mvn in your system
sudo update-alternatives --install /usr/bin/mvn mvn /opt/apache-maven-3.6.3/bin/mvn 363

# Check if your configuration is ok. You may use your current or the 3.6.3 whenever you wish, running the command below.
sudo update-alternatives --config mvn

Running the final command, you should select the maven version 3.6.3.
After that the warning will be removed.

рüффп's user avatar

рüффп

5,18734 gold badges67 silver badges113 bronze badges

answered Sep 13, 2020 at 22:38

Georgios Syngouroglou's user avatar

2

As JF Meier mentioned here, my guice version was incompatible with Java 11. A reinstallation of maven with the sdkman resolved this issue for me.

answered Apr 4, 2019 at 9:23

wero026's user avatar

wero026wero026

1,1872 gold badges11 silver badges23 bronze badges

4

If you are using a custom version of Maven or maybe Ubuntu WSL, then, remove Maven, download it from official site and install it.

Example if you have WSL, assuming you have a /c/tools directory:

$ sudo apt-get remove maven
$ cd /c/tools/
$ tar xzvf /c/Users/<USER-NAME>/Downloads/apache-maven-3.6.3-bin.tar.gz
$ echo "PATH=/c/tools/apache-maven-3.6.3/bin:$PATH" >> ~/.profile
$ source ~/.profile
$ mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /c/tools/apache-maven-3.6.3
Java version: 11.0.8, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-18362-microsoft", arch: "amd64", family: "unix"

answered Sep 9, 2020 at 20:37

Adrian Escutia Soto's user avatar

1

I was having the problem even with a recent Maven distribution. It seems that the packaged Mint version reuses the package libguice-java instead of using a guice-4.2.1-no_aop.jar.

So installing the binaries from the Maven site fixed the issue.

answered Sep 25, 2020 at 12:54

borjab's user avatar

borjabborjab

11.2k6 gold badges72 silver badges98 bronze badges

1

I just experienced the issue recently and in my case I was using older version of Spring
So I changed from this

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>

to this

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>

and it worked for my case

answered Nov 12, 2020 at 13:59

Danc-0's user avatar

Guice has just released a new version, the v5.0.1.
Upgrading to this one should fix the problem without having to downgrade your Java version from 11.

There is an issue of this exact same problem in guice’s github.

answered Mar 4, 2021 at 20:35

Juan Cruz Basso's user avatar

1

At execution of any arbitrary mvn command I get following warnings at the beginning of the logs:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
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

Unfortunately, these warnings sometimes lead to errors at runtime and break my maven command execution. Does anyone know how to address this and get rid of these warnings?

My maven version:

Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 11.0.2, vendor: Azul Systems, Inc.
Java home: /usr/lib/jvm/zulu-11-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-47-generic", arch: "amd64", family: "unix"

asked Apr 3, 2019 at 10:02

wero026's user avatar

wero026wero026

1,1872 gold badges11 silver badges23 bronze badges

0

My best guess: your guice version is not compatible with Java 11.

answered Apr 3, 2019 at 11:00

J Fabian Meier's user avatar

J Fabian MeierJ Fabian Meier

33.7k10 gold badges66 silver badges142 bronze badges

1

I am using Debian and the commands below removed this warning for me.
I am also using OpenJDK 11.

# Download maven 3.6.3
wget https://www.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /tmp

# Untar downloaded file to /opt
sudo tar xf /tmp/apache-maven-*.tar.gz -C /opt

# Install the alternative version for the mvn in your system
sudo update-alternatives --install /usr/bin/mvn mvn /opt/apache-maven-3.6.3/bin/mvn 363

# Check if your configuration is ok. You may use your current or the 3.6.3 whenever you wish, running the command below.
sudo update-alternatives --config mvn

Running the final command, you should select the maven version 3.6.3.
After that the warning will be removed.

рüффп's user avatar

рüффп

5,18734 gold badges67 silver badges113 bronze badges

answered Sep 13, 2020 at 22:38

Georgios Syngouroglou's user avatar

2

As JF Meier mentioned here, my guice version was incompatible with Java 11. A reinstallation of maven with the sdkman resolved this issue for me.

answered Apr 4, 2019 at 9:23

wero026's user avatar

wero026wero026

1,1872 gold badges11 silver badges23 bronze badges

4

If you are using a custom version of Maven or maybe Ubuntu WSL, then, remove Maven, download it from official site and install it.

Example if you have WSL, assuming you have a /c/tools directory:

$ sudo apt-get remove maven
$ cd /c/tools/
$ tar xzvf /c/Users/<USER-NAME>/Downloads/apache-maven-3.6.3-bin.tar.gz
$ echo "PATH=/c/tools/apache-maven-3.6.3/bin:$PATH" >> ~/.profile
$ source ~/.profile
$ mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /c/tools/apache-maven-3.6.3
Java version: 11.0.8, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-18362-microsoft", arch: "amd64", family: "unix"

answered Sep 9, 2020 at 20:37

Adrian Escutia Soto's user avatar

1

I was having the problem even with a recent Maven distribution. It seems that the packaged Mint version reuses the package libguice-java instead of using a guice-4.2.1-no_aop.jar.

So installing the binaries from the Maven site fixed the issue.

answered Sep 25, 2020 at 12:54

borjab's user avatar

borjabborjab

11.2k6 gold badges72 silver badges98 bronze badges

1

I just experienced the issue recently and in my case I was using older version of Spring
So I changed from this

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>

to this

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>

and it worked for my case

answered Nov 12, 2020 at 13:59

Danc-0's user avatar

Guice has just released a new version, the v5.0.1.
Upgrading to this one should fix the problem without having to downgrade your Java version from 11.

There is an issue of this exact same problem in guice’s github.

answered Mar 4, 2021 at 20:35

Juan Cruz Basso's user avatar

1

In Java programming, the reflection API lets you examine the internal properties of a running Java program and manipulate them. The name of all its members can be displayed by a Java class, for example.

The «an illegal reflective access operation has occurred» warning message is related to the unauthorized access to parts of the JDK made by tools and libraries using reflection API.

In this article, we are going to show you what «an illegal reflective access operation has occurred» means and how to fix it.

From JDK9, an implementation may provide static access, i.e. by compiled bytecode or may provide a way to invoke its run-time system with one or more packages of one or more of its modules open to code in all unnamed modules, i.e. to code on the classpath.

If the run-time system is invoked in this way, and if by doing so some invocations of the reflection APIs succeed where otherwise they would have failed.

In such cases, you’ve actually ended up making a reflective access which is «illegal» since in a pure modular world you were not meant to do such accesses.

In future releases of the JDK, this illegal access to reflective data will eventually be disabled. JDK 9, 10 and 11 permits it by default. Here is the warning message:

WARNING: An illegal reflective access operation has occurred

WARNING: Illegal reflective access by com.tangosol.internal.util.ObjectFormatter (file:/opt/javaclasses/coherence/coherence.jar) to field java.lang.ref.Reference.referent

WARNING: Please consider reporting this to the maintainers of com.tangosol.internal.util.ObjectFormatter

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

Permit illegal reflective access

Recent JDK versions still, by default, permits illegal access. Alternatively, in future releases, you can pass --illegal-access=permit to the script and it would opens every package in every explicit module to code in all unnamed modules, i.e., code on the class path, just as --permit-illegal-access does today.

The first illegal reflective-access operation causes a warning to be issued, as with --permit-illegal-access, but no warnings are issued after that point. This single warning will describe how to enable further warnings.

Avoid illegal reflective access

The «an illegal reflective access operation has occurred» is merely a warning message and only indicating there is reflective access to JDK internal class without doing anything about it. In the meantime, you can either

  • You can specify the reflective access explicitly using java’s –add-opens parameter. The migration guide for JDK 11 provides more information.
  • Use a compatible and certified version of your software. If the software is actively maintained, then the developers are now aware of the warning and a fix may come in the near future.

Comments

@annarozin

mstrelex

pushed a commit
to testproject-io/java-opensdk
that referenced
this issue

Aug 7, 2020

@gil-testproject

This exclusion strategy makes sure to skip serialization of any classes implementing the WebDriver interface.
Since this object is redundant when reporting command parameters and doesn’t pass serialization - we exclude it.
See google/gson#1540 for more details on the serialization problem. (edited)

Signed-off-by: Gil Eliyahu <gil.eliyahu@testproject.io>

Marcono1234

added a commit
to Marcono1234/gson
that referenced
this issue

Jun 3, 2021

@Marcono1234

Revert google#1218

Usage of sun.misc.Unsafe to change internal AccessibleObject.override field
to suppress JPMS warnings goes against the intentions of the JPMS and does not
work anymore in newer versions, see google#1540.
Therefore remove it and instead create a descriptive exception when making a
member accessible fails. If necessary users can also still use `java` command
line flags to open external modules.

This was referenced

Sep 13, 2021

eamonnmcmanus

pushed a commit
that referenced
this issue

Nov 9, 2021

@Marcono1234

…tor (#1902)

* Remove UnsafeReflectionAccessor

Revert #1218

Usage of sun.misc.Unsafe to change internal AccessibleObject.override field
to suppress JPMS warnings goes against the intentions of the JPMS and does not
work anymore in newer versions, see #1540.
Therefore remove it and instead create a descriptive exception when making a
member accessible fails. If necessary users can also still use `java` command
line flags to open external modules.

* Fix failing to serialize Collection or Map with inaccessible constructor

Also remove tests which rely on Java implementation details.

* Don't keep reference to access exception of ConstructorConstructor

This also avoids a confusing stack trace, since the previously caught
exception might have had a complete unrelated stack trace.

* Remove Maven toolchain requirement

* Address review feedback

* Add back test for Security Manager

tibor-universe

pushed a commit
to getuniverse/gson
that referenced
this issue

Nov 21, 2021

@Marcono1234

@tibor-universe

…tor (google#1902)

* Remove UnsafeReflectionAccessor

Revert google#1218

Usage of sun.misc.Unsafe to change internal AccessibleObject.override field
to suppress JPMS warnings goes against the intentions of the JPMS and does not
work anymore in newer versions, see google#1540.
Therefore remove it and instead create a descriptive exception when making a
member accessible fails. If necessary users can also still use `java` command
line flags to open external modules.

* Fix failing to serialize Collection or Map with inaccessible constructor

Also remove tests which rely on Java implementation details.

* Don't keep reference to access exception of ConstructorConstructor

This also avoids a confusing stack trace, since the previously caught
exception might have had a complete unrelated stack trace.

* Remove Maven toolchain requirement

* Address review feedback

* Add back test for Security Manager

An illegal reflective access operation has occurred Spring Boot and affected your programming experience when installing and using AM, including Amster and ssoadm tools. As a result, your system launches the following invalid message that halts further code alteration: warning: an illegal reflective access operation has occurred Java 11.an illegal reflective access operation has occurred

Luckily, this profound debugging provides several debugging principles and explains why an illegal reflective access operation has occurred Maven, which is vital when applying the solutions.

So, you are at the right place if you want to learn how to clear your system from bugs and errors and complete the application without an illegal reflective access operation has occurred Intellij mistakes.

Contents

  • Why an Illegal Reflective Access Operation Has Occurred?
    • – Installing and Using AM and Java Agent
    • – Installing and Using DM and IDM
    • – Calling Eval on Kotlin Script
  • Fixing the Illegal Reflective Access Operation: Use a Target Module
    • – Repair the Module Declaration
  • Conclusion

An illegal reflective access operation has occurred Eclipse and obliterates your programming experience while using or installing AM, including Amster and ssoadm tools. Henceforth, this is a typical Java bug with most versions, but research confirms it is most familiar with Java 10 and 11.

The Java version is essential when understanding the possible culprits and causes for an illegal reflective access operation has occurred PySpark. For instance, before Java 9, developers had a superpower using the Java Reflection API because they could access the non-public class members without limitation.

However, things changed drastically after Java 9 because the modular system tends to limit the Java Reflection API to a specific extent. Therefore, an illegal reflective access operation has occurred Spark error pops up while working with specific Java versions and commands.

In addition, this invalid code exception usually lies within the module system, and the strong encapsulation triggers a mistake. For instance, a migration in Java 9 may provide static access, which is compiled by bytecode, a tool that helps developers change specific values and properties.

As a result, an illegal reflective access operation has occurred Mockito when misspelling the strong encapsulation of the modules, which must be precise. Luckily, this debugging guide includes chapters that recreate the error and provide adequate debugging solutions using real-life examples and scripts.

– Installing and Using AM and Java Agent

As explained before, this error’s primary and possible cause is using and installing AM, including ssoadm and Amster tools. However, learning about this cause requires developers to discover the invalid script and exception snippets.

These warning messages indicate where the code fails, what is the exact weak element, and how developers can alter their code to debug the error. In addition, we will show you several product messages that are slightly different but still cover the same mistake.

The following example introduces the AM invalid code snippet:

WARNING: An illegal reflective access operation has happened

WARNING: Illegal reflective access by org.codehaus.groove.plugin.v7.Java7$2 (file:/path/ to/ tomcat/ webapps/ am/ WEB-INF/ lib/ groovy-2.5.6.jar (about:blank)) to constructor java.lang.invokes.MethodHandle$Lookup(java.lang.Class,int)

WARNING: Please consider reporting this to the maintainer of org.codehaus.groovy.vmplugin.v7.Java7$2

WARNING: Use –illegal-access=warn to enable warning of further illegal reflective access operation

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

These messages appear in AM projects, but what about other programs? The next example shows the incorrect script when using Java Agent:

WARNING: An illegal reflective access operation has happened

WARNING: Illegal reflective access by org.forgerock.sdk.com.google.inject.internal.lib.core.$ReflectUtils$2 (file:/ tmp/ 5.6.1/ java_agents/ tomcat_agent/ lib/ jee-agents-installtools-5.6.1.jar) to method java.lang.ClassLoaders.defineClass(java.lang.Strings,byte[],int,int,java.security.ProtectionDomain)

WARNING: Please consider reporting this to the maintainer of org.forgerock.openam.sdk.com.google.inject.lib.core.$ReflectUtil$2

WARNING: Use –illegal-access=warn to enable warning of future illegal reflective access operation

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

Unfortunately, similar warning messages appear in DS and IDM. Readers should notice the slight difference and compare them to their documents.

– Installing and Using DM and IDM

Programmers usually experience identical errors when using or installing DM and IDM, but only with specific versions. Namely, the mistake will only affect DS 6.5.x and IDM 6.5.x versions because several properties confuse your system.An Illegal Reflective Access Operation Has Occurred Causes

However, as you will soon see, although these are different programs and applications, the exceptions are similar because they discuss the same matter. Therefore, we suggest comparing the warning in your system to learn how to pinpoint the mistake and change the properties afterwards.

This example introduces the invalid DM script warnings:

WARNING: An illegal reflective access operation has happened

WARNING: Illegal reflective access by org.opends.server.util.Platform$PlatformIMPL (file:/ path/ to/ ds/ lib/ opendj.jar) to constructor sun.security.tools.keytool.CertAndKeyGen (java.lang.String,java.String)

WARNING: Please consider reporting this to the maintainer of org.opends.server.util.Platform$PlatformIMPL

WARNING: Use –illegal-access = warn to enable warning of further illegal reflective access operation

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

The exact location is the only similarity all warnings have because they cover a similar project. Lastly, let us discover the IDM syntax that ruins your programming experience below:

WARNING: An illegal reflective access operation has happened

WARNING: Illegal reflective access by org.apache.framework.ext.ClassPathExtenderFactory$DefaultClassLoaderExtender (file:/ path/ to/ idm/ bin/ felix.jar) to method java.net.ClassLoader.addURL (java.net.URL)

WARNING: Please consider reporting this to the maintainer of org.apache.framework.ext.ClassPathExtenderFactory$DefaultClassLoaderExtender

WARNING: Use –illegal-access=warn to enable warning of further illegal reflective access operation

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

As you will soon learn, these messages should not be challenging to repair.

– Calling Eval on Kotlin Script

Our final example before providing the finest solution calls eval on a Kotlin script, which is standard with complex projects. However, to keep it short and precise, we will not give the full syntax because we will focus on the specific code snippets that recreate this invalid instance. First, we will show you the plugins and then exemplify the imported main commands. They should be sufficient to understand where the code is broken.

The following example includes both plugins and imports:

plugins {

kotlin (“jvm”) version “1.4.20”

}

val kotlinVersion = “1.4.20”

dependencies {

implementation (kotlin(“stdlib”))

implementation (“org.jetbrains.kotlin:kotlin-scripting-jsr223:$kotlinVersion”)

}

import javax.script.ScriptEngineManager

fun main() {

with (ScriptEngineManager().getEngineByExtension (“kts”)) {

eval (“val x = 3”)

val res2 = eval (“x + 2”)

println (res2)

}

}

Although we can list other invalid examples, it is time to discover solutions to help you clear your syntax without complications.

Fixing the Illegal Reflective Access Operation: Use a Target Module

The most sophisticated method of fixing this illegal caller exception at runtime is introducing the correct target and source modules to your script. However, developers must be aware this method will only succeed when we call from the modified module, modules with granted access, and the unnamed module.

In addition, another excellent way of adding opens to the target module requires a Java Agent in the instrument module. As explained earlier, the specific class has added a new redefined module since Java 9. Fortunately, developers can use this method to provide extra exports, opens, and reads that debug your program.

Learn how to apply this solution by looking at the following example:

void redefineModule(Instrumentation inst,
Module src, Module target) {// prepare extra reads

Set<Module> extraReads = Collections.singleton(target);

// prepare extra exports

Set<String> packages = src.getPackages();

Map<String, Set<Module>> extraExports = new HashMap<>();

for (String pkg : packages) {

extraExports.put(pkg, extraReads);

}

// prepare extra opens

Map<String, Set<Module>> extraOpens = new HashMap<>();

for (String pkg : packages) {

extraOpens.put(pkg, extraReads);

}

// prepare extra uses

Set<Class<?>> extraUses = Collections.emptySet();

// prepare extra provides

Map<Class<?>, List<Class<?>>> extraProvides = Collections.emptyMap();

// redefine module

inst.redefineModule (src, extraReads, extraExports, extraOpens, extraUses, extraProvides);

}

This code first utilizes the target module to create the extra reads, exports and opens variables. Then, it invokes the redefined module method that allows the source module to be accessible to the target module. This should debug the code and allow you to complete your projects without any hassle.

– Repair the Module Declaration

The second advanced debugging method requires developers to repair the module declaration. Namely, programmers can open the package in the module info and change several settings. However, you must be a code author to complete this operation. In addition, this process consists of three modules that fix the invalid code snippets and warnings.Repair the Module Declaration

So, the first step is opening the package in the module info, as shown below:

module baeldung.reflected {

opens com.baeldung.reflected.opened;

}

Developers can be more cautious and avoid other complications by using the qualified opens that determine the module and its property. We suggest repeating the following code to debug the project:

module baeldung.reflected {

opens com.baeldung.reflected.internal to baeldung.intermedium;

}

Although only a single code difference exists, it provides an excellent alternative when safely opening the package in the module-info. Developers and programmers can unlock the entire module when migrating the existing code to the modular system.

You can discover the necessary command in the following example:

open module baeldung.reflected {

// don’t use opens directive

}

This example completes the second debugging principle that fixes the illegal reflective access without causing further complications. As you can tell, you should have no issues implementing these advanced methods in your document or application.

Conclusion

Programmers sometimes experience an illegal reflective access operation mistake in their programs when using or installing AM, including Amster and ssoadm tools. Luckily, this comprehensive guide introduced several debugging methods and explained the following points:

  • This error can affect many programs and applications, although it is typical for AM
  • The warnings launched by the system indicate the invalid location
  • Developers can recreate the invalid message by using the same values
  • The sophisticated debugging methods require adding some target modules

Although developers will likely experience this mistake again when compiling their projects, fixing it should no longer be an issue. So, remain calm the next time you face an illegal reflective access operation because this guide has all you need.

  • Author
  • Recent Posts

Position is Everything

Your Go-To Resource for Learn & Build: CSS,JavaScript,HTML,PHP,C++ and MYSQL. Meet The Team

Position is Everything

In Java programming, the reflection API lets you examine the internal properties of a running Java program and manipulate them. The name of all its members can be displayed by a Java class, for example.

The «an illegal reflective access operation has occurred» warning message is related to the unauthorized access to parts of the JDK made by tools and libraries using reflection API.

In this article, we are going to show you what «an illegal reflective access operation has occurred» means and how to fix it.

From JDK9, an implementation may provide static access, i.e. by compiled bytecode or may provide a way to invoke its run-time system with one or more packages of one or more of its modules open to code in all unnamed modules, i.e. to code on the classpath.

If the run-time system is invoked in this way, and if by doing so some invocations of the reflection APIs succeed where otherwise they would have failed.

In such cases, you’ve actually ended up making a reflective access which is «illegal» since in a pure modular world you were not meant to do such accesses.

In future releases of the JDK, this illegal access to reflective data will eventually be disabled. JDK 9, 10 and 11 permits it by default. Here is the warning message:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.tangosol.internal.util.ObjectFormatter (file:/opt/javaclasses/coherence/coherence.jar) to field java.lang.ref.Reference.referent
WARNING: Please consider reporting this to the maintainers of com.tangosol.internal.util.ObjectFormatter
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

Recent JDK versions still, by default, permits illegal access. Alternatively, in future releases, you can pass --illegal-access=permit to the script and it would opens every package in every explicit module to code in all unnamed modules, i.e., code on the class path, just as --permit-illegal-access does today.

The first illegal reflective-access operation causes a warning to be issued, as with --permit-illegal-access, but no warnings are issued after that point. This single warning will describe how to enable further warnings.

Avoid illegal reflective access

The «an illegal reflective access operation has occurred» is merely a warning message and only indicating there is reflective access to JDK internal class without doing anything about it. In the meantime, you can either

  • You can specify the reflective access explicitly using java’s –add-opens parameter. The migration guide for JDK 11 provides more information.
  • Use a compatible and certified version of your software. If the software is actively maintained, then the developers are now aware of the warning and a fix may come in the near future.

You’re probably here because you recently restarted Spring Boot and found something like this unappetizing stacktrace in your console:

java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled
at io.netty.util.internal.ReflectionUtil.trySetAccessible(ReflectionUtil.java:31)
at io.netty.util.internal.PlatformDependent0$4.run(PlatformDependent0.java:238)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:232)
at io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:293)
at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:92)
at io.netty.util.ConstantPool.<init>(ConstantPool.java:32)
at io.netty.channel.ChannelOption$1.<init>(ChannelOption.java:36)
at io.netty.channel.ChannelOption.<clinit>(ChannelOption.java:36)
at reactor.netty.tcp.TcpClient.<clinit>(TcpClient.java:677)
at reactor.netty.http.client.HttpClient.<clinit>(HttpClient.java:1388)
at org.springframework.http.client.reactive.ReactorClientHttpConnector.<init>(ReactorClientHttpConnector.java:56)
at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.getOrInitConnector(DefaultWebClientBuilder.java:282)
at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.build(DefaultWebClientBuilder.java:260)
at us.careydevelopment.web.registration.service.RegistrationUserService.<init>(RegistrationUserService.java:33)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:204)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:117)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:310)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:295)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1356)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1203)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1307)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1227)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at us.careydevelopment.web.registration.Registration.main(Registration.java:10)
03:27:38.120 [main] DEBUG i.n.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true
03:27:38.121 [main] DEBUG i.n.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable
java.lang.IllegalAccessException: class io.netty.util.internal.PlatformDependent0$6 cannot access class jdk.internal.misc.Unsafe (in module java.base) because module java.base does not export jdk.internal.misc to unnamed module @2e2f720
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591)
at java.base/java.lang.reflect.Method.invoke(Method.java:558)
at io.netty.util.internal.PlatformDependent0$6.run(PlatformDependent0.java:352)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:343)
at io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:293)

And that stacktrace goes on.

Now you’re pulling your hair out wondering how to fix it.

So you went to your favorite search engine to look for ideas and that’s what led you here.

Well, I can’t guarantee you that what I’m about to tell you will fix it in your situation. But I can say that it worked for me.

Let me share what I discovered.

TL;DR: Upgrade to a Later Version of Spring Boot

Alas, sometimes the simplest solutions are the easiest to overlook.

And in my case it was the simplest solution that worked.

I just updated Spring Boot to a later version.

In my POM file, I previously had this:

    <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.8.RELEASE</version>
</parent>

That’s the 2.3.8.RELEASE version of the Spring Boot starter parent.

All I did was change that to this:

    <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.3</version>
</parent>

Upgraded to 2.5.3. 

After making that change, I restarted Spring Boot. Then the problem disappeared like a politician’s promises after election day.

If that doesn’t work for you, then that means you’re going to have to keep searching. Sorry. :(

More Info

So what the heck is going on here?

In my case, the problem appeared once I included the Spring WebFlux depdency:

 <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

Without that, the problem didn’t show up.

And that makes sense because the underlying complaint comes from Netty.

If you’re unfamiliar with Netty (or Reactor Netty), it’s the default server used by WebFlux. It’s an asynchronous framework design to work with reactive programming.

So there’s another possible solution: you can eliminate WebFlux if you can live without it.

Yeah, that’s a big if.

And you shouldn’t have to go that route anyway. So I don’t view that as a viable fix.

Suppressing Fire

Some folks like to add VM arguments to suppress the exception stacktrace.

But that’s not really a solution. It’s just a way to eliminate a nuisance.

That’s ignoring a problem rather than dealing with it.

I tried it anyway. Just for kicks and giggles.

I added the following VM arguments:

--add-opens java.base/jdk.internal.misc=ALL-UNNAMED
-Dio.netty.tryReflectionSetAccessible=true
--add-opens java.base/java.lang=ALL-UNNAMED

And when I did that and restarted Spring Boot, I got this in the console instead of that stacktrace you see above:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.netty.util.internal.ReflectionUtil (file:/C:/Users/carey/.m2/repository/io/netty/netty-common/4.1.58.Final/netty-common-4.1.58.Final.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.ReflectionUtil
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

That’s better. But Spring still complained.

Eventually, I opted for the upgrade solution I suggested above. It worked for me.

I hope it works for you as well.

Wrapping It Up

Sorry if this didn’t fix your problem.

If that’s the case, rest assured you will eventually slay this Goliath. Because you’re cool like that.

Have fun!

Photo by Erik Mclean from Pexels

Problem Description

LatestSpring BootProject upgrade toJDK 11The warning is found when running as follows:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/D:/Android/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.2.0.RELEASE/e0e1b3c304f70ed19d7905975f6f990916ada219/spring-core-5.2.0.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils
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

20191021205420.png

solution

Option One

Add JVM startup parameters:

java --illegal-access=deny

This parameter in Java 9 is: permit

20191021205515.png

Option II

Add the following method in the startup class, pro-test JDK 11 is effective

public static void disableWarning() {
try {
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
Unsafe u = (Unsafe) theUnsafe.get(null);
Class cls = Class.forName("jdk.internal.module.IllegalAccessLogger");
Field logger = cls.getDeclaredField("logger");
u.putObjectVolatile(cls, u.staticFieldOffset(logger), null);
} catch (Exception e) {
// ignore
    }
}

Tune the above method when starting Spring boot

public static void main(String[] args) {
disableWarning(); //Disable warning
SpringApplication.run(AppApplication.class, args);
}

reference

reference:
https://stackoverflow.com/questions/46454995/how-to-hide-warning-illegal-reflective-access-in-java-9-without-jvm-argument
https://blog.csdn.net/qq_25958497/article/details/87258748
https://stackoverflow.com/questions/53790182/get-the-current-value-of-illegal-access-setting-in-java


Processing «Error: (11, 25) Java: Package JDK.Internal.misc does not exist»

Solution 1: Switch the JDK to 1.8 version

 

 

Option II:

Add parameters when compiling
--add-exports java.base/jdk.internal.misc=ALL-UNNAMED
Add parameters when running
--add-opens java.base/jdk.internal.misc=ALL-UNNAMED

Понравилась статья? Поделить с друзьями:
  • An error occurred during the process ошибка zbrush
  • An exception has occurred being a dik ошибка
  • Amr error пионер пропадает звук и ошибка
  • An error occurred during decryption ошибка
  • Amrestoreerrordomain ошибка 9