Skip to content

Commit 880679c

Browse files
committed
add a test for not leaking a foreign object's toString in various cases
1 parent 2a1db78 commit 880679c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_interop.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,34 @@ def test_java_imports():
339339
assert repr(ArrayList()) == "[]"
340340

341341
assert java.util.ArrayList == ArrayList
342+
343+
def test_foreign_object_does_not_leak_Javas_toString():
344+
try:
345+
from java.util import ArrayList
346+
except NotImplementedError as e:
347+
assert "host lookup is not allowed" in str(e)
348+
else:
349+
try:
350+
ArrayList(12, "12")
351+
except TypeError as e:
352+
assert "@" not in str(e) # the @ from Java's default toString
353+
354+
try:
355+
ArrayList(12, foo="12") # keywords are not supported
356+
except TypeError as e:
357+
assert "@" not in str(e) # the @ from Java's default toString
358+
359+
try:
360+
ArrayList.bar
361+
except AttributeError as e:
362+
assert "@" not in str(e) # the @ from Java's default toString
363+
364+
try:
365+
del ArrayList.bar
366+
except AttributeError as e:
367+
assert "@" not in str(e) # the @ from Java's default toString
368+
369+
try:
370+
del ArrayList.bar
371+
except AttributeError as e:
372+
assert "@" not in str(e) # the @ from Java's default toString

0 commit comments

Comments
 (0)