[bug?] Dynamically defined classes cause linkage errors (duplicate definitions).

Dawid Weiss <[email protected]>
Newsgroups gmane.comp.java.beanshell.devel
Organization Poznan University of Technology
Message-ID <[email protected]>
(Apologies if this has been discussed before and I missed it)

Hi Pat, everybody,

I've  just  encountered  an  unexpected  problem. Let me state the scenario
first, so that you know what I'm talking about:

I  have  a  method  that  executes  BeanShell scripts. Every script should,
theoretically,  be  given  its  own  namespace  (and  I'm  also giving it a
separate Interpreter object). Now, this script:

> import [...]
> 
> public class MyFactory implements LocalComponentFactory {
>     public LocalComponent getInstance() {
>             LocalComponent c = new StubOutputComponent();
>             c.setProperty("property", "value");
>             return c;
>     }
> };
> 
> return new LoadedComponentFactory(
>         /* id */ "stub-output", 
>         new MyFactory(), 
>         /* pool size */ 5);

which  defines  a  new  'scripted'  class  works  fine the first time it is
executed. But successive attempts to run it throw:

java.lang.LinkageError: duplicate class definition: MyFactory

I  looked  in  the source code and you always instantiate new classes using
BshClassManager's parent class loader:

>     public Class defineClass(String s, byte abyte0[])
>     {
>         ClassLoader classloader = getClass().getClassLoader();
>         Class class1;
>         try
>         {
>             class1 = (Class)Reflect.invokeObjectMethod(classloader, "defineClass", new Object[] {
>                 s, abyte0, new Primitive(0), new Primitive(abyte0.length)
>             }, (Interpreter)null, (CallStack)null, (SimpleNode)null);
>         }
...

This  approach  makes true script isolation virtually impossible, right? Or
am I missing something here.

Dawid

-- 
Dawid Weiss, http://www.cs.put.poznan.pl/dweiss
Laboratory of Intelligent Decision Support Systems, Poznan UT, Poland



-------------------------------------------------------
This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek
For a limited time only, get FREE Ground shipping on all orders of $35
or more. Hurry up and shop folks, this offer expires April 30th!
http://www.thinkgeek.com/freeshipping/?cpg=12297
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.