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
NoSuchMethodError on Decapsulation.setField with JDK9 build 118 #278
Comments
Is the test calling Deencapsulation.setField on a static final field? If so, it won't work on JDK 9 for the reason exposed, and the test should be changed. However, apart from that there is no problem in keeping this method for use on JDK 8 or older. |
Yes, the call from which this stack trace was taken does set a static final field. It works in JDK8 just fine. It doesn't work in JDK9, as of build 115. Apparently, we have about a thousand such calls in our tests, so changing all of these tests isn't particularly feasible. Are you saying that you are unable to make it work in the latest JDK9? |
As far as I know, there is no way to make it work in JDK 9, because they removed the "sun.reflect.ReflectionFactory" class, with no equivalent replacement. I did some google searches, but couldn't find anything useful on the topic. I am inclined to remove this feature (the ability to set a static final field), as it has always been of dubious value anyway. And if it won't be possible anymore in Java 9+, people will have to change their tests sooner or later. |
Take a look at the method setPrivateStaticField in this class I have confirmed that this works in JDK9, other than for primitives and strings, which the compiler might optimize away. It turns out to be quite useful in a lot of cases, at least with regard to test written with SimpleStub. With JMockit, you could probably do it a different way; unfortunately, a lot of our developers have chosen to do it this way. |
Yes, it does work. For some reason, I thought that setting the field through "ReflectionFactory#newFieldAccessor(...)" was needed, but it's not. |
…rivate field via Deencapsulate.setField
We get:
java.lang.NoSuchMethodError: sun.reflect.ReflectionFactory.newFieldAccessor(Ljava/lang/reflect/Field;Z)Lsun/reflect/FieldAccessor;
at weblogic.server.ServerLifecycleRuntimeTest.testShutdownRequestTimeout(ServerLifecycleRuntimeTest.java:244)
at weblogic.server.ServerLifecycleRuntimeTest.testNewDefaultShutdownRequestTimeout(ServerLifecycleRuntimeTest.java:222)
when running with JMockit 1.23 on the latest version of JDK9, as JMockit is using internal Sun APIs to access internals. These were removed in build 115
The text was updated successfully, but these errors were encountered: