What to do about "illegal reflective access"

991 views
Skip to first unread message

Chris Dams

unread,
Aug 16, 2022, 9:36:28 AM8/16/22
to mockito
Dear All,

Running my tests yields the warning below.

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.mockito.internal.util.reflection.ReflectionMemberAccessor (file:/home/chrisd/.m2/repository/org/mockito/mockito-core/4.7.0/mockito-core-4.7.0.jar) to field java.lang.Thread.name
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 tried to debug/simplify and found out that merely doing thread = spy(new Thread()) in a test leads to this warning being displayed. (In the actual test I am trying to spy on a class that inhertis from Thread, but the result is the same). Should something be done about this warning or is it harmless? It sounds bad that "All illegal access operations will be denied in a future release".....

One option would be to try to make the Thread a member of the relevant class instead of inheriting from it.

Kind Regards,
Chris

Tim van der Lippe

unread,
Aug 16, 2022, 2:41:52 PM8/16/22
to moc...@googlegroups.com
You can find more information about this in https://github.com/mockito/mockito/issues/1325

TLDR: use mockito-inline

Op di 16 aug. 2022 om 15:36 schreef Chris Dams <chris....@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/b4bb05c7-5eb6-4c37-8ecb-0a152bae0c3bn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages