Cannot pass String as JNI jstring parameter
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Empieza siguiendo la conversión de argumentos de Function mediante convertArgument(), especialmente el tratamiento de String, OPTION_ALLOW_OBJECTS y JniEnv.CURRENT. Verifica cómo se convierte actualmente un Java String antes de la invocación y determina si los objetos jstring pueden pasar sin romper las conversiones específicas de JNA. Se considera terminado cuando la llamada JVM_FindLoadedClass indicada puede recibir un Java String como jstring, con cobertura para el comportamiento de conversión.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
-
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....)
- Lenguaje dominante
- Java
- Estrellas
- 8.9k
- Forks
- 1.7k
- Merge medio
- 1 d 13 h
- PR fusionados (30 d)
- 1
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de java-native-access/jna
-
`Native.typeOptions` never releases library interfaces, leaking classloadersPosiblemente ocupada @curforever la tomó hace 5 días. Abierto
Dificultad 4/5 1-2 días Aptitud para principiantes 48/100
java-native-access/jna#1742 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 66/100
java-native-access/jna#1738 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
java-native-access/jna#1736 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
java-native-access/jna#1717 ·
-
Windows32Exception - The parameter is incorrectPosiblemente ocupada @marktech0813 la tomó hace 341 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
java-native-access/jna#1700 · 11 comentarios ·
Todos los issues de java-native-access/jna
Issues similares
-
NullPointerException when a `DeserializationProblemHandler` returns `null` for `byte[]` (single value unwrapped) and `char[]` elementsPosiblemente ocupada @Marti2203 la tomó hoy. Abierto
Dificultad 2/5 Medio día Aptitud para principiantes 88/100
FasterXML/jackson-databind#6300 ·
Los mantenedores suelen responder en 1 día
-
content good first issue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
cpinitiative/usaco-guide#6699 ·
Los mantenedores suelen responder en 1 día
-
BC remittance upload: a claim MSP refused (S03) is saved with a blank status instead of refused (F)Abiertotype: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
carlos-emr/carlos#4933 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
apache/rocketmq-dashboard#6925 ·
Los mantenedores suelen responder en 3 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Vakore/ZappierGames#147 ·