Skip to content

Commit 8d493b2

Browse files
committed
1 parent 2df2101 commit 8d493b2

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

doc/CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Latest Changes:
1212

1313
- Fixed conversion of float16 for subnormal numbers.
1414

15+
- Fixed segmentation fault on null String.
16+
1517
- Fixed bugs with java.util.List concat and repeat methods.
1618

1719
- Enhancement to JProxy to handle wrapping an existing Python object with a Java

native/common/jp_javaframe.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,8 @@ class JPStringAccessor
10941094
string JPJavaFrame::toString(jobject o)
10951095
{
10961096
auto str = (jstring) CallObjectMethodA(o, getContext()->m_Object_ToStringID, nullptr);
1097+
if (str == nullptr)
1098+
return "null";
10971099
return toStringUTF8(str);
10981100
}
10991101

test/harness/jpype/str/Bad.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* ****************************************************************************
2+
Licensed under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License.
4+
You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
14+
See NOTICE file for details.
15+
**************************************************************************** */
16+
package jpype.str;
17+
18+
public class Bad
19+
{
20+
public String toString()
21+
{
22+
return null;
23+
}
24+
}

test/jpypetest/test_jstring.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,7 @@ def testSlice(self):
181181
self.assertEqual(s[:5], s2[:5])
182182
self.assertEqual(s[3:], s2[3:])
183183
self.assertEqual(s[::-1], s2[::-1])
184+
185+
def testBad(self):
186+
bad = jpype.JClass("jpype.str.Bad")()
187+
self.assertEqual(str(bad), "null")

0 commit comments

Comments
 (0)