Skip to content

StackWalker.Option not found on Mockito 5.1.0 #2890

Closed
@sergiandreplace

Description

@sergiandreplace

We have an Android project using Mockito and we tried to upgrade from 5.0.0 to 5.1.0.

When running the Android tests we always receive an error like this:

java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/StackWalker$Option;
	at org.mockito.internal.debugging.LocationImpl.stackWalker(LocationImpl.java:138)
	at org.mockito.internal.debugging.LocationImpl.<clinit>(LocationImpl.java:40)
	at org.mockito.internal.debugging.LocationFactory.create(LocationFactory.java:17)
	at org.mockito.internal.debugging.LocationFactory.create(LocationFactory.java:13)
	at org.mockito.internal.matchers.LocalizedMatcher.<init>(LocalizedMatcher.java:19)
	at org.mockito.internal.progress.ArgumentMatcherStorageImpl.reportMatcher(ArgumentMatcherStorageImpl.java:30)
	at org.mockito.ArgumentMatchers.reportMatcher(ArgumentMatchers.java:1036)
	at org.mockito.ArgumentMatchers.any(ArgumentMatchers.java:177)
	...

After some investigation we found that:

  • StackWalker is only available from Java 9. All our modules are setup to use Java 11.
  • We can't see StackWalker class from the IDE
  • This only happens on Android instrumental tests, not in "normal" java tests
  • The class StackWalker is not available in Android SDK java implementation: https://github.com/AndroidSDKSources/android-sdk-sources-for-api-level-33/tree/master/java/lang (that would explain why is not working only for instrumental tests, as they are executed on an Android device). Checked for latest android versions.

It looks like a very specific Android issue.

For the meantime, we will halt the upgrade, but any help will be great.

Thanks in advance

  • The mockito message in the stacktrace have useful information, but it didn't help
  • [N/A] The problematic code (if that's possible) is copied here;
    Note that some configuration are impossible to mock via Mockito
  • Provide versions (mockito / jdk / os / any other relevant information)
  • Provide a Short, Self Contained, Correct (Compilable), Example of the issue
    (same as any question on stackoverflow.com)
  • Read the contributing guide

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