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

Closed
russgold opened this Issue May 18, 2016 · 5 comments

Comments

2 participants
@russgold

russgold commented May 18, 2016

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

@rliesenfeld rliesenfeld added the other label May 18, 2016

@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld May 18, 2016

Member

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.

Member

rliesenfeld commented May 18, 2016

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.

@russgold

This comment has been minimized.

Show comment
Hide comment
@russgold

russgold May 18, 2016

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?

russgold commented May 18, 2016

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?

@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld May 18, 2016

Member

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.

Member

rliesenfeld commented May 18, 2016

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.

@russgold

This comment has been minimized.

Show comment
Hide comment
@russgold

russgold May 18, 2016

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.

russgold commented May 18, 2016

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.

@rliesenfeld rliesenfeld self-assigned this May 19, 2016

@rliesenfeld rliesenfeld added bug and removed other labels May 19, 2016

@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld May 19, 2016

Member

Yes, it does work. For some reason, I thought that setting the field through "ReflectionFactory#newFieldAccessor(...)" was needed, but it's not.

Member

rliesenfeld commented May 19, 2016

Yes, it does work. For some reason, I thought that setting the field through "ReflectionFactory#newFieldAccessor(...)" was needed, but it's not.

russgold added a commit to russgold/jmockit1 that referenced this issue May 20, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment