Skip to content

Commit

Permalink
[Java.Interop.Dynamic] Use JniTypeSignature.Name for JniType.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonpryor committed Dec 9, 2015
1 parent dda3904 commit 5ef4b66
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ static List<JniType> GetJniTypes (DynamicMetaObject[] args)
var vm = JniEnvironment.Runtime;
foreach (var a in args) {
try {
var at = new JniType (vm.TypeManager.GetTypeSignature (a.LimitType).QualifiedReference);
var at = new JniType (vm.TypeManager.GetTypeSignature (a.LimitType).Name);
r.Add (at);
} catch (JavaException e) {
e.Dispose ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public bool CompatibleWith (List<JniType> args, DynamicMetaObject[] dargs)
for (int i = 0; i < arguments.Count; ++i) {
if (args [i] == null) {
// Builtin type -- JNIEnv.FindClass("I") throws!
if (JniEnvironment.Types.GetJniTypeNameFromClass (arguments [i]) != vm.TypeManager.GetTypeSignature (dargs [i].LimitType).QualifiedReference)
if (JniEnvironment.Types.GetJniTypeNameFromClass (arguments [i]) != vm.TypeManager.GetTypeSignature (dargs [i].LimitType).Name)
return false;
}
else if (!JniEnvironment.Types.IsAssignableFrom (arguments [i], args [i].PeerReference))
Expand Down

0 comments on commit 5ef4b66

Please sign in to comment.