8000 Bug: cannot Mock Class With Package-Private Parent · Issue #119 · mockk/mockk · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Bug: cannot Mock Class With Package-Private Parent #119

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

Open
3 tasks done
pusolito opened this issue Jul 27, 2018 · 18 comments
Open
3 tasks done

Bug: cannot Mock Class With Package-Private Parent #119

pusolito opened this issue Jul 27, 2018 · 18 comments
Labels

Comments

@pusolito
Copy link
pusolito commented Jul 27, 2018

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Expected Behavior

I expect the mock to be created successfully

Current Behavior

An exception is thrown when mocking class.

Failure Information (for bugs)

Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Run the sample code

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • MockK version: 1.8.5
  • OS: Mac OS Sierra
  • Kotlin version: 1.2.41
  • JDK version: 1.8.0_45
  • Type of test: unit test

Failure Logs

Please include any relevant log snippets or files here.

Stack trace

[main] WARN io.mockk.proxy.jvm.transformation.InlineInstrumentation - Failed to transform classes [class Foo, class Bar, class java.lang.Object]
java.lang.UnsupportedOperationException: class redefinition failed: attempted to add a method
	at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
	at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144)
	at io.mockk.proxy.jvm.transformation.InlineInstrumentation.execute(InlineInstrumentation.kt:26)
	at io.mockk.proxy.jvm.ProxyMaker.inline(ProxyMaker.kt:88)
	at io.mockk.proxy.jvm.ProxyMaker.proxy(ProxyMaker.kt:30)
	at io.mockk.impl.instantiation.JvmMockFactory.newProxy(JvmMockFactory.kt:34)
	at io.mockk.impl.instantiation.AbstractMockFactory.newProxy$default(AbstractMockFactory.kt:27)
	at io.mockk.impl.instantiation.AbstractMockFactory.mockk(AbstractMockFactory.kt:44)
	at FooKt.main(Foo.kt:23)
Exception in thread "main" java.lang.UnsupportedOperationException: class redefinition failed: attempted to add a method
	at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
	at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144)
	at io.mockk.proxy.jvm.transformation.InlineInstrumentation.doCancel(InlineInstrumentation.kt:47)
	at io.mockk.proxy.jvm.transformation.InlineInstrumentation.access$doCancel(InlineInstrumentation.kt:9)
	at io.mockk.proxy.jvm.transformation.InlineInstrumentation$execute$cancellation$1.invoke(InlineInstrumentation.kt:20)
	at io.mockk.proxy.jvm.transformation.InlineInstrumentation$execute$cancellation$1.invoke(InlineInstrumentation.kt:9)
	at io.mockk.proxy.jvm.transformation.InlineInstrumentation.execute(InlineInstrumentation.kt:30)
	at io.mockk.proxy.jvm.ProxyMaker.inline(ProxyMaker.kt:88)
	at io.mockk.proxy.jvm.ProxyMaker.proxy(ProxyMaker.kt:30)
	at io.mockk.impl.instantiation.JvmMockFactory.newProxy(JvmMockFactory.kt:34)
	at io.mockk.impl.instantiation.AbstractMockFactory.newProxy$default(AbstractMockFactory.kt:27)
	at io.mockk.impl.instantiation.AbstractMockFactory.mockk(AbstractMockFactory.kt:44)
	at FooKt.main(Foo.kt:23)

Minimal reproducible code (the gist of this issue)

// Foo.kt
import io.mockk.mockk

internal class Foo: Bar()

fun main(args: Array<String>) {
    mockk<Foo>(relaxed = true)
}
// Bar.java
class Bar {
    public void foo() { }
}
// -----------------------[ GRADLE DEFINITIONS ] -----------------------
dependencies {
    testImplementation "io.mockk:mockk:1.8.5"
}
@oleksiyp oleksiyp added bug no reproduction Not able to reproduce labels Jul 29, 2018
@oleksiyp
Copy link
Collaborator
oleksiyp commented Jul 29, 2018

Hm. I checked it in a test and it is creating mockk

/usr/java/jdk1.8.0_161/bin/java ...
2018-07-29 08:10:06 [main] DEBUG i.m.i.i.AbstractMockFactory - Creating mockk for Foo name=#1, moreInterfaces=[]

Process finished with exit code 0

@oleksiyp
Copy link
Collaborator
oleksiyp commented Jul 29, 2018

I see you are using JDK version 1.8.0_45, which is pretty old. Just a guess, but maybe you can try use 1.8.0_161 which I use right now

@pusolito
Copy link
Author

This issue still reproduces for me with JDK 1.8.0_181 and mockk 1.8.6. Are the tests you ran to confirm available?

@oleksiyp
Copy link
Collaborator

Probably it was not reproduced well. I didnt commit this test

@pusolito
Copy link
Author

Anything more I can do to help? This issue is currently blocking my adoption of what is an otherwise fantastic mocking framework.

@oleksiyp
Copy link
Collaborator
oleksiyp commented Sep 2, 2018

I returned back to reproduction and still not able to do it.
I wonder what method retransformation is trying to add.

In next release there will be a possibility to dump class files before transformation by specifying a directory in a system property to put classes in.
So you can specify in VM options -Dio.mockk.classdump.path=dump and get retransformed files from dump directory.

Please do it and send to me. Thanks

@oleksiyp
Copy link
Collaborator
oleksiyp commented Sep 2, 2018

Version 1.8.7 released. Please capture class dump as described above and send it to me. Thanks

@pusolito
Copy link
Author
pusolito commented Sep 4, 2018

Thanks for adding the the class dump. Hopefully it will help get to the bottom of this issue. I'm still able to reproduce with 1.8.7 using the following code:

import com.datastax.driver.core.UDTValue
import io.mockk.mockk

fun main(args: Array<String>) {
    mockk<UDTValue>(relaxed = true)
}

I've attached the contents of the class dump: dump.zip.

@oleksiyp
Copy link
Collaborator
oleksiyp commented Sep 5, 2018

Can you please provide a version of Apache DataStax Driver? I need to fetch original UDTValue from it.

@pusolito
Copy link
Author
pusolito commented Sep 5, 2018 via email

@pusolito
Copy link
Author

We’re you able to reproduce this with the latest sample I provided?

@oleksiyp
Copy link
Collaborator

Not yet

@pusolito
Copy link
Author
pusolito commented Nov 5, 2018

Any update on this issue?

@oleksiyp
Copy link
Collaborator
oleksiyp commented Nov 5, 2018

I have spent almost all my weekend to fix few issues, but didnt touch this one. Sorry

@oleksiyp
Copy link
Collaborator
oleksiyp commented Nov 10, 2018

ok, so I reproduced, minimized it and submitted this issue to ByteBuddy

@oleksiyp oleksiyp changed the title Cannot Mock Class With Package-Private Parent Bug: cannot Mock Class With Package-Private Parent Dec 25, 2018
@oleksiyp
Copy link
Collaborator
oleksiyp commented Jan 6, 2019

Adding link raphw/byte-buddy#561

@stale
Copy link
stale bot commented Jul 23, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you are sure that this issue is important and should not be marked as stale just put an important tag.

@stale stale bot added the stale label Jul 23, 2019
@stale stale bot closed this as completed Jul 30, 2019
@oleksiyp
Copy link
Collaborator
oleksiyp commented Nov 2, 2019

As mentioned in raphw/byte-buddy#561

You can now set VisibilityBridgeStrategy.Default.NEVER on the ByteBuddy instance.

Reopening to try to fix it

@oleksiyp oleksiyp reopened this Nov 2, 2019
@stale stale bot removed the stale label Nov 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants
0