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

javax.tools.ToolProvider could not be found in InlineByteBuddyMockMaker #1855

Closed
nuxzero opened this issue Jan 7, 2020 · 8 comments
Closed

Comments

@nuxzero
Copy link

nuxzero commented Jan 7, 2020

Hi guys

I'm encountering a crash when I run AndroidTest that contain mocking class cause the ByteBuddy didn't found javax.tools.ToolProvider. I tried to reinstall JDK 8 but doesn't work. It seems to be javax.tools.ToolProvider not existing in it.

Could you guys help me please?

Cheer,

Natthawut

Environment


Gradle 5.4.1

Build time: 2019-04-26 08:14:42 UTC
Revision: 261d171646b36a6a28d5a19a69676cd098a4c19d

Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_231 (Oracle Corporation 25.231-b11)
OS: Mac OS X 10.15.2 x86_64

Dependencies

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:3.2.4'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'org.mockito:mockito-android:3.2.4'
    androidTestImplementation "io.mockk:mockk-android:1.9.3.kotlin12"

Strack trace

E/TestRunner: failed: mockFoo(co.sample.mockitoandroid.MockWithMockitoTest)
    ----- begin exception -----
E/TestRunner: java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null)
        at org.mockito.internal.configuration.plugins.PluginLoader$1.invoke(PluginLoader.java:74)
        at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
        at $Proxy3.isTypeMockable(Unknown Source)
        at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:29)
        at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
        at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:241)
        at org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java:229)
        at org.mockito.internal.MockitoCore.mock(MockitoCore.java:62)
        at org.mockito.Mockito.mock(Mockito.java:1908)
        at org.mockito.Mockito.mock(Mockito.java:1817)
        at co.sample.mockitoandroid.MockWithMockitoTest.<init>(MockWithMockitoTest.kt:17)
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
        at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:104)
        at org.junit.runners.Suite.runChild(Suite.java:128)
        at org.junit.runners.Suite.runChild(Suite.java:27)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
        at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
        at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392)
        at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145)
     Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/tools/ToolProvider;
        at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.<init>(InlineByteBuddyMockMaker.java:172)
        at java.lang.Class.newInstance(Native Method)
        at org.mockito.internal.configuration.plugins.PluginInitializer.loadImpl(PluginInitializer.java:49)
        at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:57)
        at org.mockito.internal.configuration.plugins.PluginLoader.loadPlugin(PluginLoader.java:44)
        at org.mockito.internal.configuration.plugins.PluginRegistry.<init>(PluginRegistry.java:22)
        at org.mockito.internal.configuration.plugins.Plugins.<clinit>(Plugins.java:19)
        at org.mockito.internal.configuration.plugins.Plugins.getMockMaker(Plugins.java:35)
        at org.mockito.internal.util.MockUtil.<clinit>(MockUtil.java:24)
        at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:29) 
        at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22) 
        at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:241) 
        at org.mockito.internal.creation.MockSettingsImpl.build(MockSettingsImpl.java:229) 
        at org.mockito.internal.MockitoCore.mock(MockitoCore.java:62) 
        at org.mockito.Mockito.mock(Mockito.java:1908) 
        at org.mockito.Mockito.mock(Mockito.java:1817) 
        at co.sample.mockitoandroid.MockWithMockitoTest.<init>(MockWithMockitoTest.kt:17) 
        at java.lang.reflect.Constructor.newInstance0(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
        at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217) 
        at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266) 
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
        at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263) 
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
        at androidx.test.ext.junit.runners.AndroidJUnit4.run(AndroidJUnit4.java:104) 
        at org.junit.runners.Suite.runChild(Suite.java:128) 
        at org.junit.runners.Suite.runChild(Suite.java:27) 
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137) 
        at org.junit.runner.JUnitCore.run(JUnitCore.java:115) 
        at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56) 
        at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392) 
        at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145) 
     Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.tools.ToolProvider" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/data/app/co.sample.mockitoandroid.test-ZJFawUg-
    ----- end exception -----

Screen Shot 2563-01-07 at 12 45 26

MockitoAndroid.zip

@cazgp
Copy link

cazgp commented Mar 9, 2020

I think this commit is part of the problem: https://github.com/mockito/mockito/pull/1567/files

@tonisives
Copy link

tonisives commented Mar 18, 2020

I think this commit is part of the problem: https://github.com/mockito/mockito/pull/1567/files

I tried with mockito 2.22.0, which should be a release before the commit, but the error is still there. https://github.com/mockito/mockito/releases?after=v2.23.0

edit: what fixed the issue for me was removing the mock-maker-inline resource file

@TimvdLippe
Copy link
Contributor

The inline mockmaker is not supported on Android (as listed in the exception). However, we should probably not crash before we can show that message to the user. I would welcome a PR to fix this problem.

@glend1
Copy link

glend1 commented Jul 15, 2020

@TimvdLippe What should people do for android then? Kotlin uses final classes only.

@TimvdLippe
Copy link
Contributor

@raphw What is our advice for Android? I don't remember what our final resolution was for inline + android for Kotlin.

@tonisives
Copy link

I just started using https://mockk.io/. Its Kotlin friendly also

@raphw
Copy link
Member

raphw commented Jul 16, 2020

On Android, the inline mock maker won't work (neither will Mockk which uses the same approach as we do). It does not support the instrumentation API alltogether.

I do agree that the error message is misleading. Currently preparing a PR to improve this.

raphw added a commit that referenced this issue Jul 16, 2020
raphw added a commit that referenced this issue Jul 17, 2020
@raphw raphw closed this as completed in 12ba593 Jul 18, 2020
raphw added a commit that referenced this issue Jul 18, 2020
…ove-error-message

Fixes #1855 and #939: improve error message when the inline mock maker cannot be used.
@mitsest
Copy link

mitsest commented Jan 7, 2021

You can achieve this by using com.linkedin.dexmaker:dexmaker-mockito-inline for APIs >= 28

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

No branches or pull requests

7 participants