-
Notifications
You must be signed in to change notification settings - Fork 892
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
Java 16 and 17 compatibility #191
Comments
Did you place cglib in a module? This is supposed to solve your problem. Alternatively, you can change the setting that forbids accessing internal API. |
cglib is a transitive dependency so I can't put it in a module. As I mentioned above,
|
@raphw can you please explain what you mean by you can change the setting that forbids accessing internal API.? thank you |
I believe the correct fix for this problem would be for cglib to ship with a |
JEP 403 targeted for JDK 17 (release planned for Sept 2021) will remove cglib can go with standard replacements for the most commonly used internal elements of the JDK. |
Same issue here, using |
FYI: I've just implemented an initial hacky workaround to make cglib some kind of work with JDK17. See this commit rototor@cc8632e It's ugly because it needs to get a class in the package of the class going to be defined. To do so it does some "magic" with the class path, including (in my case) stripping "Wicket_Proxy_" prefixes. Feel free to use this as a base to make a clean version of it. (The real solution for me would be if Wicket just migrated to ByteBuddy...) |
Is there likely to be a Java 17 compatibility fix in the near future? I know Apache Wicket are affected by this and looking at putting in a fix but if a fix is planned at this end, they don't need to worry. https://issues.apache.org/jira/browse/WICKET-6913 |
Instead of layering one hack on top of another, wouldn't it be better to implement this using public methods that are guaranteed to continue working in the future? |
Any update for the fix for java 17? |
Last commit to this project is August 2019. Methinks it's time to bury it. |
@adityajoshee I don't think that there will be a fixed release for JDK 17. If at any way possible you should migrate to ByteBuddy. If you have CGLib as dependency of some other library you use, you should try to migrate to the latest version of this library. E.g. Wicket and Hibernate already migrated away to ByteBuddy. As a last resort you can use my commit rototor@cc8632e as a base for your own local built and deployed cglib version. |
FYI all, I added a note to the top-level README about its current state: IMPORTANT NOTE: cglib is unmaintained and does not work well (or possibly at all?) in newer JDKs, particularly JDK17+. If you need to support newer JDKs, we will accept well-tested well-thought-out patches... but you'll probably have better luck migrating to something like ByteBuddy. |
For those unable to migrate to ByteBuddy easily, Spring Framework maintains patches for cglib that include compatibility for Java 17, you could do a similar thing and embed cglib into your sources: |
try add jvm option |
I have replace cglib to the one embeded in spring framework, but the issue still occurs: org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @385e9564 |
It can be solved without any JVM parameter with Burningwave Core reflection components that thanks to a special driver work on all JDKs from 8. In this case you can also simply call the method |
Problem solved,thank you very much |
Switched to ByteBuddy for the imposteriser. I was using `cglib` before, but it is not compatible with Java 16+ and there are no signs it will get fixed any time soon. I can now compile and run tests using Java 19. cglib/cglib#191 The JUnit 4 integration needed a different `Mockery`, for some reason. I had to add a no-arg constructor to `ConstantPool` so that jMock could mock it with the new ByteBuddy imposteriser. ByteBuddy has a lot of difficulty imposterizing some classes. One test was trying to mock `PrintWriter` and I had to rewrite it to validate the output using a wrapped `StringWriter` instead.
How do it in Idea? |
just use spring-core cglib,do not need to change code:
import org.springframework.cglib.proxy.Enhancer; |
Hi - Can you please where and how did you added these jvm options? I am using maven, spring boot latest versions, while migrating to jdk 17 i am getting InaccessibleObjectException, please advise. Thanks, |
网上一大把 |
Hi, did you get this working? Please advise how did you solved this issue? |
I seem to have found the answer, it works fine on spring-core-6.0.15 and the key to the fix lies in this patch. |
IntelliJ top bar -> Run -> Edit Configurations -> Modify options -> Add VM options -> Add the below option.
Add the above JVM option to your classes that use CGLIB. This should basically unlock reflection access on certain paths. This error is caused by the module system introduced in Java 9 and later. It indicates that CGLIB tried to access the Specifically, Java's module system restricts reflection access to certain packages or classes by default, and It need to make reflection access unrestricted by default on certain paths. Therefore, add the following JVM option. |
not working at all |
https://stackoverflow.com/questions/66974846/java-lang-exceptionininitializererror-with-java-16-j-l-classformaterror-access/67006749#67006749 --»» adding following VM params does not work::(baler beta bal) --add-opens java.base/java.lang=ALL-UNNAMED cglib/cglib#191
https://stackoverflow.com/questions/66974846/java-lang-exceptionininitializererror-with-java-16-j-l-classformaterror-access/67006749#67006749 --»» adding following VM params does not work::(baler beta bal) --add-opens java.base/java.lang=ALL-UNNAMED cglib/cglib#191
This worked for me, thanks! |
Upgrading to Java 16 I receive the following Exception. I tried adding the VM option
--add-opens java.base/java.lang=ALL-UNNAMED
which I thought would work around the issue to no avail.The text was updated successfully, but these errors were encountered: