Skip to content
Permalink
Browse files

Fix bug reported on null array slices.

  • Loading branch information...
Thrameos committed Jun 28, 2019
1 parent 5f2b85f commit 9000f283f2c7eb4c7b85b0064c0203a63ad01a74
Showing with 14 additions and 2 deletions.
  1. +3 −0 doc/CHANGELOG.rst
  2. +6 −2 native/common/jp_class.cpp
  3. +5 −0 test/jpypetest/test_array.py
@@ -4,6 +4,9 @@ Changelog
This changelog *only* contains changes from the *first* pypi release (0.5.4.3) onwards.

- **Next version - unreleased**

- Corrected segfault when converting null elements while accessing a slice
from a Java object array.

- **0.7.0 - 2019**
- Doc strings are generated for classes and methods.
@@ -201,6 +201,7 @@ void JPClass::setField(JPJavaFrame& frame, jobject c, jfieldID fid, PyObject* ob

JPPyObject JPClass::getArrayRange(JPJavaFrame& frame, jarray a, jsize start, jsize length)
{
JP_TRACE_IN("JPClass::getArrayRange");
jobjectArray array = (jobjectArray) a;

JPPyTuple res(JPPyTuple::newTuple(length));
@@ -209,11 +210,14 @@ JPPyObject JPClass::getArrayRange(JPJavaFrame& frame, jarray a, jsize start, jsi
for (int i = 0; i < length; i++)
{
v.l = frame.GetObjectArrayElement(array, i + start);
JPClass* t = JPTypeManager::findClassForObject(v.l);
res.setItem(i, t->convertToPythonObject(v).get());
JPClass* type = this;
if (v.l != NULL)
type = JPTypeManager::findClassForObject(v.l);
res.setItem(i, type->convertToPythonObject(v).get());
}

return res;
JP_TRACE_OUT;
}

void JPClass::setArrayRange(JPJavaFrame& frame, jarray a, jsize start, jsize length, PyObject* vals)
@@ -389,3 +389,8 @@ def testArrayClone(self):
self.assertFalse(array.equals(carray))
# Copy is shallow
self.assertTrue(array[0].equals(carray[0]))

def testObjectNullArraySlice(self):
# Check for bug in 0.7.0
array = jpype.JArray(jpype.JObject)([None,])
self.assertEqual(array[:], (None,))

0 comments on commit 9000f28

Please sign in to comment.
You can’t perform that action at this time.