Skip to content

Commit 4c749ba

Browse files
committed
[[ Bug 22619 ]] Fix crash where listener param is null
This patch fixes an issue where if a listener method is called where one of the parameters is `null` a crash would occur. `__MCJavaProperListFromJObjectArray` is currently only called from `MCJavaPrivateDoNativeListenerCallback` where the `JObjectArray` is the function args.
1 parent 57500b0 commit 4c749ba

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

docs/lcb/notes/22619.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# LiveCode Builder Language
2+
## Android Listener support
3+
4+
# [19973] A `null` listener parameter no longer causes a crash.

libfoundation/src/foundation-java-private.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,20 @@ static bool __MCJavaProperListFromJObjectArray(jobjectArray p_obj_array, MCPrope
517517
MCJavaAutoLocalRef<jobject> t_object =
518518
s_env -> GetObjectArrayElement(p_obj_array, i);
519519

520-
MCAutoJavaObjectRef t_obj;
521-
if (!MCJavaObjectCreate(t_object, &t_obj))
522-
return false;
520+
if (t_object != nullptr)
521+
{
522+
MCAutoJavaObjectRef t_obj;
523+
if (!MCJavaObjectCreate(t_object, &t_obj))
524+
return false;
523525

524-
if (!MCProperListPushElementOntoBack(*t_list, *t_obj))
525-
return false;
526+
if (!MCProperListPushElementOntoBack(*t_list, *t_obj))
527+
return false;
528+
}
529+
else
530+
{
531+
if (!MCProperListPushElementOntoBack(*t_list, kMCNull))
532+
return false;
533+
}
526534
}
527535

528536
return MCProperListCopy(*t_list, r_list);

0 commit comments

Comments
 (0)