Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

JNI local-reference accumulation in the string array helpers

Đang mở
#1,256 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
cpp, java
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu bằng cách đọc ToStringVector trong dataset/src/main/cpp/jni_util.cc và ToStringMap cùng LoadNamedTables trong dataset/src/main/cpp/jni_wrapper.cc, tập trung vào từng lệnh gọi GetObjectArrayElement. Đảm bảo mọi tham chiếu cục bộ được nhận đều bị xóa trên các đường dẫn thông thường và các đường dẫn JniThrow(); hoàn tất nghĩa là không còn tham chiếu nào của lần lặp hiện tại bị bỏ lại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Type: bug
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.cc
  • dataset/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().

Ngôn ngữ chính
Java
Star
95
Fork
154
Merge trung bình
2 ngày 10 giờ
Pull request đã merge (30 ngày)
11

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/arrow-java

Tất cả issue của apache/arrow-java

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.