Message1905

Author tellarite
Recipients
Date 2007-09-12.03:10:40
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
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', '', '']
>>> 
History
Date User Action Args
2008-02-20 17:18:01adminlinkissue1792881 messages
2008-02-20 17:18:01admincreate