Spock with JDK 1.8 and non-interface types

4,972 views
Skip to first unread message

Vetle Leinonen-Roeim

unread,
Aug 13, 2014, 6:24:36 AM8/13/14
to spockfr...@googlegroups.com
Hi,

Trying to build a project with JDK 1.8, with "-target 1.8", and running into some issues. Specifically, there seems to be a problem with JDK 1.8 and CGLIB:
java.lang.IllegalArgumentException: null
        at net.sf.cglib.proxy.BridgeMethodResolver.resolveAll(BridgeMethodResolver.java:61)
        at net.sf.cglib.proxy.Enhancer.emitMethods(Enhancer.java:911)
        at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:498)
        at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
        at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
        at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
        at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
        at org.spockframework.mock.runtime.ProxyBasedMockFactory$CglibMockFactory.createMock(ProxyBasedMockFactory.java:91)

Removing the CGLIB dependency gives me this error:
org.spockframework.mock.CannotCreateMockException: Cannot create mock for class x.y.Z. Mocking of non-interface types requires the CGLIB library. Please put cglib-nodep-2.2 or higher on the class path. 

It would seem that CGLIB is not compatible with JDK 1.8.

Has anyone run into this problem?
Any ideas on how to solve it without rewriting to use interfaces?

Regards,
Vetle

Vetle Leinonen-Roeim

unread,
Aug 13, 2014, 8:33:17 AM8/13/14
to spockfr...@googlegroups.com
Ok, so to answer my own question, it seems that Java 8 support in cglib has been added, but a version that includes it has not yet been released.

pnie...@gmail.com

unread,
Aug 13, 2014, 11:59:55 AM8/13/14
to spockfr...@googlegroups.com
I already pinged the CGLIB folks and asked them to cut a release, but didn't get a response. I also tried to switch to ByteBuddy, but that turned out to be too complicated. At this point I’m still hoping for a new CGLIB release.

Cheers,
Peter

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spockframewor...@googlegroups.com.
To post to this group, send email to spockfr...@googlegroups.com.
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

Vetle Leinonen-Roeim

unread,
Aug 14, 2014, 1:56:54 PM8/14/14
to spockfr...@googlegroups.com
Ok, thanks. Crossing my fingers!

Daniel Scott

unread,
Nov 4, 2014, 4:27:50 PM11/4/14
to spockfr...@googlegroups.com
Did you get any further with this? The latest version of CGLIB is 3.1 (Dec 2013), and I'm still getting the same errors.

I'm guessing I can work around it by only mocking interfaces? This would be a fairly large code change for me though.

Dan

Peter Niederwieser

unread,
Nov 5, 2014, 7:20:04 AM11/5/14
to spockfr...@googlegroups.com
From what I can tell, CGLIB is neglecting this problem and still hasn't put out a new release. I've made some attempts to switch out CGLIB for ByteBuddy, but this turned out to be more complicated then expected. So unfortunately, I can't offer a solution at this time. Any help on this would be appreciated.

It's correct that CGLIB is only used when class are mocked. For mocking interfaces, plain Java dynamic proxies are used, which don't have this problem.

Cheers,
Peter

Oscar Bernal

unread,
Dec 11, 2014, 8:23:45 AM12/11/14
to spockfr...@googlegroups.com
Hi Peter. Have you tried compiling Spock against their code in the master branch and have you confirmed the issue is solved by doing so? I built their code myself and tried using the 3.2.0-SNAPSHOT dependency in my project, however I got a few NoClassDefFoundError exceptions when running the tests. Expected since Spock is built against an earlier version of cglib.

However if you have already tried their latest code which supposedly fixes this and have confirmed that takes care of this issue, maybe we can all put some pressure here on the issue https://github.com/cglib/cglib/issues/8 and get them to make a release.

Sorry if you have already tested and it's an obvious question, but I just don't want to get a vague response like "please file a bug" when all we need is a release. We too are on Java8 and having quite a few problems with this.

Thanks!

Oscar

Peter Niederwieser

unread,
Dec 15, 2014, 7:32:38 PM12/15/14
to spockfr...@googlegroups.com
I'm pretty sure I tried it, but having somebody double-check would be very welcome.

Cheers,
Peter

Oscar Bernal

unread,
Dec 18, 2014, 8:13:58 AM12/18/14
to spockfr...@googlegroups.com
Ok, I'll give it a shot and come back with results. 

Thanks!

Oscar

Odin Hole Standal

unread,
Jan 13, 2015, 10:06:39 AM1/13/15
to spockfr...@googlegroups.com
Any traction on this issue? We're seeing the same kinds of issues, hope this gets fixed soon.

/Odin

Cameron Fieber

unread,
Feb 6, 2015, 3:23:20 PM2/6/15
to spockfr...@googlegroups.com
I think I worked around this by forcing my cglib dependency to the latest (cglib:cglib:3.1 not cglib:cglib-nodep:3.1) and then forcing asm to the latest (org.ow2.asm:asm-all:5.0.3 + exclude asm:*)

josch...@netflix.com

unread,
Feb 16, 2015, 6:49:39 PM2/16/15
to spockfr...@googlegroups.com
+1 on Cameron's solution which works for Spock.  Groovy map and closure coercion is still broken for the same reason up to at least groovy 2.3.9 unfortunately.

Peter Niederwieser

unread,
Mar 2, 2015, 9:41:38 PM3/2/15
to spockfr...@googlegroups.com
See `spock-specs/specs.gradle` for how I solved the problem for Spock's own Java 8 build. Effectively it comes down to using a prerelease version of CGLIB 3.2, which is now very easy thanks to the awesome 

https://jitpack.io.

Cheers, Peter

Kevin Wittek

unread,
Jun 2, 2015, 6:27:35 AM6/2/15
to spockfr...@googlegroups.com
When using the latest GIT revision, I get the following error in my Spring project using Spock:


java.lang.NoClassDefFoundError: Could not initialize class org.spockframework.mock.runtime.ProxyBasedMockFactory$CglibMockFactory$ConstructorFriendlyEnhancer
at org.spockframework.mock.runtime.ProxyBasedMockFactory$CglibMockFactory.createMock(ProxyBasedMockFactory.java:80)

Leonard Brünings

unread,
Jun 11, 2015, 4:28:18 PM6/11/15
to spockfr...@googlegroups.com
Hi Kevin, it should work with the current master.

Sairam Rekapalli

unread,
Dec 14, 2015, 7:24:08 PM12/14/15
to Spock Framework - User
I'm usng cglib-nodep:3.2.0 and is on the classpath, java 8 & spock 1.0-grovy-2.4 and I receive this error:

Cannot create mock for class . Mocking of non-interface types requires the CGLIB library. Please put cglib-nodep-2.2 or higher on the class path.

what version of cglib has the fix ?

Appreciate any input.

Thanks.

John Allen

unread,
Aug 26, 2016, 3:44:08 PM8/26/16
to Spock Framework - User
So just a reply for the latest status.

Both RELEASE and LATEST versions work.  Hurray!

<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>RELEASE</version>
</dependency>

Xin Meng

unread,
Oct 23, 2017, 12:14:43 PM10/23/17
to Spock Framework - User
After testing, the latest version of cglib has resolved this issue

<dependency>
   
<groupId>cglib</groupId>
   
<artifactId>cglib-nodep</artifactId>

   
<version>3.2.5</version>
</dependency>

Reply all
Reply to author
Forward
0 new messages