kostaskougios/cloning

Java 9 - illegal reflective access operation

Closed this issue · 3 comments

Hello there

Running on Java9, there are the following warnings when using Cloner.standard().deepCopy():

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.rits.cloning.Cloner (file:/C:/Users/Username/.gradle/caches/modules-2/files-2.1/uk.com.robust-it/cloning/1.9.6/22ff4e3fc66dd84a57f39a9b4c6325e41a389225/cloning-1.9.6.jar) to field java.util.TreeSet.m
WARNING: Please consider reporting this to the maintainers of com.rits.cloning.Cloner
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'm using gradle with the dependency compile 'uk.com.robust-it:cloning:1.9.6'

IntelliJ Ultimate 2017.2.5

Java JDK 9 (build 9+181 mixed mode) x64.

Ok, this must be a JDK warning regarding the access to private fields of classes that Cloner does.
In order to clone, cloner has to access private fields of classes , read them and then write them to the cloned instance. It is the fundamental way it works, I don't think we can do otherwise.

final Object fieldObject = field.get(o);
....
field.set(newInstance, fieldObjectClone);

As long as it works, I don't think there's need to change something.
It would maybe be great to include that in the docs or something the like.
And if it really changes from java 10 onwards, it would be something to consider in the future.

Thanks for your reply, I appreciate active developers!

Thanks, added a note in usage instructions, closing this.