Skip to content

Commit d891115

Browse files
committed
[GR-46267] Test and fix invocation of Java proxies when they communicate an argument error via UnsupportedOperationException
PullRequest: graalpython/2790
2 parents eab3541 + a2ecc9f commit d891115

File tree

2 files changed

+53
-2
lines changed
  • graalpython

2 files changed

+53
-2
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/interop/JavaInteropTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.io.IOException;
5151
import java.io.UnsupportedEncodingException;
5252
import java.util.Arrays;
53+
import java.util.HashMap;
5354
import java.util.Map;
5455

5556
import org.graalvm.polyglot.Context;
@@ -60,9 +61,12 @@
6061
import org.graalvm.polyglot.Value;
6162
import org.graalvm.polyglot.proxy.ProxyArray;
6263
import org.graalvm.polyglot.proxy.ProxyHashMap;
64+
import org.graalvm.polyglot.proxy.ProxyExecutable;
65+
import org.graalvm.polyglot.proxy.ProxyObject;
6366
import org.junit.After;
6467
import org.junit.Before;
6568
import org.junit.Test;
69+
import org.junit.Ignore;
6670
import org.junit.experimental.runners.Enclosed;
6771
import org.junit.runner.RunWith;
6872
import org.junit.runners.Parameterized;
@@ -324,6 +328,53 @@ public void accessSuitePy() throws IOException {
324328
assertEquals("'e39957904b7e79caf4fa54f30e8e4ee74d4e9e37'", dacapo.getHashValue("sha1").toString());
325329
}
326330

331+
public class AForeignExecutable implements ProxyExecutable {
332+
@Override
333+
public Object execute(Value... arguments) {
334+
throw new UnsupportedOperationException("wrong arity");
335+
}
336+
}
337+
338+
@Ignore // blocked by GR-46281
339+
@Test
340+
public void runAForeignExecutable() throws IOException {
341+
Source suitePy = Source.newBuilder("python",
342+
"""
343+
def foo(obj):
344+
try:
345+
obj()
346+
except TypeError as e:
347+
pass
348+
else:
349+
assert False
350+
foo
351+
""",
352+
"suite.py").build();
353+
Value foo = context.eval(suitePy);
354+
foo.execute(new AForeignExecutable());
355+
}
356+
357+
@Ignore // blocked by GR-46281
358+
@Test
359+
public void invokeAForeignMember() throws IOException {
360+
Source suitePy = Source.newBuilder("python",
361+
"""
362+
def foo(obj):
363+
try:
364+
obj.fun()
365+
except TypeError as e:
366+
pass
367+
else:
368+
assert False
369+
foo
370+
""",
371+
"suite.py").build();
372+
Map<String, Object> m = new HashMap<>();
373+
m.put("fun", new AForeignExecutable());
374+
Value foo = context.eval(suitePy);
375+
foo.execute(ProxyObject.fromMap(m));
376+
}
377+
327378
@ExportLibrary(InteropLibrary.class)
328379
public static class ForeignObjectWithOOInvoke implements TruffleObject {
329380
public String getMyName() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ protected Object doForeignMethod(ForeignMethod callable, Object[] arguments, PKe
193193
gil.release(true);
194194
try {
195195
return fromForeign.executeConvert(interop.invokeMember(callable.receiver, callable.methodName, arguments));
196-
} catch (ArityException | UnsupportedTypeException e) {
196+
} catch (ArityException | UnsupportedTypeException | UnsupportedMessageException e) {
197197
typeError.enter(inliningTarget);
198198
throw raise.raise(TypeError, e);
199-
} catch (UnknownIdentifierException | UnsupportedMessageException e) {
199+
} catch (UnknownIdentifierException e) {
200200
// PyObjectGetMethod is supposed to have checked isMemberInvocable
201201
throw CompilerDirectives.shouldNotReachHere("Cannot invoke member");
202202
} finally {

0 commit comments

Comments
 (0)