Skip to content

Commit 07a42e5

Browse files
committed
Update PyjObject.callMethod -> UNDEFINED_RESULT
1 parent 459ea27 commit 07a42e5

File tree

1 file changed

+11
-8
lines changed
  • common/src/main/resources/system/lib

1 file changed

+11
-8
lines changed

common/src/main/resources/system/lib/java.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def _find_java_member(clss, name: str):
149149

150150
with script_loop:
151151
Object_id = _find_java_class("java.lang.Object")
152+
Object_equals_id = _find_java_member(Object_id, "equals")
152153
Object_getClass_id = _find_java_member(Object_id, "getClass")
153154

154155
Objects_id = _find_java_class("java.util.Objects")
@@ -176,10 +177,6 @@ def _find_java_member(clss, name: str):
176177
Float_id = _find_java_class("java.lang.Float")
177178
Double_id = _find_java_class("java.lang.Double")
178179

179-
Array_id = _find_java_class("java.lang.reflect.Array")
180-
Array_get_id = _find_java_member(Array_id, "get")
181-
Array_getLength_id = _find_java_member(Array_id, "getLength")
182-
183180
Iterable_id = _find_java_class("java.lang.Iterable")
184181

185182
Collection_id = _find_java_class("java.util.Collection")
@@ -191,6 +188,7 @@ def _find_java_member(clss, name: str):
191188
PyjObject_callMethod_id = _find_java_member(PyjObject_id, "callMethod")
192189
PyjObject_class_id = _find_java_member(PyjObject_id, "__class__")
193190
PyjObject_dict_id = _find_java_member(PyjObject_id, "__dict__")
191+
PyjObject_UNDEFINED_RESULT_id = _find_java_member(PyjObject_id, "UNDEFINED_RESULT")
194192
PyjClass_id = _find_java_class("org.pyjinn.interpreter.Script$PyjClass")
195193
PyjClass_name_id = _find_java_member(PyjClass_id, "name")
196194
PyjDict_id = _find_java_class("org.pyjinn.interpreter.Script$PyjDict")
@@ -208,6 +206,8 @@ def _find_java_member(clss, name: str):
208206
KeywordArgs_ctor_id = java_ctor(KeywordArgs_id)
209207
KeywordArgs_put_id = _find_java_member(KeywordArgs_id, "put")
210208

209+
UNDEFINED_RESULT = java_access_field(_null_id, PyjObject_UNDEFINED_RESULT_id)
210+
211211
@dataclass
212212
class Float:
213213
"""Wrapper class for mirroring Java `float` in Python.
@@ -384,16 +384,19 @@ def call_pyjinn_method(*args):
384384
# no matching method:
385385
# Object[] callMethod(Environment env, String methodName, Object... params)
386386
params = create_java_object_array(args)
387-
result = auto(java_call_method(
387+
result = java_call_method(
388388
self.id,
389389
PyjObject_callMethod_id,
390390
self.script_env,
391391
auto(java_string(name)),
392-
params.id))
393-
if from_java_handle(java_call_method(_null_id, Array_getLength_id, result)) > 0:
394-
return from_java_handle(java_call_method(_null_id, Array_get_id, result, auto(java_int(0))))
392+
params.id)
393+
# Call as UNDEFINED_RESULT.equals(result) because UNDEFINED_RESULT is not null but result
394+
# may be null.
395+
if not from_java_handle(java_call_method(UNDEFINED_RESULT, Object_equals_id, result)):
396+
return from_java_handle(result)
395397
else:
396398
# No dynamic PyjObject method found, so fall back to compiled Java method call.
399+
java_release(result)
397400
binding = JavaBoundMember(
398401
self.get_class_id(), self.id, name, ref=self.ref, script_env=self.script_env)
399402
return binding(*args)

0 commit comments

Comments
 (0)