Skip to content
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

Open
srijancerner opened this issue Apr 27, 2018 · 8 comments
Open

Warning: Illegal access operation for Java 10 #74

srijancerner opened this issue Apr 27, 2018 · 8 comments

Comments

@srijancerner
Copy link

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.

@kostaskougios
Copy link
Owner

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.

@bergmannm
Copy link

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.

@albertcheng
Copy link

@kostaskougios what shall we do though? downgrade java to java 7 ?

@bergmannm
Copy link

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

  • registerKnownConstants could be called on demand when really needed.
  • or there could be Cloner configuration option for that.

@tweimer
Copy link
Contributor

tweimer commented Mar 11, 2021

@kostaskougios and those it may concern:

In java 16, the default mode will be --illegal-access=deny instead of --illegal-access=permit. See JEP 396.

So, you have to explicitely use permit in combination with this cloner, to have access to private fields, if the module isn't open for reflection.

@Petkomat
Copy link

Petkomat commented Nov 24, 2021

In Java 17, this solution is not a solution anymore: Java HotSpot(TM) 64-Bit Server VM warning: Ignoring option --illegal-access=permit; support was removed in 17.0.

I got the error Unable to make field private transient java.util.Hashtable$Entry[] java.util.Hashtable.table accessible: module java.base does not "opens java.util" to unnamed module @482f8f11

and --add-opens=java.base/java.util=ALL-UNNAMED resolved the issue.

However, this seems like a dirty hack and maybe, it would be better to change the cloner itself if possible.

@albertcheng
Copy link

it is pointless, if they do not want others to use reflection why did they design this feature first place?

@robertvazan
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants