question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IllegalStateException: Invisible parameter type of kotlin.jvm.internal.DefaultConstructorMarker

See original GitHub issue

I have a Kotlin class:

open class SomeClass(val cheese: String = "brie") {
    fun foo() = "bar"
}

… and a Spock test:

class SomeClassTest 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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
raphwcommented, Oct 21, 2017

This seems like a bug in Kotlin. Its compiler creates a synthetic constructor: public synthetic <init>(Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;

The DefaultConstructorMarker type is package-private and therefore not visible to SomeClass$SpockMock. According to the spec, this is not legal as you must not refer to classes that are not visible to a class but the JVM is sometimes more forgiving like in this case.

The javac compiler does a similar thing but creates an anonymous type in the same package of the class it creates. The Kotlin compiler should do the same thing or make the default marker type public (whilst it could still retain the class’s constructor public.)

2reactions
raphwcommented, Oct 13, 2017

Its on my agenda and I hope to find some time next week!

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Could not find class 'kotlin.jvm.internal ... - Stack Overflow
XXX E/dalvikvm: Could not find class 'kotlin.jvm.internal.DefaultConstructorMarker', referenced from method ch.XXX.XXX.commons.features.
Read more >
Composable function in `init` block causes "Exception during ...
Int) declared in kotlin.jvm.internal.Lambda' arity: CONST Int type=kotlin.Int value=2 BLOCK type=kotlin.Unit origin=null FUN name:invoke ...
Read more >
Kotlin Error: Unknown parameter type kotlin.jvm.internal ...
"Unknown parameter type kotlin.jvm.internal.DefaultConstructorMarker in method SubscribeMessagingEvents in managed type Com.Liveperson.Api.
Read more >
Automated Malware Analysis Report for kotlin-stdlib.jar
Hide Legend. Legend: Process ... File Type: compiled Java class data, version 53.0 ... Lkotlin/jvm/internal/DefaultConstructorMarker;.
Read more >
FasterXML - Bountysource
Created 1 year ago in FasterXML/jackson-module-kotlin with 0 comments. ... type java.io.NotSerializableException with message kotlin.reflect.jvm.internal.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found