Issue Details (XML | Word | Printable)

Key: GROOVY-1248
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Jochen Theodorou
Reporter: Art Gramlich
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
groovy

Class reloading of classes through GCL fails when a groovy class is a subclass of another groovy class

Created: 16/Feb/06 01:35 PM   Updated: 02/Mar/06 09:24 AM   Resolved: 02/Mar/06 09:24 AM
Component/s: groovy-jdk
Affects Version/s: None
Fix Version/s: 1.0-JSR-6

Time Tracking:
Not Specified

File Attachments: 1. Text File class_reloading.patch (1 kB)


Testcase included: yes


 Description  « Hide

In order for Grails to support reloading of classes without causing problems with cached instances in application and session scope I need Groovy to support a loadClass method that reloads a class if it has been changed.

Ideally it needs to interact with the GroovyResourceLoader to load resources as Urls if possibly.

Something like

gcl.loadClass(final String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve, boolean reload)

would be ok.. otherwise maybe a different method

gcl.reloadClassIfNecessary(String name) maybe ?
gcl.reloadClass(String name, boolean force) // for forced reload or false to return current if no changes?

I've attached the test case I used to test this out originally in Grails. It is not Grails specific so you should be able to drop it into groovy and just change the package names



Art Gramlich added a comment - 16/Feb/06 01:40 PM

It looks like when a groovy class is a subclass of another groovy class, the reloading doesn't work since it doesn't see the GroovyObject interface. I've created a simple patch to descend the inheritance tree. Seems to work fine with the patch.


Art Gramlich added a comment - 16/Feb/06 01:41 PM

The patch described.


Art Gramlich added a comment - 16/Feb/06 02:52 PM

It also looks like removeFromCache should be

public void removeFromCache(Class aClass) { cache.remove(aClass.getName()); }

instead of

public void removeFromCache(Class aClass) { cache.remove(aClass); }


Jochen Theodorou added a comment - 02/Mar/06 09:24 AM

I now use Class#isAssignableFrom instead of going through the class tree and doing the compares with strings. I think that is good enough, because if the GroovyObject.class of the ClassLoader is the wrong one, then a newly generated class will have also the wrong class. I don't think that is something we should support. It is difficult enough with so many class loaders. The removing of the class works now by name.