On Oct 20, 4:50 pm, Jon  Zeppieri <[EMAIL PROTECTED]> wrote:
> On Oct 20, 2:13 pm, Jon  Zeppieri <[EMAIL PROTECTED]> wrote:
>
> > I have a class "one.two.Foo" in a jar file named "foo.jar".  From the
> > documentation, I think I should be able to do the following:
>
> > var url = new java.net.URL("file:///path/to/foo.jar");
> > var loader = new java.net.URLClassLoader([ url ]);
> > var pks = new Packages(loader);
> > var foo = pks.one.two.Foo();
>
> > However, this doesn't work.  I'm getting a NullPointerException:
>
> > [snip]
>
> > This is taking place in a very simple embedding of Rhino in a servlet.
>
> By the way, the exact same error occurs in the shell, so the embedding
> is irrelevant.  The 'pks' instance of NativeJavaPackage apparently
> doesn't have a parent scope.  I'd expect it to be the global scope,
> right?  But, for some reason, it's null.
>
> -Jon


I guess I'm in the business of replying to myself, but maybe one of
the Rhino developers can tell me if the change I made is correct...

So, when you use

   var foo = new Packages(classloader)

... a new instance of NativeJavaPackage is constructed, but neither
its prototype nor its parent scope is set.  The relevant code is in
NativeJavaTopPackage.construct().  I replaced the last line of that
method:

   return new NativeJavaPackage(true, "", loader);

... with the following four lines:

   NativeJavaPackage result = new NativeJavaPackage(true, "", loader);
   result.setPrototype(getObjectPrototype(scope));
   result.setParentScope(scope);
   return result;

Are these the correct values for the prototype and parent scope?  (I'm
pretty confident about the scope but not so much about the
prototype.)  Also, is this the right place for this code?

(This change does fix the particular problem I reported.)

-Jon
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to