Hi all,
We use Rhino in an environment where the class loader that is used to load Java classes from JavaScript might change over time. It may also be that new versions of already available and used classes may become available over time.
We are evaluating what caches in Rhino prevent these new versions of classes to be used in JavaScript. We already found out about the org.mozilla.javascript.ClassCache instance at the top level scope where a simple clearCache() does the trick.
We however now encounter a problem if Java Classes are referenced and created via Java package expressions like:
var object = new Packages.my.package.containing.a.CustomClass()
As we see in the code every NativeJavaPackage object, responsible for representing a Java package in JS, has its own "class cache". It simply stores the retrieved sub-package/class as property slot on itself. This can be nicely seen in method NativeJavaPackage.getPkgProperty():
synchronized Object getPkgProperty(String name, Scriptable start,
boolean createPkg)
{
Object cached = super.get(name, start);
if (cached != NOT_FOUND)
return cached;
if (negativeCache != null && negativeCache.contains(name)) {
// Performance optimization: see bug 421071
return null;
}
....
}
In order to also effectively clear this cache, I assume one would need to rebuild/clear it on the root package object "Packages" or would need to replace the root scope along with it altogether, which I think is rather heavy.
Is there any way to get rid of this package/class cache that I'm missing?
Thanks for any insight!
Oliver