spock: IllegalStateException: Invisible parameter type of kotlin.jvm.internal.DefaultConstructorMarker
I have a Kotlin class:
open class SomeClass(val cheese: String = "brie") {
fun foo() = "bar"
}
… and a Spock test:
class OpenTest extends Specification {
def "should be able to mock"() {
given:
def someMock = Mock(SomeClass)
someMock.foo() >> "cheese"
expect: "that we actually can mock it"
someMock.cheese == "brie"
someMock.foo() == "cheese
}
}
… using the following Gradle dependencies:
testCompile(
"org.spockframework:spock-core:1.1-groovy-2.4",
"net.bytebuddy:byte-buddy:1.7.5",
)
Running the test gives me:
java.lang.IllegalArgumentException: Could not create type
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:140)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355)
at org.spockframework.mock.runtime.ProxyBasedMockFactory$ByteBuddyMockFactory.createMock(ProxyBasedMockFactory.java:108)
at org.spockframework.mock.runtime.ProxyBasedMockFactory.create(ProxyBasedMockFactory.java:65)
at org.spockframework.mock.runtime.JavaMockFactory.createInternal(JavaMockFactory.java:59)
at org.spockframework.mock.runtime.JavaMockFactory.create(JavaMockFactory.java:40)
at org.spockframework.mock.runtime.CompositeMockFactory.create(CompositeMockFactory.java:44)
at org.spockframework.lang.SpecInternals.createMock(SpecInternals.java:51)
at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:296)
at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:286)
at org.spockframework.lang.SpecInternals.MockImpl(SpecInternals.java:105)
at no.finn.travel.shared.common.kotlin.OpenTest.should be able to mock #subject(OpenTest.groovy:11)
Caused by: java.lang.IllegalStateException: Invisible parameter type of kotlin.jvm.internal.DefaultConstructorMarker arg2 for public no.finn.travel.shared.common.kotlin.SomeClass$SpockMock$bAkOnnH5(java.lang.String,int,kotlin.jvm.internal.DefaultConstructorMarker)
at net.bytebuddy.dynamic.scaffold.InstrumentedType$Default.validated(InstrumentedType.java:925)
at net.bytebuddy.dynamic.scaffold.MethodRegistry$Default.prepare(MethodRegistry.java:465)
at net.bytebuddy.dynamic.scaffold.subclass.SubclassDynamicTypeBuilder.make(SubclassDynamicTypeBuilder.java:162)
at net.bytebuddy.dynamic.scaffold.subclass.SubclassDynamicTypeBuilder.make(SubclassDynamicTypeBuilder.java:155)
at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase.make(DynamicType.java:2639)
at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase$Delegator.make(DynamicType.java:2741)
at org.spockframework.mock.runtime.ProxyBasedMockFactory$ByteBuddyMockFactory$1.call(ProxyBasedMockFactory.java:113)
at org.spockframework.mock.runtime.ProxyBasedMockFactory$ByteBuddyMockFactory$1.call(ProxyBasedMockFactory.java:110)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138)
... 13 more
The test works without the byte-buddy dependency.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (15 by maintainers)
Commits related to this issue
- Add project to demonstrate kotlin/spock/bytebuddy inoperability issue Ref: - https://github.com/raphw/byte-buddy/issues/350#issuecomment-334121150 - https://github.com/spockframework/spock/issues/776 — committed to henrik242/kotlin-bytebuddy-spock by henrik242 7 years ago
- Add project to demonstrate kotlin/spock/bytebuddy inoperability issue Ref: - https://github.com/raphw/byte-buddy/issues/350#issuecomment-334121150 - https://github.com/spockframework/spock/issues/776 — committed to henrik242/kotlin-bytebuddy-spock by henrik242 7 years ago
- Update ByteBuddy do 1.7.6 and disable TypeValidation to fix #776 — committed to leonard84/spock by leonard84 7 years ago
Sorry, little baby at home, I hope to look into this within this week. But yes, I suggest to turn off validation in the first place. Also, latest Byte Buddy fully supports Java 9, might be worth the update!
Spock should configure Byte Buddy to run by
new ByteBuddy().with(TypeValidation.DISABLED).I will however look into the issue and hopefully fix it!