Issue607391

classification
Title: Static sys.packageManager breaks class l
Type: Severity: normal
Components: Core Versions: Jython 2.5
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: zyasoft Nosy List: fwierzbicki, sly, wr0ngway, zyasoft
Priority: high Keywords:

Created on 2002-09-10.16:27:52 by wr0ngway, last changed 2014-10-05.16:34:50 by zyasoft.

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
msg7397 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2012-08-13.18:45:00
Some of these globals are still around - this needs fixing for 2.5.4 and 2.7.
msg8237 (view) Author: Vladimir Kravets (sly) Date: 2014-02-04.09:23:07
Guys, in our project we are using jython as script engine and this issue it's very urgent for us.

We can apply this patch but, could you please specify why this patch is not applied yet? 
Is enough to apply attached patch or something else also need to waiting in the jython core.
msg8700 (view) Author: Jim Baker (zyasoft) Date: 2014-06-19.04:39:38
Target beta 4 - we really need to get rid of such static mutable globals. Especially since it has been a well known problem for 12 years now!

The shadowing fix we did for 2.5.1 (?) was only a partial fix - and we don't want to repeat shadowing because we didn't get it in time for a 2.X.0 release.
msg9035 (view) Author: Jim Baker (zyasoft) Date: 2014-09-26.04:58:06
Fixed as of https://hg.python.org/jython/rev/0e29ad2e098c - sorry I'm just closing out this bug now 3 months later
History
Date User Action Args
2014-10-05 16:34:50zyasoftsetstatus: pending -> closed
2014-09-26 04:58:06zyasoftsetstatus: open -> pending
resolution: accepted -> fixed
messages: + msg9035
2014-06-19 04:39:38zyasoftsetassignee: fwierzbicki -> zyasoft
resolution: remind -> accepted
messages: + msg8700
nosy: + zyasoft
2014-02-04 09:23:08slysetnosy: + sly
messages: + msg8237
2013-02-25 18:41:47fwierzbickisetversions: + Jython 2.5, - 2.5.1
2012-08-13 18:45:01fwierzbickisetpriority: low -> high
messages: + msg7397
2012-08-13 18:44:00fwierzbickisetresolution: remind
2009-03-30 16:39:57fwierzbickisetversions: + 2.5.1
2008-11-03 22:23:41fwierzbickisetassignee: fwierzbicki
nosy: + fwierzbicki
2002-09-10 16:27:52wr0ngwaycreate