-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warning: Illegal access operation for Java 10 #74
Comments
cloning is heavily based on reflection and reflective access of private fields. I suppose if newer Java versions blocks that, then the library will be unusable. My guess is that there should be a way to override it in future versions of Java but we can't be sure at the moment. |
Actually, the Java#10 warning could be avoided for most use cases. It's caused by Cloner.registerKnownConstants() method, which scans static fields of a few java.util classes (Maps&Sets) . But this rarely needed, because they are usually cloned by FastCloner . Only when cloning class, which inherits from one of TreeSet, HashSet, HashMap, TreeMap, static fields need to be scanned. |
@kostaskougios what shall we do though? downgrade java to java 7 ? |
Downgrade to java 7 won't resolve the issue, because new Java versions are here to stay. I suppose there is only one way to really fix it - don't use reflection on java internal classes, because it's going to stop working with future java versions anyway. Since Oracle is releasing new Java versions quite rapidly, it may happen pretty soon. For backward compatibility
|
@kostaskougios and those it may concern: In java 16, the default mode will be So, you have to explicitely use |
In Java 17, this solution is not a solution anymore: I got the error and However, this seems like a dirty hack and maybe, it would be better to change the cloner itself if possible. |
it is pointless, if they do not want others to use reflection why did they design this feature first place? |
@albertcheng Since Java 9, every module decides for itself whether it wants to open its classes for reflection. The correct solution is to turn every library into a module and "open" (in module-info.java) those libraries where reflection makes sense. For java.base, this library should have dedicated fast cloner for every class that needs it. |
Although deepClone is working fine for me in Java#10 but I am getting the warning messages:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.rits.cloning.Cloner (file:/D:/eclipse_neon/workspace/CloneTest/cloning-1.9.9.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
Is there any plan work on it ? As there is a possibility of these operations will actually be denied in near future.
The text was updated successfully, but these errors were encountered: