Message2727

Author mehendran
Recipients
Date 2007-07-02.08:36:07
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
PS: Patch file is attached with this

Problem:
========

lets say ur in /home/someuser/. 
In this folder u r creating prog.jar which has __run__.py. 
          
__run__.py contains
--------------------
# __run__.py begin --
from java.lang import Thread
class PythonThread(Thread): pass
# __run__.py end -- 


if u run like 

"jython -jar prog.jar" 

from /home/someuser/ it is not giving any error.
but if run from some other folder or even the same folder like  

"jython -jar /home/someuser/prog.jar"

it is throwing exception 

java.lang.NoClassDefFoundError: IllegalName: org.python.proxies./home
/someuser/prog.jar$PythonThread$0

Reason: 
=======

The name of the class is generated step by step as in the following

PyClass.java
------------
String proxyName = __name__;  
//proxyName contains "PythonThread"

PyObject module = dict.__finditem__("__module__");     // module.toString ==> "/home/someuser/prog.jar"

if (module != null) {
   proxyName = module.toString() + "$" + __name__;    

MakeProxies.java
----------------
String fullProxyName = proxyPrefix + proxyName + "$" + proxyNumber++;  

Now the name of the class name would be      org.python.proxies./home/someuser/prog.jar$PythonThread$0

When you run, this class is loaded with the name of above said. But The following check is being done before loading the class.

ClassLoader.java (java.lang.ClassLoader)
----------------------------------------
private ProtectionDomain preDefineClass(String name,                                              
ProtectionDomain protectionDomain)
{
    // name - class name with pkg including          
    if (!checkName(name)) 
        throw new NoClassDefFoundError("IllegalName: " + name);
    ---
    ---
    ---
}

the checkName method of ClassLoader.java
-----------------------------------------
   private boolean checkName(String name) {
	if ((name == null) || (name.length() == 0))
   	    return true;
	if ((name.indexOf('/') != -1)
	    || (!VM.allowArraySyntax() && (name.charAt(0) == '[')))
   	    return false;
 	return true;
    }

Because the name of the class contains '/' character, the check func fails and it results in NoClassDefFoundExceptiion.

Solution:
=========
This may be one of the solutions.

jython.java
----------
public static void runJar(String filename) {
     ---
     locals.__setitem__("__name__", new PyString(filename));
     ---
     ---         
}            

Here filename is "/home/someuser/prog.jar". 

So if u pass the file name after trimming the 
path (ie passing merely the name of the jar[prog.jar]), 
the program runs quietly.



History
Date User Action Args
2008-02-20 17:18:43adminlinkissue1746339 messages
2008-02-20 17:18:43admincreate