Issue1792881

classification
Title: PyString.split throws NullPointerException
Type: Severity: normal
Components: Core Versions:
Milestone:
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, tellarite
Priority: normal Keywords:

Created on 2007-09-12.03:10:40 by tellarite, last changed 2007-09-13.06:37:27 by cgroves.

Files
File name Uploaded Description Edit Remove
PythonStrings.java tellarite, 2007-09-12.03:10:40
Messages
msg1905 (view) Author: Ryan McGuire (tellarite) Date: 2007-09-12.03:10:40
The following java code throws a NullPointerException when I run PyString.split. (Also see PythonStrings.java attached)

I've confirmed that this ocurrs with both Jython 2.2 stable as well as today's trunk (r3470).

#####################################################

package com.enigmacurry.learning;

import org.python.core.*;

public class PythonStrings {
  public static void main(String[] args){
    PyString py_string = new PyString("  This is a test string  ");
    //This next line gives me a NullPointerException
    PyList py_list = py_string.split(" ");
  }
}

#####################################################

I get the following traceback:

#####################################################
Exception in thread "main" java.lang.NullPointerException
        at org.python.core.AbstractArray.setNewBase(AbstractArray.java:497)
        at org.python.core.AbstractArray.ensureCapacity(AbstractArray.java:269)
        at org.python.core.PyObjectArray.ensureCapacity(PyObjectArray.java:205)
        at org.python.core.AbstractArray.getAddIndex(AbstractArray.java:287)
        at org.python.core.PyObjectArray.add(PyObjectArray.java:72)
        at org.python.core.PyObjectList.pyadd(PyObjectList.java:84)
        at org.python.core.PySequenceList.pyadd(PySequenceList.java:135)
        at org.python.core.PyList.list_append(PyList.java:1069)
        at org.python.core.PyList.append(PyList.java:1065)
        at org.python.core.PyString.splitfields(PyString.java:2523)
        at org.python.core.PyString.str_split(PyString.java:2472)
        at org.python.core.PyString.str_split(PyString.java:2463)
        at org.python.core.PyString.split(PyString.java:2459)
        at com.enigmacurry.learning.PythonStrings.main(PythonStrings.java:9)

#####################################################

What's really interesting to me though is when I'm in the jython command line interpreter I get no such exception (granted I'm a jython newb and this is probably doing something slightly different):

ryan@insurgent enigmacurry $ jython
Jython 2.2 on java1.6.0
from oType "copyright", "credits" or "license" for more information.
>>> from org.python.core import PyString
>>> PyString("  This is a test string  ").split(" ")
['', '', 'This', 'is', 'a', 'test', 'string', '', '']
>>> 
msg1906 (view) Author: Charlie Groves (cgroves) Date: 2007-09-13.06:37:27
This is failing because Jython hasn't been initialized.  Jython assumes you've working with it through an instance of PythonInterpreter, so create one of those first and that code should work.
History
Date User Action Args
2007-09-12 03:10:40tellaritecreate