Message3580

Author nriley
Recipients leosoto, nriley
Date 2008-09-14.04:05:26
SpamBayes Score 4.440892e-16
Marked as misclassified No
Message-id <1221365127.97.0.231284603334.issue1127@psf.upfronthosting.co.za>
In-reply-to
Content
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-09-14 04:05:27nrileysetmessageid: <1221365127.97.0.231284603334.issue1127@psf.upfronthosting.co.za>
2008-09-14 04:05:27nrileysetrecipients: + nriley, leosoto
2008-09-14 04:05:27nrileylinkissue1127 messages
2008-09-14 04:05:27nrileycreate