Skip to content

Commit 5ef4b66

Browse files
committed
[Java.Interop.Dynamic] Use JniTypeSignature.Name for JniType.
While running the Java.Interop.Dynamic unit tests, the JDK was issuing a WARNING: $ make run-tests TESTS=bin/Debug/Java.Interop.Dynamic-Tests.dll ... WARNING in native method: JNI FindClass received a bad class descriptor "Ljava/lang/Integer;". A correct class descriptor has no leading "L" or trailing ";". Incorrect descriptors will not be accepted in future releases. The source of the warning was due to JavaClassInfo.GetJniTypes(), which was passing the result of JniTypeSignature.QualifiedReference to the JniType constructor: // WRONG var sig = JniRuntime.CurrentRuntime.TypeManager.GetTypeSignature (a.LimitType); var type = new JniType (sig.QualifiedReference); This is WRONG, because JniTypeSignature.QualifiedReference *always* provides the "full" type, e.g. `Ljava/lang/Integer;`. As per the JDK warning, this isn't correct. Instead, JavaClassInfo.GetJniTypes() should instead use JniTypeSignature.Name, e.g. `java/lang/Integer`, which provides the correct value for the JniType constructor: // RIGHT var sig = JniRuntime.CurrentRuntime.TypeManager.GetTypeSignature (a.LimitType); var type = new JniType (sig.Name); I wonder if this means there should be a JniTypeSignature.CreateType() method which creates the JniType instance... Fixing JavaClassInfo.GetJniTypes() removes the JDK warning. Further inspection of all uses of JniTypeSignature.QualifiedReference found JavaMethodBase.CompatibleWith(), which compares the result of JniEnvironment.Types.GetJniTypeNameFromClass() to JnITypeSignature.QualifiedReference, which doens't make sense as the former is really java.lang.Class.getName(), which is really JniTypeSignature.Name, not .QualifiedReference. Fix that.
1 parent dda3904 commit 5ef4b66

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/Java.Interop.Dynamic/Java.Interop.Dynamic/JavaClassInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static List<JniType> GetJniTypes (DynamicMetaObject[] args)
330330
var vm = JniEnvironment.Runtime;
331331
foreach (var a in args) {
332332
try {
333-
var at = new JniType (vm.TypeManager.GetTypeSignature (a.LimitType).QualifiedReference);
333+
var at = new JniType (vm.TypeManager.GetTypeSignature (a.LimitType).Name);
334334
r.Add (at);
335335
} catch (JavaException e) {
336336
e.Dispose ();

src/Java.Interop.Dynamic/Java.Interop.Dynamic/JavaMethodBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public bool CompatibleWith (List<JniType> args, DynamicMetaObject[] dargs)
118118
for (int i = 0; i < arguments.Count; ++i) {
119119
if (args [i] == null) {
120120
// Builtin type -- JNIEnv.FindClass("I") throws!
121-
if (JniEnvironment.Types.GetJniTypeNameFromClass (arguments [i]) != vm.TypeManager.GetTypeSignature (dargs [i].LimitType).QualifiedReference)
121+
if (JniEnvironment.Types.GetJniTypeNameFromClass (arguments [i]) != vm.TypeManager.GetTypeSignature (dargs [i].LimitType).Name)
122122
return false;
123123
}
124124
else if (!JniEnvironment.Types.IsAssignableFrom (arguments [i], args [i].PeerReference))

0 commit comments

Comments
 (0)