Issue1127

classification
Title: Jython has problems to dynamically loading classes when installed on the boot classpath
Type: Severity: normal
Components: Core Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: fwierzbicki, leosoto, nriley, pjenvey
Priority: Keywords:

Created on 2008-09-13.18:47:45 by leosoto, last changed 2008-12-14.17:14:47 by fwierzbicki.

Messages
msg3522 (view) Author: Leonardo Soto (leosoto) Date: 2008-09-13.18:47:45
As discussed on
<http://thread.gmane.org/gmane.comp.lang.jython.user/7156>;, configuring
jython on the bootclasspath (as the current launcher script does) is
causing problems when dynamically loading classes which "live" on the
normal CLASSPATH (i.e, when using Class.forName()).

This typically impacts the use of JDBC drivers.
msg3523 (view) Author: Leonardo Soto (leosoto) Date: 2008-09-13.18:48:32
#1096 is clearly related to this issue.
msg3524 (view) Author: Leonardo Soto (leosoto) Date: 2008-09-13.18:49:04
Oh, and for the record, the current workaround is to use the --verify
flag when starting jython.
msg3543 (view) Author: Leonardo Soto (leosoto) Date: 2008-09-13.22:27:14
#1129 is also this problem
msg3580 (view) Author: Nicholas Riley (nriley) Date: 2008-09-14.04:05:26
So:

>>> Class.forName('com.apple.mrj.MRJPriv')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:169)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)

The full stack looks like:

Class<T>.forName(String) line: 169	
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39	
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25	
Method.invoke(Object, Object...) line: 597	
PyReflectedFunction.__call__(PyObject, PyObject[], String[]) line: 162	
PyReflectedFunction.__call__(PyObject[], String[]) line: 170	
PyReflectedFunction(PyObject).__call__(PyObject) line: 273	
_pyx2.f$0(PyFrame) line: not available	
_pyx2.call_function(int, PyFrame) line: not available	
PyTableCode.call(PyFrame, PyObject) line: 187	
PyTableCode(PyCode).call(PyFrame) line: 14	
Py.runCode(PyCode, PyObject, PyObject) line: 1200	
Py.exec(PyObject, PyObject, PyObject) line: 1227	
InteractiveConsole(PythonInterpreter).exec(PyObject) line: 134	
InteractiveConsole(InteractiveInterpreter).runcode(PyObject) line: 90	
InteractiveConsole(InteractiveInterpreter).runsource(String, String, String) line: 71	
InteractiveConsole(InteractiveInterpreter).runsource(String, String) line: 46	
InteractiveConsole.push(String) line: 110	
InteractiveConsole.interact(String, PyObject) line: 90	
jython.run(String[]) line: 294	
jython.main(String[]) line: 114	

So the problem is that Class.forName uses ClassLoader.getCallerClassLoader, whereas we want it to use another 
one.

>>> Thread.currentThread().getContextClassLoader()
sun.misc.Launcher$AppClassLoader@e47858e
>>> Class.forName('com.apple.mrj.MRJPriv', True, Thread.currentThread().getContextClassLoader())
<jclass com.apple.mrj.MRJPriv 1>

At least for cases like #1129 and #1096, we could change Jython's and zxJDBC's Class.forName calls to 
explicitly specify a classloader, as above.

Another issue is people using Class.forName explicitly from Jython.  In general it looks like we need to have 
the invoking class have a "valid" classloader.  From instrumenting ClassLoader.getCallerClassLoader, that 
ends up being PyReflectedFunction.  So, maybe we can load PyReflectedFunction from somewhere else to get 
around this?
History
Date User Action Args
2008-12-14 17:14:47fwierzbickisetnosy: + fwierzbicki
2008-12-10 08:36:28pjenveysetnosy: + pjenvey
2008-09-14 04:05:27nrileysetnosy: + nriley
messages: + msg3580
2008-09-13 22:27:14leosotosetmessages: + msg3543
2008-09-13 18:49:04leosotosetmessages: + msg3524
2008-09-13 18:48:32leosotosetmessages: + msg3523
2008-09-13 18:47:46leosotocreate