Cannot pass String as JNI jstring parameter
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu bằng cách theo dõi quá trình chuyển đổi đối số của Function thông qua convertArgument(), đặc biệt là cách xử lý String, OPTION_ALLOW_OBJECTS và JniEnv.CURRENT. Xác minh cách một Java String hiện được chuyển đổi trước khi gọi và xác định liệu các đối tượng jstring có thể được truyền qua mà không làm hỏng các chuyển đổi dành riêng cho JNA hay không. Được xem là hoàn tất khi lệnh gọi JVM_FindLoadedClass được báo cáo có thể nhận một Java String dưới dạng jstring, với độ bao phủ cho hành vi chuyển đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
-
Version of JNA and related jars
JNA 5.3.1 -
Version and vendor of the java virtual machine
Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 1.8.0_181 -
Operating system
Ubuntu 16.04.6 -
System architecture (CPU type, bitness of the JVM)
Intel x64, x64 JVM -
Complete description of the problem
I cannot passStringobjects to a JNI method for invocation, (even using JniEnv.CURRENT and setting OPTION_ALLOW_OBJECTS), since aStringis always converted toNativeString.When trying to call JNI methods, JNA invokes
convertArgument()just before C method invocation, andStringis converted toNativeStringbeforeallowObjectsis checked. This means that it is impossible to pass the JavaString(jstring) object to C (which acceptsjstringas a parameter type). For example, JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name); -
Steps to reproduce
public
interface JVM extends com.sun.jna.Library {
Class JVM_FindLoadedClass(JNIEnv env, Object classLoader, String name);
}
Map options = new HashMap();
options.put(Library.OPTION_ALLOW_OBJECTS, Boolean.TRUE);
JVM libjvm = Native.load("jvm", JVM.class, options);
jvm.JVM_FindLoadedClass(JNIEnv.CURRENT, classLoader, className);
It is entirely likely that I don't know what I'm doing, after reading through the documentation and studying the source -- I do not know how to pass a String as a jstring object (not a char* object) to native code. I've tried type converters, but those didn't get me anywhere, since String is always converted to NativeString as an argument...
Because the Function constructor is package scope, as is invoke, I cannot overload invoke to not convert arguments, so I am unable to modify the method invocation (outside of rewriting the class definition at runtime via javassist or something similar)
One solution I thought of, while trying to figure this out, is modify the convertArgument() method so that the check for allowObjects occurs sooner, allowing all Java objects to passed without conversion -- so the check for allowObjects is after JNA specific object types (struct, etc), but before the Java object type conversion (mostly string), instead of where currently is (which is last)....
NOTE: Loading the JVM library for Windows 32 bit, or MACOS is slightly different. The above only loads it on Linux, specifically Ubuntu 16.04.6 x64 with an Oracle JVM (from my testing, this is currently true for all released Oracle JVM's on Linux, but I haven't tested every combination....)
- Ngôn ngữ chính
- Java
- Star
- 8.9k
- Fork
- 1.7k
- Merge trung bình
- 1 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của java-native-access/jna
-
`Native.typeOptions` never releases library interfaces, leaking classloadersCó thể đã có người làm @curforever đã nhận 5 ngày trước. Đang mở
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 48/100
java-native-access/jna#1742 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 66/100
java-native-access/jna#1738 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
java-native-access/jna#1736 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
java-native-access/jna#1717 ·
-
Windows32Exception - The parameter is incorrectCó thể đã có người làm @marktech0813 đã nhận 341 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
java-native-access/jna#1700 · 11 bình luận ·
Tất cả issue của java-native-access/jna
Issue tương tự
-
enhancement Improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
zowe/zowe-client-java-sdk#647 ·
-
NullPointerException when a `DeserializationProblemHandler` returns `null` for `byte[]` (single value unwrapped) and `char[]` elementsCó thể đã có người làm @Marti2203 đã nhận hôm nay. Đang mở
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 88/100
FasterXML/jackson-databind#6300 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
content good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
cpinitiative/usaco-guide#6699 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
BC remittance upload: a claim MSP refused (S03) is saved with a blank status instead of refused (F)Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởtype: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
carlos-emr/carlos#4933 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[studio] Data source connection tests leak loading and results across modal sessionsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
apache/rocketmq-dashboard#6925 ·
Maintainer thường phản hồi trong vòng 3 ngày