jmockit / jmockit1

Advanced Java library for integration testing, mocking, faking, and code coverage
Other
458 stars 238 forks source link

java.lang.UnsupportedOperationException: class redefinition failed: attempted to change the class NestHost, NestMembers, Record, or PermittedSubclasses attribute #744

Open mgorovoy opened 1 year ago

mgorovoy commented 1 year ago

Please provide the following information:

The issue #740 appears to describe the same situation, but lacks details or example to reproduce it.

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.

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. jmockit-test.tar.gz