[hal] Allocate CANStreamMessage in JNI if null (#6107)

This commit is contained in:
Thad House
2023-12-28 22:50:57 -08:00
committed by GitHub
parent 6a2d3c30a6
commit 9333951736
3 changed files with 17 additions and 2 deletions

View File

@@ -160,8 +160,15 @@ Java_edu_wpi_first_hal_can_CANJNI_readCANStreamSession
JLocal<jobject> elem{
env, static_cast<jstring>(env->GetObjectArrayElement(messages, i))};
if (!elem) {
// TODO decide if should throw
continue;
// If element doesn't exist, construct it in place. If that fails, we are
// OOM, just return
elem = JLocal<jobject>{env, CreateCANStreamMessage(env)};
if (elem) {
std::printf("Allocated and set object\n");
env->SetObjectArrayElement(messages, i, elem);
} else {
return 0;
}
}
JLocal<jbyteArray> toSetArray{
env, SetCANStreamObject(env, elem, msg->dataSize, msg->messageID,