Title: NPE for PythonInterpreter after new PyInteger
Type: crash Severity: normal
Components: Core, Library Versions: Jython 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: flungo, zyasoft
Priority: Keywords:

Created on 2016-04-13.15:00:15 by flungo, last changed 2016-04-27.21:32:50 by zyasoft.

msg10835 (view) Author: Fabrizio Lungo (flungo) Date: 2016-04-13.15:00:14
I am sure there are probably other objects that cause this, but if you instantiate a `PyInteger` before any other call within the jython library, it will then cause the instantiation of a `PythonInterpreter` to always throw a NullPointerException.

This is very easy to reproduce:

public class NPETest {
    public static void main(String[] args) {
        new PyInteger(0);
        new PythonInterpreter();


When the above code is run, the following warning message is printed:

init: Bootstrapping class not in BootstrapTypesSingleton.getInstance()[class=class org.python.core.PyInteger]

This can be avoided by getting the class loader to load the `PyObject` class before instantiating the new `PyInteger` even indirectly through loading `PyInteger`: adding `System.out.println(PyInteger.gcMonitorGlobal);` before instantiating the PyInteger works. This seems to only works because `PyInteger.gcMonitorGlobal` is inherited from `PyObject`.

I am not sure if adding a static code block that forces initialisation in `PyInteger` will help, or even be the best way to resolve this but it might work as a temporary fix.

This may be related to #1671 or the fix introduced for it.
msg10841 (view) Author: Jim Baker (zyasoft) Date: 2016-04-27.21:32:50
This will be challenging to fix, due to PySystemState's complex initialization. Right now, it's important to start the Jython runtime before using it; this should be easier to do as a client of Jython than Jython itself, just because of the various entry points we support.
Date User Action Args
2016-04-27 21:32:50zyasoftsetnosy: + zyasoft
messages: + msg10841
2016-04-13 15:00:15flungocreate