Skip to content
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

InternalError when using mockito 5.3 with -XX:+AllowEnhancedClassRedefinition #259

Closed
schmidti159 opened this issue Nov 28, 2023 · 5 comments
Assignees

Comments

@schmidti159
Copy link

schmidti159 commented Nov 28, 2023

Hi,
we recently upgraded from Spring Boot 2.7 to Spring Boot 3.1 and with this we also upgraded mockito from 4.5.1 to 5.3.1 and bytebuddy from 1.12.23 to 1.14.10.

We use JBR in our development flow with -XX:+AllowEnhancedClassRedefinition to have faster development cycles when working on UI tests so no restart is required.

After the upgrade we see exceptions caused by java.lang.InternalError in our tests when we use JBR with this flag.

I uploaded a minimal reproducer here: https://github.com/schmidti159/reproducer_for-internal_error_in_jbr_with_mockito

The readme also contains the complete stacktrace and steps how to reproduce.

I am using IntelliJ IDEA 2023.2.5 to start the test and could reproduce it with JBR version 17.0.9+7-b1087.3

Could you please have a look? Having enhanced class redefinition is very valuable to our development workflow.

@schmidti159 schmidti159 changed the title InternalError when using mockito with -XX:+AllowEnhancedClassRedefinition InternalError when using mockito 5.3 with -XX:+AllowEnhancedClassRedefinition Nov 28, 2023
@mkartashev
Copy link
Collaborator

Thanks for reporting this, I filed JBR-6363 in our issue tracker.

@skybber
Copy link
Collaborator

skybber commented Dec 12, 2023

This problem is a bit more difficult. The sample program uses PowerMock, which redefines java.lang.Object, which results in redefining all subclasses, i.e. almost all the classes just loaded in ClassLoader. In this case, there are ~4,000 classes. The size wouldn't be such a problem, but the problem is that it redefines java.lang.Object, which has a lot of bindings and dependencies in the JVM and the current DCEVM doesn't support redefinition of this class. However, a fix is being worked on, but it won't be in the short term, this is a major intervention in the DCEVM code.

@schmidti159
Copy link
Author

Thank you for your analysis. I was not aware that the sample was using PowerMock explicitly, so I looked at it again.
The root cause of why it only occurred now, is that Mockito changed the default MockMaker with version 5. Before it was using the subclass MockMaker, now the default is the inline MockMaker (see https://github.com/mockito/mockito/releases/tag/v5.0.0).

So if the subclass MockMaker is enough for the current project a simple workaround is to add this dependency to the project:

    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-subclass</artifactId>
      <scope>test</scope>
    </dependency>

@skybber
Copy link
Collaborator

skybber commented Jan 22, 2024

There is a jbr branch with the patch available at:

https://github.com/JetBrains/JetBrainsRuntime/tree/vladimir.dvorak/JBR-6363

if you know how to build a JDK, it would be great if you could try it on your case, but don't feel it's necessary

@skybber
Copy link
Collaborator

skybber commented Feb 12, 2024

New release https://github.com/JetBrains/JetBrainsRuntime/releases/tag/jbr-release-17.0.10b1186.1 support redefinition of java.lang.object, so this issue should be fixed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants