mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[hal] Properly error check readCANStreamSession (#6108)
This commit is contained in:
@@ -135,6 +135,17 @@ Java_edu_wpi_first_hal_can_CANJNI_readCANStreamSession
|
||||
(JNIEnv* env, jclass, jint sessionHandle, jobjectArray messages,
|
||||
jint messagesToRead)
|
||||
{
|
||||
if (messages == nullptr) {
|
||||
ThrowNullPointerException(env, "messages cannot be null");
|
||||
return 0;
|
||||
}
|
||||
|
||||
jsize messagesArrayLen = env->GetArrayLength(messages);
|
||||
|
||||
if (messagesArrayLen < messagesToRead) {
|
||||
messagesToRead = messagesArrayLen;
|
||||
}
|
||||
|
||||
uint32_t handle = static_cast<uint32_t>(sessionHandle);
|
||||
uint32_t messagesRead = 0;
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ static JException canMessageNotFoundExCls;
|
||||
static JException canMessageNotAllowedExCls;
|
||||
static JException canNotInitializedExCls;
|
||||
static JException uncleanStatusExCls;
|
||||
static JException nullPointerEx;
|
||||
static JClass powerDistributionVersionCls;
|
||||
static JClass pwmConfigDataResultCls;
|
||||
static JClass canStatusCls;
|
||||
@@ -85,7 +86,8 @@ static const JExceptionInit exceptions[] = {
|
||||
&canMessageNotAllowedExCls},
|
||||
{"edu/wpi/first/hal/can/CANNotInitializedException",
|
||||
&canNotInitializedExCls},
|
||||
{"edu/wpi/first/hal/util/UncleanStatusException", &uncleanStatusExCls}};
|
||||
{"edu/wpi/first/hal/util/UncleanStatusException", &uncleanStatusExCls},
|
||||
{"java/lang/NullPointerException", &nullPointerEx}};
|
||||
|
||||
namespace hal {
|
||||
|
||||
@@ -212,6 +214,10 @@ void ReportCANError(JNIEnv* env, int32_t status, int message_id) {
|
||||
}
|
||||
}
|
||||
|
||||
void ThrowNullPointerException(JNIEnv* env, std::string_view msg) {
|
||||
nullPointerEx.Throw(env, msg);
|
||||
}
|
||||
|
||||
void ThrowCANStreamOverflowException(JNIEnv* env, jobjectArray messages,
|
||||
jint length) {
|
||||
static jmethodID constructor =
|
||||
|
||||
@@ -51,6 +51,7 @@ inline bool CheckCANStatus(JNIEnv* env, int32_t status, int32_t message_id) {
|
||||
return status == 0;
|
||||
}
|
||||
|
||||
void ThrowNullPointerException(JNIEnv* env, std::string_view msg);
|
||||
void ThrowCANStreamOverflowException(JNIEnv* env, jobjectArray messages,
|
||||
jint length);
|
||||
void ThrowIllegalArgumentException(JNIEnv* env, std::string_view msg);
|
||||
|
||||
Reference in New Issue
Block a user