jbwheatley / pact4s

Apache License 2.0
29 stars 11 forks source link

(Consumer) IllegalAccessException when using some unexpected types as state parameters #607

Closed gaeljw closed 5 months ago

gaeljw commented 7 months ago

When changing the state parameters of one contract from a Int to a Seq[Int], I've got the following exception on the consumer:

[info]   kotlin.reflect.full.IllegalCallableAccessException: java.lang.IllegalAccessException: class kotlin.reflect.jvm.internal.calls.CallerImpl$FieldGetter cannot access a member of class scala.collection.immutable.$colon$colon with modifiers "private final"
[info]   at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:247)
[info]   at au.com.dius.pact.core.support.Utils.objectToJsonMap(Utils.kt:116)
[info]   at au.com.dius.pact.core.support.Utils.jsonSafeValue(Utils.kt:136)
[info]   at au.com.dius.pact.core.model.ProviderState.toMap(ProviderState.kt:20)
[info]   at au.com.dius.pact.core.model.RequestResponseInteraction.toMap(RequestResponseInteraction.kt:37)
[info]   at au.com.dius.pact.core.model.RequestResponsePact.toMap(RequestResponsePact.kt:31)
[info]   at au.com.dius.pact.core.model.DefaultPactWriter.writePact(PactWriter.kt:63)
[info]   at au.com.dius.pact.core.model.DefaultPactWriter.writePact(PactWriter.kt:111)
[info]   at au.com.dius.pact.consumer.BaseMockServer.verifyResultAndWritePact(MockHttpServer.kt:177)
[info]   at pact4s.RequestResponsePactForgerResources.verifyResultAndWritePactFiles(RequestResponsePactForgerResources.scala:39)
[info]   ...
[info]   Cause: java.lang.IllegalAccessException: class kotlin.reflect.jvm.internal.calls.CallerImpl$FieldGetter cannot access a member of class scala.collection.immutable.$colon$colon with modifiers "private final"
[info]   at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:392)
[info]   at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:674)
[info]   at java.base/java.lang.reflect.Field.checkAccess(Field.java:1102)
[info]   at java.base/java.lang.reflect.Field.get(Field.java:423)
[info]   at kotlin.reflect.jvm.internal.calls.CallerImpl$FieldGetter.call(CallerImpl.kt:161)
[info]   at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:107)
[info]   at au.com.dius.pact.core.support.Utils.objectToJsonMap(Utils.kt:116)
[info]   at au.com.dius.pact.core.support.Utils.jsonSafeValue(Utils.kt:136)
[info]   at au.com.dius.pact.core.model.ProviderState.toMap(ProviderState.kt:20)
[info]   at au.com.dius.pact.core.model.RequestResponseInteraction.toMap(RequestResponseInteraction.kt:37)
[info]   ...

Relevant code:

ConsumerPactBuilder
    ....
   .`given`("Some entities", Map("ids" -> Seq(123, 456)))

Sounds related to using Scala types that Pact JVM itself is not able to convert to a known Java type. Not necessarily a big issue, I just log it in case anyone face it as well.

gaeljw commented 6 months ago

Transforming the objects to Java (with standard Scala converters) works fine.

jbwheatley commented 6 months ago

yeah the state stuff was always a little janky/unsafe - I'll see what we can do to make it more usuable ootb

jbwheatley commented 6 months ago

think I fixed this on main, not release yet

jbwheatley commented 5 months ago

fixed in 0.12.1, please reopen if not the case