(THIS CODING RULE OR GUIDELINE IS UNDER CONSTRUCTION)
According to [JNI Tips], section "Local and Global References", references in native code to the same object may have different values. Return values from the
NewGlobalRef() function when applied to the same object may differ from each other. Consequently, object references are not necessarily constant or unique. Object references should never be compared using == or
!= in native code. When testing for object equality, the
IsSameObject() function should be used instead of
Noncompliant Code Example
This noncompliant code example shows an example where it is assumed that an object reference is constant with erroneous results.
In this compliant solution, in native code, object references are tested for object equality using the
IsSameObject() function, and the object references tested are global references
If it is assumed that an object reference is constant or unique then erroneous results may be obtained that could lead to the app crashing. This, in turn, could be used to mount a denial-of-service attack.
Although it may be possible to automatically detect the use of == or != for comparing object references in native code, in general automatic detection of the wider issue is not feasible. [Is it?]