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
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.
Fix issue #278 - NoSuchMethodError when setting static final private …
…field via Deencapsulate.setField
Fixed bug where a "sun.reflect" class was used unnecessarily; closes #…