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

"IllegalArgumentException: source and target are not compatible" if Spy is assigned to variable with interface type #822

reftel opened this Issue Feb 15, 2018 · 2 comments


None yet
2 participants

reftel commented Feb 15, 2018

Issue description

When a Spy with a provided instance is created and assigned to a variable that is explicitly declared as having an interface as type, creating the spy fails with an IllegalArgumentException in ReflectionUtil.deepCopyFields . If the variable is explicitly declared as having a class as type, or is defined using "def", then creating the spy works as intended.

The stack trace produced is:

java.lang.IllegalArgumentException: source and target are not compatible.

	at org.spockframework.util.ReflectionUtil.deepCopyFields(
	at org.spockframework.mock.runtime.JavaMockFactory.createInternal(
	at org.spockframework.mock.runtime.JavaMockFactory.create(
	at org.spockframework.mock.runtime.CompositeMockFactory.create(
	at org.spockframework.lang.SpecInternals.createMock(
	at org.spockframework.lang.SpecInternals.createMockImpl(
	at org.spockframework.lang.SpecInternals.SpyImpl(
	at com.reftel.magnus.spockspytestcase.CallerTest.should not call expensive method - interface(CallerTest.groovy:37)

How to reproduce

See testcase at

Additional Environment information

Spock version

Spock 1.2-groovy-2.4-20180205.215134-43


java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

Groovy version



This comment has been minimized.


leonard84 commented Feb 15, 2018

Yes there is an issue with the inferredType for Spy.

@leonard84 leonard84 added the bug label Feb 15, 2018

leonard84 added a commit to leonard84/spock that referenced this issue Aug 9, 2018

@leonard84 leonard84 closed this in d3a493d Aug 9, 2018


This comment has been minimized.

reftel commented Aug 9, 2018

Yup, that solved it. Thanks!

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