JNI - accessing primitive Arrays and null values

D

Dzikus

Hello,
Suppose I have native function
private native int sumArray(int[] arr);

How should I behave in C implementation if someone calls this function
with null value as an argument?
sumArray(null);

My first implementation was:
....(JNIEnv *env, ..., jintArray data)
{
jint *carr;
carr = (*env)->GetIntArrayElements(env, carr, 0);
if((*env)->GetArrayLength(env, carr) == 0)
{
//empty array or null?
}
....
It works on Linux but crasches on WIN :(

I have changed code to:
....(JNIEnv *env, ..., jintArray data)
{
jint *carr;
if(data == 0)
{
//null
}
....
It works but I'm not sure if this solution is ok. I haven't found eny
examples how to deal with such null values ...


Thanks in advance
Dominik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top