Issue2492

classification
Title: NPE for PythonInterpreter after new PyInteger
Type: crash Severity: normal
Components: Core, Library Versions: Jython 2.7
Milestone:
process
Status: pending Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: flungo, jeff.allen, zyasoft
Priority: normal Keywords:

Created on 2016-04-13.15:00:15 by flungo, last changed 2018-03-13.22:08:42 by jeff.allen.

Messages
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.
msg11793 (view) Author: Jeff Allen (jeff.allen) Date: 2018-03-13.22:08:41
It may be challenging, but I seem to have fixed it without even trying 8)

Improved reasoning around the bootstrap process, as part of #2609, made it possible to remove this error message:
https://hg.python.org/jython/rev/55756721fa02#l7.7
and although something like it reappears here:
https://hg.python.org/jython/rev/55756721fa02#l8.950
I think bootstrapping sorts itself out unless you mess up the class path.

I can reproduce the error using Fabrizio's sample code with:
PS bugs> java -cp ".;C:\Jython\2.7.0\jython.jar" iss2492.NPETest
init: Bootstrapping class not in BootstrapTypesSingleton.getInstance()[class=class org.python.core.PyInteger]

and:
PS bugs> java -cp ".;C:\Jython\2.7.1rc3\jython.jar" iss2492.NPETest
init: Bootstrapping class not in BootstrapTypesSingleton.getClassToType()[class=class org.python.core.PyInteger]

but:
PS bugs> java -cp ".;C:\Jython\2.7.2a1\jython.jar" iss2492.NPETest
works. I propose therefore to close as fixed.
History
Date User Action Args
2018-03-13 22:08:42jeff.allensetpriority: normal
status: open -> pending
resolution: fixed
messages: + msg11793
nosy: + jeff.allen
2016-04-27 21:32:50zyasoftsetnosy: + zyasoft
messages: + msg10841
2016-04-13 15:00:15flungocreate