JNI local-reference accumulation in the string array helpers
还没有人认领这个 Issue。
评估
调研方向
首先阅读 dataset/src/main/cpp/jni_util.cc 中的 ToStringVector,以及 dataset/src/main/cpp/jni_wrapper.cc 中的 ToStringMap 和 LoadNamedTables,重点检查每个 GetObjectArrayElement 调用。确保每个获取的局部引用都在正常路径和 JniThrow() 路径上被删除;完成的标准是当前迭代不再有任何被遗弃的引用。
由索引模型根据 Issue 内容生成。
描述
Describe the bug, including details regarding any error messages, version, and platform.
There is a JNI local-reference issue in the dataset helpers that convert Java String[] arrays into C++ containers. They get each element with GetObjectArrayElement() and convert it, but never delete the resulting local reference.
Files:
dataset/src/main/cpp/jni_util.ccdataset/src/main/cpp/jni_wrapper.cc
Functions:
ToStringVector(jni_util.cc)ToStringMap,LoadNamedTables(jni_wrapper.cc)
Relevant code in ToStringVector():
std::vector<std::string> ToStringVector(JNIEnv* env, jobjectArray& str_array) {
int length = env->GetArrayLength(str_array);
std::vector<std::string> vector;
for (int i = 0; i < length; i++) {
auto string = reinterpret_cast<jstring>(env->GetObjectArrayElement(str_array, i));
vector.push_back(JStringToCString(env, string));
}
return vector;
}
JStringToCString() does correctly release the native UTF chars it acquires:
const char* chars = env->GetStringUTFChars(string, nullptr);
std::string ret(chars);
env->ReleaseStringUTFChars(string, chars);
return ret;
but that release only matches GetStringUTFChars(). It does not delete the jstring local reference that GetObjectArrayElement() returned, so one reference remains live per element until the native method returns.
ToStringMap() has the same pattern with two references per iteration:
for (int i = 0; i < length; i += 2) {
auto key = reinterpret_cast<jstring>(env->GetObjectArrayElement(str_array, i));
auto value = reinterpret_cast<jstring>(env->GetObjectArrayElement(str_array, i + 1));
map[JStringToCString(env, key)] = JStringToCString(env, value);
}
LoadNamedTables() also takes two per iteration, and has three JniThrow() exits inside the loop body — the odd-length check and the two std::stol failure handlers — so on those paths the references acquired in the current iteration are abandoned mid-loop.
These are local references, so they are reclaimed when the native method returns, and the inputs are option maps, partition columns, and named-table lists — typically tens of entries. There is no observable leak or reachable failure here; the reference count is simply higher than necessary for the duration of the call.
Suggested fix:
auto string = reinterpret_cast<jstring>(env->GetObjectArrayElement(str_array, i));
vector.push_back(JStringToCString(env, string));
env->DeleteLocalRef(string);
For the key/value loops, delete both key and value, including on the JniThrow() paths in LoadNamedTables().
- 主要语言
- Java
- 星标
- 95
- 派生
- 154
- 平均合并
- 2 天 10 小时
- 30 天内合并 PR
- 11
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/arrow-java 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
apache/arrow-java#1261 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
apache/arrow-java#1236 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
apache/arrow-java#1230 ·
-
Type: bug
难度 2/5 1-3 小时 新手友好度 85/100
apache/arrow-java#1205 ·
-
Type: bug
难度 2/5 1-3 小时 新手友好度 68/100
apache/arrow-java#1196 · 1 条评论 ·
查看 apache/arrow-java 的全部 Issue
相似的 Issue
-
bug untriaged
难度 2/5 1-3 小时 新手友好度 84/100
opensearch-project/ml-commons#5094 ·
-
bug
难度 2/5 1-3 小时 新手友好度 85/100
-
emitter:client:csharp feature
难度 2/5 1-3 小时 新手友好度 72/100
-
affects/8.10 affects/8.9 component/clients kind/bug likelihood/mid severity/mid
难度 2/5 1-3 小时 新手友好度 78/100
-
bug frontend maui-pilot
难度 2/5 1-3 小时 新手友好度 72/100