Repository: jpype-project/jpype (language: python)

Issue:
Crash on array operations
The following code was found to crash jpype version 1.2.1 under linux with open JDK 11.   It is not clear if it is simply memory exhaustion, a reference counting issue, or a memory overrun in an array operation.  The error log indicates some type of garbage collection issue.

```
import jpype
import numpy as np

jpype.startJVM()

gamma = jpype.JDouble[:](np.array(range(0,256)))
for i in range(100000):
    gamma2 = jpype.JDouble[512]
    gamma2[0:256] = gamma
    gamma2[256:] = 0.5*np.array(gamma)
```


Discussion / hints:
That seems somehow related to 32 bits architectures e.g. i686 and armv7hl but no idea why.

Fix patch:
diff --git a/.azure/build.yml b/.azure/build.yml
index b7403f51d..374edb661 100644
--- a/.azure/build.yml
+++ b/.azure/build.yml
@@ -84,6 +84,7 @@ jobs:
       mac-3.9:
         imageName: "macos-10.14"
         python.version: '3.9'
+        jpypetest.fast: 'true'
 
   pool:
     vmImage: $(imageName)
diff --git a/doc/CHANGELOG.rst b/doc/CHANGELOG.rst
index 869143ee4..61a130c75 100644
--- a/doc/CHANGELOG.rst
+++ b/doc/CHANGELOG.rst
@@ -5,6 +5,10 @@ This changelog *only* contains changes from the *first* pypi release (0.5.4.3) o
 
 Latest Changes:
 - **1.2.2_dev0 - 2021-01-03**
+  
+  - Fixed a bug with arrays created using the short cut.  The wrong type
+    was being returned.
+
 - **1.2.1 - 2021-01-02**
 
   - Missing stub files added.
diff --git a/native/python/pyjp_class.cpp b/native/python/pyjp_class.cpp
index b589311e8..c69950431 100644
--- a/native/python/pyjp_class.cpp
+++ b/native/python/pyjp_class.cpp
@@ -712,10 +712,9 @@ static PyObject *PyJPClass_array(PyJPClass *self, PyObject *item)
 	if (PyIndex_Check(item))
 	{
 		long sz = PyLong_AsLong(item);
-		JPClass *cls = self->m_Class->newArrayType(frame, 1);
-		jvalue v;
-		v.l = (jobject) cls->newArrayOf(frame, sz);
-		return cls->convertToPythonObject(frame, v, true).keep();
+		JPArrayClass *cls = (JPArrayClass*) self->m_Class->newArrayType(frame, 1);
+		JPValue v = cls->newArray(frame, sz);
+		return cls->convertToPythonObject(frame, v.getValue(), true).keep();
 	}
 
 	if (PySlice_Check(item))


Test patch:
diff --git a/test/jpypetest/test_array.py b/test/jpypetest/test_array.py
index 4bb881237..1f35461d0 100644
--- a/test/jpypetest/test_array.py
+++ b/test/jpypetest/test_array.py
@@ -575,3 +575,25 @@ def testZeroArray(self):
     def testLengthProperty(self):
         ja = JArray(JInt)([1, 2, 3])
         self.assertEqual(ja.length, len(ja))
+
+    def testShortcut(self):
+        # Test for odd bug introduced in 1.0.0
+        # This is unlikely to be reintroduced, but we can check anyway.
+        # The class of when created using the shortcut should always match the type created using the old method
+
+        # Check primitives
+        self.assertEqual(JBoolean[5].getClass(), JArray(JBoolean)(5).getClass())
+        self.assertEqual(JChar[5].getClass(), JArray(JChar)(5).getClass())
+        self.assertEqual(JByte[5].getClass(), JArray(JByte)(5).getClass())
+        self.assertEqual(JShort[5].getClass(), JArray(JShort)(5).getClass())
+        self.assertEqual(JInt[5].getClass(), JArray(JInt)(5).getClass())
+        self.assertEqual(JFloat[5].getClass(), JArray(JFloat)(5).getClass())
+        self.assertEqual(JDouble[5].getClass(), JArray(JDouble)(5).getClass())
+
+        # Check Objects
+        self.assertEqual(JString[5].getClass(), JArray(JString)(5).getClass())
+        self.assertEqual(JObject[5].getClass(), JArray(JObject)(5).getClass())
+
+        # Test multidimensional
+        self.assertEqual(JDouble[5, 5].getClass(), JArray(JDouble, 2)(5).getClass())
+        self.assertEqual(JObject[5, 5].getClass(), JArray(JObject, 2)(5).getClass())