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

Issue:
memoryview(direct ByteBuffer) has incorrect nbytes field
There appears to be a bug in the nbytes on some systems when using direct byte buffer.  This prevents them from being used with io.readinto

Bug replication
```
>>> import jpype
>>> import jpype.imports
>>> jpype.startJVM()
>>> from java.nio import ByteBuffer
>>> memoryview(ByteBuffer.allocateDirect(100)).nbytes
25096256
```


Discussion / hints:

Fix patch:
diff --git a/doc/CHANGELOG.rst b/doc/CHANGELOG.rst
index 12e6ded85..b41895c87 100644
--- a/doc/CHANGELOG.rst
+++ b/doc/CHANGELOG.rst
@@ -5,6 +5,9 @@ This changelog *only* contains changes from the *first* pypi release (0.5.4.3) o
 
 Latest Changes:
 - **1.4.2_dev0 - 2022-10-26**
+
+  - Fixed direct byte buffers not reporting nbytes correctly when cast to memoryview.
+
 - **1.4.1 - 2022-10-26**
   
   - Fixed issue with startJVM changing locale settings.
diff --git a/native/common/jp_buffer.cpp b/native/common/jp_buffer.cpp
index 019f03eb0..208227787 100644
--- a/native/common/jp_buffer.cpp
+++ b/native/common/jp_buffer.cpp
@@ -38,6 +38,7 @@ JPBuffer::JPBuffer(const JPValue &value)
 	m_Buffer.shape = &m_Capacity;
 	m_Buffer.strides = &m_Buffer.itemsize;
 	m_Buffer.suboffsets = 0;
+	m_Buffer.len = m_Buffer.itemsize * m_Capacity;
 	JP_TRACE_OUT;  // GCOVR_EXCL_LINE
 }
 


Test patch:
diff --git a/test/jpypetest/test_bytebuffer.py b/test/jpypetest/test_bytebuffer.py
index b9f27ec95..b4c7e4757 100644
--- a/test/jpypetest/test_bytebuffer.py
+++ b/test/jpypetest/test_bytebuffer.py
@@ -46,3 +46,6 @@ def testRepr(self):
         bb = jpype.nio.convertToDirectBuffer(a)
         self.assertIsInstance(repr(bb), str)
         self.assertEqual(repr(bb), "<java buffer 'java.nio.DirectByteBuffer'>")
+
+    def testMemoryView(self):
+        self.assertEquals(memoryview(jpype.java.nio.ByteBuffer.allocateDirect(100)).nbytes, 100)