Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Andrea <mariofutire <at> googlemail.com>
Subject: Bug in PyException and null/None?
Newsgroups: gmane.comp.lang.jython.user
Date: Tuesday 28th July 2009 08:43:20 UTC (over 8 years ago)
This is linked to the recent messages about Debug in NetBeans and bug in
sys.settrace().

I've managed to reproduce this error and been able to print the full Java
stack trace when this exception occurs (basically the tracefunction calls
a Java method and from there I print the stack trace).

        at org.python.core.PyTuple.get(PyTuple.java:487)
        at newpackage.NewClass.whatIs(NewClass.java:14)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at
org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:175)
        at
org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
        at org.python.core.PyObject.__call__(PyObject.java:397)
        at org.python.core.PyObject.__call__(PyObject.java:401)
        at
org.python.pycode._pyx0.printTrace$1(H:\foo\src\newpythonproject.py:11)
        at
org.python.pycode._pyx0.call_function(H:\foo\src\newpythonproject.py)
        at org.python.core.PyTableCode.call(PyTableCode.java:165)
        at org.python.core.PyBaseCode.call(PyBaseCode.java:163)
        at org.python.core.PyFunction.__call__(PyFunction.java:338)
        at org.python.core.PyFunction.__call__(PyFunction.java:332)
        at org.python.core.PythonTraceFunction.safeCall
        (PythonTraceFunction.java:24)
        at
org.python.core.PythonTraceFunction.traceException
(PythonTraceFunction.java:55)
        at org.python.core.PyException.(PyException.java:55)
        at org.python.core.PyException.(PyException.java:43)
        at org.python.core.PyException.(PyException.java:61)
        at org.python.core.Py.ImportError(Py.java:264)
        at org.python.core.JavaImporter.__call__(JavaImporter.java:14)

The problem is that the trace function is called with a PyException that
contains a null traceback. (PyException.java:55)
This value will eventually go into a PyTuple (at the end of
PythonTraceFunction.java)

    public TraceFunction traceException(PyFrame frame, PyException exc) {
        return safeCall(frame,
                        "exception",
                        new PyTuple(exc.type, exc.value, exc.traceback));
    }                                                    ^^^^^^^^^^^^^
                                                         this is null!

and PyTuple does not work very well with null (not None).

The null is created in the constructor of PyException (line 43),
and then again at line 47.

Since I don't know what is the general situation of null vs None,
this bug can be fixed at different levels

1) let PyException's constructor take care of avoiding null
2) let the PythonTraceFunction convert null -> None
3) let the PyTuple convert all null -> None (when they arrive)
4) let the PyTuple convert all null -> None (when they leave the PyTuple)

If anybody with more experience of Jython could explain me a bit this 
null/None situation, I will provide a patch.

Andrea



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day

trial. Simplify your report design, integration and deployment - and focus
on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
 
CD: 3ms