bgarrels / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

Don't use ObjenesisHelper #335

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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

Original issue reported on code.google.com by graeme.r...@gmail.com on 12 Nov 2013 at 1:21

GoogleCodeExporter commented 9 years ago
We have put in place this horrible hack until this is fixed

https://github.com/grails/grails-core/commit/6b02cedd5a0664ec50276ee2577fa591a23
d114b

Original comment by graeme.r...@gmail.com on 12 Nov 2013 at 1:32

GoogleCodeExporter commented 9 years ago
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?

Original comment by pnied...@gmail.com on 27 Dec 2013 at 11:36

GoogleCodeExporter commented 9 years ago
(Another option might be to never use a cache.)

Original comment by pnied...@gmail.com on 27 Dec 2013 at 11:39

GoogleCodeExporter commented 9 years ago
(Or to scope the cache to a single test class execution.)

Original comment by pnied...@gmail.com on 27 Dec 2013 at 11:43

GoogleCodeExporter commented 9 years ago
I class loader aware cache would be fine

Original comment by graeme.r...@gmail.com on 27 Dec 2013 at 11:22

GoogleCodeExporter commented 9 years ago

Original comment by pnied...@gmail.com on 28 Jan 2014 at 9:55