I use Javassist to create a class. And in a test suite, when a second test tries to create the same class, it fails at pool.makeClass( ... )
because the class is frozen (i.e. already created via toClass()
.
What's the way to overcome this? Ideally, the first test should delete the class somehow - perhaps unload from the classloader - but as I read in JLS, the unload operation is not reliable.
So perhaps the workaround is to check in the class creating code whether it exists, and if it does, defrost()
it, remove all members etc, and re-create it.
Any other ideas?
Or is there some reliable way to delete the class through Javassist?