From: <bc...@wo...> - 2000-10-19 18:40:39
|
Recently there have been several complaints about the silent handling of primary the NoClassDefFoundError exception. To the user it look as if the java class does not exists, even when it is obviously available. Rather than silently catching the NoClassDefFoundError error, I would prefer if the exception was returned as a java exception to the user. The ClassNotFoundException exception is still used to signal that the class is in fact not available. ANy comments to this change of existing behaviour? Index: Py.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/Py.java,v retrieving revision 2.20 diff -c -r2.20 Py.java *** Py.java 2000/10/13 20:02:59 2.20 --- Py.java 2000/10/19 18:36:45 *************** *** 556,561 **** --- 556,581 ---- } } + + public static Class findClassEx(String name) { + try { + ClassLoader classLoader = Py.getSystemState().getClassLoader(); + if (classLoader == null) + return Class.forName(name); + else + return classLoader.loadClass(name); + } + catch (ClassNotFoundException e) { + return null; + } + catch (IllegalArgumentException e) { + throw JavaError(e); + } + catch (LinkageError e) { + throw JavaError(e); + } + } + private static void setArgv(String arg0, String[] args) { PyObject argv[] = new PyObject[args.length+1]; argv[0] = new PyString(arg0); Index: PyJavaClass.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyJavaClass.java,v retrieving revision 2.21 diff -c -r2.21 PyJavaClass.java *** PyJavaClass.java 2000/10/09 14:45:14 2.21 --- PyJavaClass.java 2000/10/19 18:36:49 *************** *** 74,80 **** return; initializing = true; if (proxyClass == null) ! init(Py.findClass(__name__)); init__bases__(proxyClass); init__dict__(); initialized = true; --- 74,80 ---- return; initializing = true; if (proxyClass == null) ! init(Py.findClassEx(__name__)); init__bases__(proxyClass); init__dict__(); initialized = true; Index: PyJavaDirPackage.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyJavaDirPackage.java,v retrieving revision 2.1 diff -c -r2.1 PyJavaDirPackage.java *** PyJavaDirPackage.java 1999/05/17 19:59:39 2.1 --- PyJavaDirPackage.java 2000/10/19 18:36:49 *************** *** 63,69 **** return ret; } ! Class c = Py.findClass(attrName); if (c != null) { ret = PyJavaClass.lookup(c); __dict__.__setitem__(name, ret); --- 63,69 ---- return ret; } ! Class c = Py.findClassEx(attrName); if (c != null) { ret = PyJavaClass.lookup(c); __dict__.__setitem__(name, ret); Index: PyJavaPackage.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyJavaPackage.java,v retrieving revision 2.1 diff -c -r2.1 PyJavaPackage.java *** PyJavaPackage.java 1999/05/17 19:59:39 2.1 --- PyJavaPackage.java 2000/10/19 18:36:50 *************** *** 190,198 **** return ret; Class c; if (__name__.length()>0) ! c = Py.findClass(__name__+'.'+name); else ! c = Py.findClass(name); if (c != null) { ret = PyJavaClass.lookup(c); --- 190,198 ---- return ret; Class c; if (__name__.length()>0) ! c = Py.findClassEx(__name__+'.'+name); else ! c = Py.findClassEx(name); if (c != null) { ret = PyJavaClass.lookup(c); Index: imp.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/imp.java,v retrieving revision 2.25 diff -c -r2.25 imp.java *** imp.java 2000/10/18 14:00:49 2.25 --- imp.java 2000/10/19 18:36:53 *************** *** 191,197 **** return Py.java2py(Py.getSystemState()); String mod = PySystemState.getBuiltin(name); if (mod != null) { ! Class c = Py.findClass(mod); if (c != null) { try { return createFromClass(name, c); --- 191,197 ---- return Py.java2py(Py.getSystemState()); String mod = PySystemState.getBuiltin(name); if (mod != null) { ! Class c = Py.findClassEx(mod); if (c != null) { try { return createFromClass(name, c); *************** *** 210,216 **** if (Py.frozenPackage != null) { modName = Py.frozenPackage+"."+modName; } ! return Py.findClass(modName+"$_PyInner"); } private static PyObject loadPrecompiled(String name, String modName, --- 210,216 ---- if (Py.frozenPackage != null) { modName = Py.frozenPackage+"."+modName; } ! return Py.findClassEx(modName+"$_PyInner"); } private static PyObject loadPrecompiled(String name, String modName, *************** *** 352,358 **** if (ret != null) return ret; if (Py.frozen) { ! Class c = Py.findClass(name); if (c != null) return createFromClass(name, c); } --- 352,358 ---- if (ret != null) return ret; if (Py.frozen) { ! Class c = Py.findClassEx(name); if (c != null) return createFromClass(name, c); } |