Discussion:
via C++, determine if a java object is null
William Schilp
2017-07-24 18:03:49 UTC
Permalink
i'm using JCC to interface a C++ application to a java application. in the
java application a method can return a "null" java object. i need to
determine if the returned object is a null object. i do not see a way to do
this via the JCC interface. the object i get on the C++ side is an object
residing in memory space. so as far as C++ is concerned, the object is not
NULL as it points to a valid memory address, ie not 0.
so, how do i determine if the returned object is a null java object?

bill
Andi Vajda
2017-07-24 19:56:19 UTC
Permalink
Post by William Schilp
i'm using JCC to interface a C++ application to a java application. in the
java application a method can return a "null" java object. i need to
determine if the returned object is a null object. i do not see a way to do
this via the JCC interface. the object i get on the C++ side is an object
residing in memory space. so as far as C++ is concerned, the object is not
NULL as it points to a valid memory address, ie not 0.
so, how do i determine if the returned object is a null java object?
The java object is held by the 'jobject this$' member variable in the C++
wrapper. I think that if Java returned a null object, this$ is set to 0;

You might also be able to use the '!' operator declared on JObject:

inline int operator!() const
{
return env->isSame(this$, NULL);
}

if (!wrapper) // java returned null
...

Andi..
Post by William Schilp
bill
Loading...