Cglib & Spock problems with Gradle 2.5

cglib throws an IllegalArgumentException in some Spock tests when using spock.lang.MockingApi#Mock(java.lang.Class<T>):

13-Jul-2015 17:07:56	no.xxx.yyy.MyTest > Builds the info mapping lazily and once on the first lookup call FAILED
13-Jul-2015 17:07:56	    java.lang.IllegalArgumentException
13-Jul-2015 17:07:56	        at net.sf.cglib.proxy.BridgeMethodResolver.resolveAll(BridgeMethodResolver.java:61)
13-Jul-2015 17:07:56	        at net.sf.cglib.proxy.Enhancer.emitMethods(Enhancer.java:911)
13-Jul-2015 17:07:56	        at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:498)
13-Jul-2015 17:07:56	        at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
13-Jul-2015 17:07:56	        at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
13-Jul-2015 17:07:56	        at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
13-Jul-2015 17:07:56	        at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
13-Jul-2015 17:07:56	        at org.spockframework.mock.runtime.ProxyBasedMockFactory$CglibMockFactory.createMock(ProxyBasedMockFactory.java:91)
13-Jul-2015 17:07:56	        at org.spockframework.mock.runtime.ProxyBasedMockFactory.create(ProxyBasedMockFactory.java:49)
13-Jul-2015 17:07:56	        at org.spockframework.mock.runtime.JavaMockFactory.create(JavaMockFactory.java:51)
13-Jul-2015 17:07:56	        at org.spockframework.mock.runtime.CompositeMockFactory.create(CompositeMockFactory.java:44)
13-Jul-2015 17:07:56	        at org.spockframework.lang.SpecInternals.createMock(SpecInternals.java:45)
13-Jul-2015 17:07:56	        at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:281)
13-Jul-2015 17:07:56	        at org.spockframework.lang.SpecInternals.MockImpl(SpecInternals.java:99)
13-Jul-2015 17:07:56	        at no.xxx.yyy.MyTest.setup(MyTest.groovy:17)

Lines 15-18 of MyTest is only

def mockSupplier
def setup() {
    mockSupplier = Mock(SomeSupplier)
}

This only happens with a couple of mocks, not all. One mock is of a public java class (which extends an abstract java class), the other of a default groovy class (which implements a java class). I haven’t been able to pinpoint why these two are special.

Is this only happening when running your tests with Gradle 2.5? Do they work fine with 2.4? Can you try and extract a standalone reproducible example?

Yes, this happened after we upgraded from Gradle 2.4 to 2.5.

I created a small example project, but now it fails with both 2.4 and 2.5. Can’t figure out why. Annoying.

I’ll try switching to com.github.cglib:cglib.cglib-nodep:e10bc3dda2 as mentioned in https://github.com/cglib/cglib/issues/32#issuecomment-76618932