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

Mockito inline with -XX:+AllowEnhancedClassRedefinition still crashes with JBR 17.0.14 #514

Open
loetifuss opened this issue Feb 11, 2025 · 2 comments

Comments

@loetifuss
Copy link

After switching to Mockito's inline MockMaker my integration tests are crashing when using JBR 17.0.14 build1367.22 with -XX:+AllowEnhancedClassRedefinition.
Running tests with an Oracle JDK is successful.
The underlying issue is that Mockito's inline Mock maker redefines "java.lang.Object". When I debug into the Mockito code and manually edit the set of redefined classes (by removing java.lang.Object) it works.

In #259 it is stated that redefining java.lang.Object should be possible now.

Note: Since these tests are integration tests running in an OSGI environment the classloading is pretty complex.

With JBR 17.0.12 test execution will just hang forever in "retransformClasses()". With 17.0.14 I'm getting the following access violation

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffc2d9442df, pid=16216, tid=27292
#
# JRE version: OpenJDK Runtime Environment JBR-17.0.14+1-1367.22-jcef (17.0.14+1) (build 17.0.14+1-b1367.22)
# Java VM: OpenJDK 64-Bit Server VM JBR-17.0.14+1-1367.22-jcef (17.0.14+1-b1367.22, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
# Problematic frame:
# V  [jvm.dll+0x4d42df]
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
#   https://youtrack.jetbrains.com/issues/JBR
---------------  S U M M A R Y ------------

Host: 12th Gen Intel(R) Core(TM) i7-1260P, 16 cores, 31G,  Windows 11 , 64 bit Build 22621 (10.0.22621.4391)
Time: Tue Feb 11 13:57:09 2025 Mitteleuropäische Zeit elapsed time: 393.396099 seconds (0d 0h 6m 33s)

---------------  T H R E A D  ---------------

Current thread (0x000001247fb34e00):  VMThread "VM Thread" [stack: 0x0000002401100000,0x0000002401200000] [id=27292]

Stack: [0x0000002401100000,0x0000002401200000],  sp=0x00000024011ff050,  free space=1020k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [jvm.dll+0x4d42df]
V  [jvm.dll+0x4d819a]
V  [jvm.dll+0x4d5eb7]
V  [jvm.dll+0x84c11d]
V  [jvm.dll+0x84ce62]
V  [jvm.dll+0x84d38f]
V  [jvm.dll+0x84d774]
V  [jvm.dll+0x84d840]
V  [jvm.dll+0x7f3a1c]
V  [jvm.dll+0x68a7c7]
C  [ucrtbase.dll+0x29333]
C  [KERNEL32.DLL+0x1259d]
C  [ntdll.dll+0x5af38]


siginfo: EXCEPTION_ACCESS_VIOLATION (0xc0000005), reading address 0xffffffffffffffff


Registers:
RAX=0x90004f0018535edf, RBX=0x00000008012a02b0, RCX=0x000000240dbfc570, RDX=0x0000000000000000
RSP=0x00000024011ff050, RBP=0x00000024011ff239, RSI=0x000000240dbfc570, RDI=0x0000000000000014
R8 =0x00000124130251f8, R9 =0x000001240a8b2df0, R10=0x0000000000000007, R11=0x00000024011fefb0
R12=0x0000000000000000, R13=0x000001247fb34e00, R14=0x000001243031ee30, R15=0x000000240dbfc570
RIP=0x00007ffc2d9442df, EFLAGS=0x0000000000010246


Register to memory mapping:

RIP=0x00007ffc2d9442df jvm.dll
RAX=0x90004f0018535edf is an unknown value
RBX=0x00000008012a02b0 is pointing into metadata
RCX=0x000000240dbfc570 is pointing into the stack for thread: 0x0000012409b67a40
RDX=0x0 is NULL
RSP=0x00000024011ff050 points into unknown readable memory: 0x404e000000000000 | 00 00 00 00 00 00 4e 40
RBP=0x00000024011ff239 points into unknown readable memory: e2 a2 5b 24 01 00 00
RSI=0x000000240dbfc570 is pointing into the stack for thread: 0x0000012409b67a40
RDI=0x0000000000000014 is an unknown value
R8 =0x00000124130251f8 points into unknown readable memory: 0x0000000000000000 | 00 00 00 00 00 00 00 00
R9 =0x000001240a8b2df0 points into unknown readable memory: 0x00007ffc2de0ed00 | 00 ed e0 2d fc 7f 00 00
R10=0x0000000000000007 is an unknown value
R11=0x00000024011fefb0 points into unknown readable memory: 0x000001245bbe5810 | 10 58 be 5b 24 01 00 00
R12=0x0 is NULL
R13=0x000001247fb34e00 points into unknown readable memory: 0x00007ffc2de70cd8 | d8 0c e7 2d fc 7f 00 00
R14=0x000001243031ee30 points into unknown readable memory: 0x00000006898b29d8 | d8 29 8b 89 06 00 00 00
R15=0x000000240dbfc570 is pointing into the stack for thread: 0x0000012409b67a40

I haven't yet found a way to create a simple reproducer since this is only happening in our more complex integration tests.

@skybber
Copy link
Collaborator

skybber commented Feb 11, 2025

Thanks for report! Could you please provide a mapped stack trace to better understand the issue? Right now, your stack trace only shows memory addresses without corresponding method names and source file locations. A Linux JBR image should provide a stack trace with debug symbols.

Otherwise, without a reproducer, tracking down this issue will be hard—our tests with Mockito are working. It would also be great if you could try JBR21, as it includes a fix for a ClassUnloading-related issue, which might resolve the problem. Let us know if that helps!

@loetifuss
Copy link
Author

I have uploaded the full error message, just stripped some package names/file paths

dcevm.txt

I also tried JBR21, this gives a different error saying a class cannot be mocked. The class in question isn't final or anything and a spy can be successfully created when not using mockito inline

Mockito cannot mock this class: class MyServicesImpl.

If you're not sure why you're getting this error, please report to the mailing list.


Java               : 21
JVM vendor name    : JetBrains s.r.o.
JVM vendor version : 21.0.6+8-b872.85
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 21.0.6+8-b872.85
JVM info           : mixed mode, sharing
OS name            : Windows 11
OS version         : 10.0


You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.

Underlying exception : java.lang.IllegalArgumentException: Could not create type
org.mockito.exceptions.base.MockitoException: 
Mockito cannot mock this class: class MyServicesImpl.

If you're not sure why you're getting this error, please report to the mailing list.


Java               : 21
JVM vendor name    : JetBrains s.r.o.
JVM vendor version : 21.0.6+8-b872.85
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 21.0.6+8-b872.85
JVM info           : mixed mode, sharing
OS name            : Windows 11
OS version         : 10.0


You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.

Underlying exception : java.lang.IllegalArgumentException: Could not create type
	at MyServicesProvider.enableMocks(MyServicesProvider.java:local:43)
	at MyServicesMockRule.setUpRule(MyServicesMockRule.java:local:41)
	at JUnitBaseRule$1.evaluate(JUnitBaseRule.java:local:85)
	at JUnitTransactionalRule$1.evaluate(JUnitTransactionalRule.java:local:277)
Caused by: java.lang.IllegalArgumentException: Could not create type
	at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:170)
	at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:399)
	at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:190)
	at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:410)
	at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:40)
	at org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.createMockType(InlineDelegateByteBuddyMockMaker.java:391)
	at org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.doCreateMock(InlineDelegateByteBuddyMockMaker.java:351)
	at org.mockito.internal.creation.bytebuddy.InlineDelegateByteBuddyMockMaker.createSpy(InlineDelegateByteBuddyMockMaker.java:341)
	at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.createSpy(InlineByteBuddyMockMaker.java:64)
	at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:45)
	at org.mockito.internal.MockitoCore.mock(MockitoCore.java:84)
	at org.mockito.Mockito.spy(Mockito.java:2038)
	... 4 more
Caused by: java.lang.VerifyError
	at java.instrument/sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
	at java.instrument/sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:225)
	at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.triggerRetransformation(InlineBytecodeGenerator.java:276)
	at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.mockClass(InlineBytecodeGenerator.java:213)
	at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.lambda$mockClass$0(TypeCachingBytecodeGenerator.java:47)
	at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:168)
	... 15 more

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

2 participants