Skip to content

CI fails on Linux JDK 17: Mockito state corrupted by mock(Method.class) in WinRMInvocationHandlerTest #84

Description

@NassimBtk

Summary

Maven tests pass locally on Windows with JDK 17 but fail in GitHub Actions on Linux with JDK 17. Two tests fail with Mockito-related errors:

  • WinRMCommandExecutorTest.testExecuteNullPointerException: Cannot invoke "[Ljava.lang.Class;.clone()" because "parameterTypes" is null
  • WinRMWqlExecutorTest.testExecuteInvalidUseOfMatchersException (cascading failure)

This is not a Java version mismatch. CI and local both use JDK 17.

Root cause

WinRMInvocationHandlerTest uses a static mock of java.lang.reflect.Method:

private static final Method METHOD = mock(Method.class);

Mocking core JDK reflection types breaks Mockito's own reflection internals (mockito#2026). After this mock is created, later stubbing of methods such as executeCommand(...) can fail with a NullPointerException on Method.getParameterTypes().

The InvalidUseOfMatchersException in WinRMWqlExecutorTest is a secondary effect of polluted Mockito matcher state, not a separate bug in that test.

Why it passes locally but fails in CI

Surefire test execution order is filesystem-dependent:

Environment Typical order Result
Windows local WinRMCommandExecutorTest runs before WinRMInvocationHandlerTest Pass
Linux CI WinRMInvocationHandlerTest runs first, corrupts Mockito, then others fail Fail

Proposed fix

  1. WinRMInvocationHandlerTest — Remove mock(Method.class). Use a real WinRMWebService.receive Method and stub WIN_RM_WS.receive(...) instead of Method.invoke(...).

  2. WinRMCommandExecutorTest — In the SMB/file-copy path, mock WinRMService (concrete class) instead of the WindowsRemoteExecutor interface, and use eq(UTF_8) instead of any(Charset.class) for consistency with the other test branch.

Acceptance criteria

  • mvn test passes on Linux CI with JDK 17
  • Tests pass regardless of Surefire execution order (e.g. -Dtest=WinRMInvocationHandlerTest,WinRMCommandExecutorTest,WinRMWqlExecutorTest)
  • No mocking of java.lang.reflect.Method or other core JDK reflection types in tests

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions