Issue607391

classification
Title: Static sys.packageManager breaks class l
Type: Severity: normal
Components: Core Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: fwierzbicki Nosy List: fwierzbicki, wr0ngway
Priority: low Keywords:

Created on 2002-09-10.16:27:52 by wr0ngway, last changed 2008-11-03.22:23:41 by fwierzbicki.

Files
File name Uploaded Description Edit Remove
ClassLoaderBug.java wr0ngway, 2002-09-10.16:27:52 Java source illustrating bug
package-mgr-patch wr0ngway, 2002-09-10.17:19:46 patch
Messages
msg723 (view) Author: Matthew Conway (wr0ngway) Date: 2002-09-10.16:27:52
I have multiple PythonInterpreters, each constructed
with a new PySystemState, and each running in its own
thread.
I also give each PythonInterpreter its own classLoader
by setting sys.classLoader to a custom classloader
which takes care of adding the jars/etc to
sys.packageManager.
This custom classloader subclasses URLClassLoader and
allows one to dynamically add to the classpath by
delegating to URLClassLoader.addURL(), as well as
adding the entry to sys.packageManager.

Now, I have 2 interpreters (A and B) running, and add
an entry, foo.jar, to A's classLoader (and thereby the
package manager), and import a class, org.foo.Bar
If the B interpreter, which has nothing in its class
loader  also imports org.foo.Bar, it gets the one that
A pulled in, when it really should get nothing.
Even worse, if B's classloader points to a different
version of foo.jar, it still gets the version pulled in
by A's classloader (whichever gets into packageManager
first, wins)

I dug around in the code some, and discovered that
sys.packageManage is static, while sys.classLoader is
not, and imp.load(String name, PyList path) calls
PySystemState.packageManager.lookupName(name) to import
a java package.  I think this is the root of the problem.
A possible solution would be to make sys.packageManager
non-static.


Sample run of attached java source file, which shows
that the java Class loaded by jython is the same when
using different classloaders in different interpreters:


javac -classpath jython.jar;. ClassLoaderBug.java
java -classpath jython.jar;. ClassLoaderBug

Running in main thread:


sys ID: 787148
sys.classLoader ID: 4408106
sys.packageManager ID: 3163720
class:  sun.plugin.converter.ResourceHandler
class ID:  4151483

Running in another thread:


sys ID: 7337285
sys.classLoader ID: 6408657
sys.packageManager ID: 3163720
class:  sun.plugin.converter.ResourceHandler
class ID:  4151483
msg724 (view) Author: Matthew Conway (wr0ngway) Date: 2002-09-10.17:19:46
Logged In: YES 
user_id=407214

Here's the patch converting sys.packageManager to an
instance variable
History
Date User Action Args
2008-11-03 22:23:41fwierzbickisetassignee: fwierzbicki
nosy: + fwierzbicki
2002-09-10 16:27:52wr0ngwaycreate