mockito: illegal reflective access operation: AccessibilityChanger

Hi.

I’m using IntelliJ Community 2017.3 and when I run junit tests using “Menu>Run>Run All In Owner” in my project (https://github.com/lviggiano/owner/) I get the following warning at the console:

/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/bin/java -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=51785:/Applications/IntelliJ IDEA CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar:/Applications/IntelliJ IDEA CE.app/Contents/plugins/junit/lib/junit-rt.jar:/Applications/IntelliJ IDEA CE.app/Contents/plugins/junit/lib/junit5-rt.jar:/Users/luigi/var/src/owner/owner/target/test-classes:/Users/luigi/var/src/owner/owner/target/classes:/Users/luigi/.m2/repository/org/hamcrest/hamcrest-all/1.3/hamcrest-all-1.3.jar:/Users/luigi/.m2/repository/junit/junit/4.12/junit-4.12.jar:/Users/luigi/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/Users/luigi/.m2/repository/org/mockito/mockito-core/2.15.0/mockito-core-2.15.0.jar:/Users/luigi/.m2/repository/net/bytebuddy/byte-buddy/1.7.9/byte-buddy-1.7.9.jar:/Users/luigi/.m2/repository/net/bytebuddy/byte-buddy-agent/1.7.9/byte-buddy-agent-1.7.9.jar:/Users/luigi/.m2/repository/org/objenesis/objenesis/2.6/objenesis-2.6.jar:/Users/luigi/.m2/repository/commons-codec/commons-codec/1.11/commons-codec-1.11.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 @w@/private/var/folders/yx/d_5sbt_j7ns2x62q3x_7lcgr0000gn/T/idea_working_dirs_junit.tmp @/private/var/folders/yx/d_5sbt_j7ns2x62q3x_7lcgr0000gn/T/idea_junit.tmp -socket51784
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.mockito.internal.util.reflection.AccessibilityChanger (file:/Users/luigi/.m2/repository/org/mockito/mockito-core/2.15.0/mockito-core-2.15.0.jar) to field java.util.Properties.defaults
WARNING: Please consider reporting this to the maintainers of org.mockito.internal.util.reflection.AccessibilityChanger
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

Process finished with exit code 0

I cannot identify the problematic test, since I have hundreds and this happens when I run them all at once. But eventually if I find the problematic one, I’ll update this issue.

I’m using mockito-core 2.15.0; java 9.0.1, Maven 3.3.9, Mac OS X 10.13.3

/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/bin/java -Dmaven.multiModuleProjectDirectory=/Users/luigi/var/src/owner "-Dmaven.home=/Applications/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3" "-Dclassworlds.conf=/Applications/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3/bin/m2.conf" "-javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=51962:/Applications/IntelliJ IDEA CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2017.3.4 -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T17:41:47+01:00)
Maven home: /Applications/IntelliJ IDEA CE.app/Contents/plugins/maven/lib/maven3
Java version: 9.0.1, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home
Default locale: en_IT, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.3", arch: "x86_64", family: "mac"

Process finished with exit code 0

Thanks & Best regards, L.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 36 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Hi,

Found another similar issue running OpenJDK 11:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.mockito.internal.util.reflection.AccessibilityChanger (file:/..../org.mockito/mockito-core/2.23.0/497ddb32fd5d01f9dbe99a2ec790aeb931dff1b1/mockito-core-2.23.0.jar) to field java.util.HashSet.map
WARNING: Please consider reporting this to the maintainers of org.mockito.internal.util.reflection.AccessibilityChanger
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

In my case, changing the dependency from mockito-all:2.0.2-beta to mockito-core:3.2.4 solved the problem

Ooo… we have a culprit… hopefully this leads to a resolution? PS to the above mentions about downgrading the JDK to 8… yeah, no. That’s useful debugging info not a solution. Need to be able to dev on modern versions of Java… Staying on 8 forever is not an option. Only useful out of that is narrowing down the issue was aggravated by some JDK change between 8 and 9.

Great, thanks for the feedback. I tested it pretty thoroughly this time and even when prohibiting access, Mockito seems to work without any issues on the inline mock maker. There’s one edge cases when mocking a generated class without any constructor but that I don’t believe many will run into.

Just to give feedback for everyone:

using the 2 dependencies with Java 11 and mockito 3.5.15

mockito-core mockito-inline

Successfully removes the warning. If I don’t add the mockito-inline dependency, the warning continues.

Looks like version 1.9.3’s io.mockk.proxy.jvm.ClassLoadingStrategyChooser class is doing illegal reflection. Which is odd since https://github.com/mockk/mockk/pull/278 was supposed to fix issue’s with Java 12

WARNING: Illegal reflective access using Lookup on io.mockk.proxy.jvm.ClassLoadingStrategyChooser

I’m also experiencing this when using a spy with JDK 14 and mockito-core:3.2.4.

mockito-all is old. Please upgrade to a newer version of Mockito.

I have the same issue and changing the JDK is not an option for me. Any updates?

I am still seeing this error with 3.7.7:

WARNING: An illegal reflective access operation has occurred                                                                 
WARNING: Illegal reflective access by org.mockito.internal.util.reflection.ReflectionMemberAccessor (file:/usr/local/google/h
ome/jianglai/.gradle/caches/modules-2/files-2.1/org.mockito/mockito-core/3.7.7/5d43943be9b57c8ff47d2b9640ea0a7fc7211cf2/mocki
to-core-3.7.7.jar) to field java.io.ByteArrayInputStream.buf                                                                 
WARNING: Please consider reporting this to the maintainers of org.mockito.internal.util.reflection.ReflectionMemberAccessor  
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 

I still get a warning with mockito 3.5.5, but the warning has changed.

Running the following test on JDK 14:

    @Test
    public void spyReportsIllegalReflectiveAccess() {
        Mockito.spy(new File("path"));
    }

With mockito-core:3.5.5 I get the following output:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.mockito.internal.util.reflection.ReflectionMemberAccessor (file:/*********/.gradle/caches/modules-2/files-2.1/org.mockito/mockito-core/3.5.5/e8121e886510d920f75af560a3765c6f673e789/mockito-core-3.5.5.jar) to field java.io.File.path
WARNING: Please consider reporting this to the maintainers of org.mockito.internal.util.reflection.ReflectionMemberAccessor

And with mockito-inline:3.5.5 :

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access using Lookup on org.mockito.internal.util.reflection.InstrumentationMemberAccessor$Dispatcher$ByteBuddy$tKOT3Vep to class java.io.File
WARNING: Please consider reporting this to the maintainers of org.mockito.internal.util.reflection.InstrumentationMemberAccessor$Dispatcher$ByteBuddy$tKOT3Vep

The issues seems to be still present in 3.3.3:

OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.mockito.internal.util.reflection.AccessibilityChanger (file:~/.m2/repository/org/mockito/mockito-core/3.3.3/mockito-core-3.3.3.jar) to field java.time.Clock$FixedClock.instant
WARNING: Please consider reporting this to the maintainers of org.mockito.internal.util.reflection.AccessibilityChanger
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