From: Finn B. <bc...@us...> - 2000-12-05 18:56:04
|
Update of /cvsroot/jython/jython/org/python/core In directory slayer.i.sourceforge.net:/tmp/cvs-serv11427 Modified Files: PyJavaInstance.java Log Message: __init__(): Always check for abstract and interface. This gives a sensible error message when trying to create instances of a class like: public abstract class test265j { public test265j() { } } Index: PyJavaInstance.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyJavaInstance.java,v retrieving revision 2.1 retrieving revision 2.2 diff -C2 -r2.1 -r2.2 *** PyJavaInstance.java 1999/05/17 19:59:39 2.1 --- PyJavaInstance.java 2000/12/05 18:56:02 2.2 *************** *** 39,57 **** public void __init__(PyObject[] args, String[] keywords) { - PyReflectedConstructor init = ((PyJavaClass)__class__).__init__; //javaProxies = new Object[1]; ! if (init == null) { ! Class pc = __class__.proxyClass; ! if (pc != null) { ! int mods = pc.getModifiers(); ! if (Modifier.isInterface(mods)) { ! throw Py.TypeError("can't instantiate interface ("+ ! __class__.__name__+")"); ! } ! else if (Modifier.isAbstract(mods)) { ! throw Py.TypeError("can't instantiate abstract class ("+ ! __class__.__name__+")"); ! } } throw Py.TypeError("no public constructors for "+ __class__.__name__); --- 39,59 ---- public void __init__(PyObject[] args, String[] keywords) { //javaProxies = new Object[1]; ! ! Class pc = __class__.proxyClass; ! if (pc != null) { ! int mods = pc.getModifiers(); ! if (Modifier.isInterface(mods)) { ! throw Py.TypeError("can't instantiate interface ("+ ! __class__.__name__+")"); } + else if (Modifier.isAbstract(mods)) { + throw Py.TypeError("can't instantiate abstract class ("+ + __class__.__name__+")"); + } + } + + PyReflectedConstructor init = ((PyJavaClass)__class__).__init__; + if (init == null) { throw Py.TypeError("no public constructors for "+ __class__.__name__); |