Skip to content

Array argument for Java Map's key lost its original memory address in binding method, during binding AAR. #1591

Open
@lin-zy1229

Description

@lin-zy1229

Steps to Reproduce

  1. Native android aar's method
private ConcurrentHashMap<byte[], Object> map = new ConcurrentHashMap();
Object getData(byte[] key) {
    return map.get(key);
}
void putData(byte[] data) {
    map.put(data, data);
}
  1. Xamarin android invoker method generated by binding generator
void GetData(byte[] p0) {
    ...
    IntPtr native_p0 = JNIEnv.NewArray (p0);
    JValue* __args = stackalloc JValue [1];
    __args [0] = new JValue (native_p0);
    JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_getData_arrayB, __args);
    ...
}
void PutData(byte[] p0) {
    ...
    IntPtr native_p0 = JNIEnv.NewArray (p0);
    JValue* __args = stackalloc JValue [1];
    __args [0] = new JValue (native_p0);
    JNIEnv.CallVoidMethod (((global::Java.Lang.Object) this).Handle, id_putData_arrayB, __args);
    ...
}
  1. When we use this Xamarin binded lib in code, it returns null always as follows.
byte[] data=new byte[]{1,2,3};
someObj.PutData(data);
var ans = someObj.GetData(data); // always returns null

Here, we know why someObj.GetData(data)returns null always.
It is because GetData(p0) doesn't use p0 itself as a key to get corresponding value, but it generates new address by IntPtr native_p0 = JNIEnv.NewArray (p0) and use it as a key.
So the Map variable couldn't find a proper key/value stored by the key (byte array pointer address) generated newly each time in calling someObj.GetData(data).

Hope you to fix this issue ASAP.

It should NOT return null in above code, and it SHOULD return byte[]{1,2,3} as corresponding value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: BindingsIssues in Java Library Binding projects.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions