Export to GitHub

spock - issue #335

Don't use ObjenesisHelper


Posted on Nov 12, 2013 by Happy Ox

We have an issue in Grails (http://jira.grails.org/browse/GRAILS-10720) where a ClassCastException is thrown on second run of the tests. This is because Spock uses ObjenesisHelper which has the cache enabled by default. The Objenesis cache uses the class name as the key (not the class) this results if a different class being returned and the resulting ClassCastException.

Unfortunately because Spock uses ObjenesisHelper there is no way to disable the cache. Spock should use a customisable version of the ObjenesisStd and ObjenesisSerializer classes that can be modified by the user / other frameworks if needed

Comment #1

Posted on Nov 12, 2013 by Happy Ox

We have put in place this horrible hack until this is fixed

https://github.com/grails/grails-core/commit/6b02cedd5a0664ec50276ee2577fa591a23d114b

Comment #2

Posted on Dec 27, 2013 by Grumpy Cat

Would it be good enough if we put a class loader aware cache in place, or do you truly need to be able to customize this?

Comment #3

Posted on Dec 27, 2013 by Grumpy Cat

(Another option might be to never use a cache.)

Comment #4

Posted on Dec 27, 2013 by Grumpy Cat

(Or to scope the cache to a single test class execution.)

Comment #5

Posted on Dec 27, 2013 by Happy Ox

I class loader aware cache would be fine

Comment #6

Posted on Jan 28, 2014 by Grumpy Cat

(No comment was entered for this change.)

Status: Duplicate

Labels:
Type-Defect Module-Core Milestone-1.0