Skip to content

Fix that would allow use JDK 21+ to build the project - #3065

Draft
robsunday wants to merge 1 commit into
signalfx:mainfrom
robsunday:fix-for-java21-plus
Draft

robsunday wants to merge 1 commit into
signalfx:mainfrom
robsunday:fix-for-java21-plus

Conversation

@robsunday

Copy link
Copy Markdown
Contributor

Build failed on JDK 21 because JfrContextStorageTest.testAttachLifecycle test failed.
It was caused by the following sequence of actions performed on test start:

  1. Mockito’s inline mock maker retransforms ContextAttached.
  2. Java 21’s JFR machinery detects that it is an Event subclass and retransforms it again.
  3. JFR replaces begin(), commit(), and shouldCommit() with its own implementations. OpenJDK explicitly generates these methods during JFR instrumentation.
  4. Mockito’s interception of shouldCommit() is consequently lost.
  5. The real method returns false, so this expression effectively becomes: when(false).thenReturn(true) . Since Mockito recorded no invocation, it throws MissingMethodInvocationException.

With this PR Mockito can mock JFR events.

@Category("opentelemetry")
@StackTrace(false)
public class ContextAttached extends Event {
public class ContextAttached extends Event implements JfrEvent {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inherited final JFR methods satisfy the interface in production, while Mockito can mock the interface without competing with JFR bytecode instrumentation.

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

Successfully merging this pull request may close these issues.

1 participant