Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy 2.0.1, GroovyCastException on my own class?

Tags:

java

groovy

I'm extensively using groovy classes in my web app project. I can create an instance of a type (defined as a groovy class) but can never at a later time cast back to it (GroovyCastException occurs).

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.company.role.delegation.ProfileModel@49ee6848' with class 'com.company.role.delegation.ProfileModel' to class 'com.company.role.delegation.ProfileModel'

According to the above error message, the source and destination class types are the same. Huh?

like image 278
dingalla Avatar asked Sep 04 '12 22:09

dingalla


1 Answers

Most likely the reason is that the class have been loaded twice via different classloaders. Check if the getClass().getClassLoader() for both the instances are identical.

like image 97
Anton Arhipov Avatar answered Nov 18 '22 02:11

Anton Arhipov