You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Java.Interop] Normalize JniType.Name on JNI convention.
java.lang.Class.getName() is...weird, at least on Desktop Java:
it is NOT the JNI value; `java.lang.Object.class.getName()` returns
"java.lang.Object", i.e. "Java" convention.
Nested types are some bizarre combination of Java & JNI:
`java.lang.Thread.State.class.getName()` returns
"java.lang.Thread$State", i.e. `$` is used to separate nested types,
as is done in JNI.
This is why JniType.Name already replaces s#\.#/#g, resulting in JNI
convention ('java/lang/Object', 'java/lang/Thread$State').
...except for builtin types: `int.class.getName()` returns "int",
*not* "I", EVEN THOUGH `int[].class.getName()` is "[I".
Ditto other arrays; `Object[].class.getName()` is
"[Ljava.lang.Object;", because why the hell not?
In short, Class.getName() is *really weird* about which convention
it's using, using either Java, JNI, or bastardized mixing of the two.
Which makes it difficult to sanely use the result of JniType.Name in
any other context, e.g. to generate JNI method signatures, because you
never know what the value is.
Fix that: JniType.Name shall henceforth return a value in JNI
convention, including for bulitin types: add a typename mapping from
the Java builtin values (e.g. "int") to their corresponding JNI values
(e.g. "I"), so that JniType.Name for an `int` is "I".
A problem, testing-wise: `new JniType("I")` and `new JniType("int")`
fail, because JNIEnv::FindClass() refuses to do anything with
builtins. (JNI bug?)
Thus, in order to *test* that JniType.Name for an `int` is "I", we
first need to convince the JVM to give us a Class instance for `int`.
To do *that*, we use JNI to invoke Java Reflection to lookup
java.lang.Object.hashCode(), which returns an int. This allows us to
get Java's `int.class`, allowing us to call `int.class.getName()` and
ensure that it is sanely mapped to "I", not "int".
0 commit comments