Closed arthurhjorth closed 10 years ago
Sounds like classloader problems — the same .class file on disk, loaded into memory twice in two different class loaders, results in two Class
objects that have the same name, but are not actually the same class, since they belong to different classloaders.
And NetLogo always loads each extension in its own private classloader, so that's why there are multiple loaders involved here.
One way to get around this would be to do your instanceof
check other calls using reflection. It's kind of a hack, but you might decide it's the shortest path to working code.
It's not clear to me what a "real" fix might consist of. I guess it would involve finding some way to convince ExtensionManager to use the same class loader for a child models as it's already using for the parent. I don't know much about the internals of ExtensionManager; other people did the heavy lifting and setting up the class loader stuff in there, and I've never had to seriously mess with it.
Oh, that explains it. The problem isn't really the instanceof
check, because I could just do a string comparison - it is that I can't cast the object so that I can use it. I'll try and use Reflection to get the class of the object and see if that works. Reflection might reference the classloader of the class that uses it though, but we'll see. It won't be super fast, but this is only for when people close models, which shouldn't be that frequently.
Thanks a lot!
I've been working on this for a while now, but I've run into a strange problem. It seems like Java doesn't recognize classes of Extensions in the ExtensionsManager. Not sure how to explain it, but here is my setup and code (I replaced print statements with comments).
I load a GUI model of a custom Wolf Sheep Predation that loads the LevelsSpace extension, and then loads Bounce Example.nlogo (i.e. the latter is the child of the former, and the former is the child of the main App.) My goal is to have all models be closed at the call of this method:
Does anyone have any idea what could be causing this?