You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description of the problem or enhancement request: Execution of a test that mocks specific class results in following exception - java.lang.UnsupportedOperationException: class redefinition failed: attempted to change the class NestHost, NestMembers, Record, or PermittedSubclasses attribute
Check the following:
If a defect or unexpected result, JMockit project members should be able to reproduce it.
For that, include an example test (perhaps accompanied by a Maven/Gradle build script) which
can be executed without changes and reproduces the failure.
If an enhancement or new feature request, it should be justified by an example test
demonstrating the validity and usefulness of the desired enhancement or new feature.
The issue does not fall outside the scope of the project (for example, attempting to use
JMockit APIs from Groovy or Scala code, or with an Android runtime).
The JDK where the problem occurs is a final release, not a development build.
I've stripped the class from our product that was being mocked until I found the minimum viable example of the test (attached) that causes it to fail. I've been able to reproduce the failure both with Maven 3.9.3 (see below), as well as Eclipse 2023-6 on macOS. I've tried both OpenJDK 17.0.2 on macOS and Oracle JDK 17.0.2 on Windows with the same results.
The issue seems to occur because the first element in static enum declaration overrides a method of the enum class as follows.
COUNT {
@Override
public void send(OutputStream outputStream) throws IOException {
// do something
}
},
Removing this override as follows makes the exception disappear.
COUNT,
Unfortunately, we use this type of construct in many places throughout our product, and the specific class that this example is borrowed from is mocked very extensively throughout our tests.
Please look this over mockito/mockito#2315 as it seems same issues existed with byte buddy and mockito that were fixed. I don't know what the fix was specifically but some users comment that mocking enums is a dubious process and there are other ways around it. Possibly one of those might resolve it for you or possibly you can find more info on what was fixed that we could also fix.
hazendaz
changed the title
java.lang.UnsupportedOperationException: class redefinition failed: attempted to change the class NestHost, NestMembers, Record, or PermittedSubclasses attribute
java 17 and enums: class redefinition failed: attempted to change the class NestHost, NestMembers, Record, or PermittedSubclasses attribute
Dec 2, 2023
When upgrading to Java 17, we saw these errors in many different tests using the latest jmockit from this repo (version 1.53.0). The fix for one of the tests was to not mock java.lang.reflect.Method. It's a silly object to mock because it's so easy to get a real impl.
Please provide the following information:
Version of JMockit that was used: 1.50.0
Version of JDK that was used: 17.0.2
Version of Maven that was used: 3.9.3
Description of the problem or enhancement request: Execution of a test that mocks specific class results in following exception - java.lang.UnsupportedOperationException: class redefinition failed: attempted to change the class NestHost, NestMembers, Record, or PermittedSubclasses attribute
Check the following:
If a defect or unexpected result, JMockit project members should be able to reproduce it.
For that, include an example test (perhaps accompanied by a Maven/Gradle build script) which
can be executed without changes and reproduces the failure.
If an enhancement or new feature request, it should be justified by an example test
demonstrating the validity and usefulness of the desired enhancement or new feature.
The issue does not fall outside the scope of the project (for example, attempting to use
JMockit APIs from Groovy or Scala code, or with an Android runtime).
The JDK where the problem occurs is a final release, not a development build.
I've stripped the class from our product that was being mocked until I found the minimum viable example of the test (attached) that causes it to fail. I've been able to reproduce the failure both with Maven 3.9.3 (see below), as well as Eclipse 2023-6 on macOS. I've tried both OpenJDK 17.0.2 on macOS and Oracle JDK 17.0.2 on Windows with the same results.
$ mvn -v
Apache Maven 3.9.3 (21122926829f1ead511c958d89bd2f672198ae9f)
Maven home: /usr/local/Cellar/maven/3.9.3/libexec
Java version: 17.0.7, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk@17/17.0.7/libexec/openjdk.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "13.4.1", arch: "x86_64", family: "mac"
The issue seems to occur because the first element in static enum declaration overrides a method of the enum class as follows.
Removing this override as follows makes the exception disappear.
Unfortunately, we use this type of construct in many places throughout our product, and the specific class that this example is borrowed from is mocked very extensively throughout our tests.
jmockit-test.tar.gz
The text was updated successfully, but these errors were encountered: