Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid binding for java.util.SortedMap #583

Open
jpobst opened this issue Feb 24, 2020 · 0 comments
Open

Invalid binding for java.util.SortedMap #583

jpobst opened this issue Feb 24, 2020 · 0 comments
Labels
bug Component does not function as intended generator Issues binding a Java library (generator, class-parse, etc.)

Comments

@jpobst
Copy link
Contributor

jpobst commented Feb 24, 2020

Today we bind java.util.SortedMap as Android.Runtime.JavaDictionary so it feels more like using .NET types. However, JavaDictionary does not implement ISortedMap, causing this error when attempting to use the type at runtime:

JNI ERROR (app bug): attempt to pass an instance of java.util.HashMap as argument 1 to void org.osmdroid.views.overlay.advancedpolyline.ColorMappingRanges.<init>(java.util.SortedMap)

Code specifying this conversion:
https://github.com/xamarin/java.interop/blob/master/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/SymbolTable.cs#L212

To fix this we will need to create something like JavaSortedDictionary and map it to java.util.SortedMap.

Workaround

To work around this, the generated member can be deleted via metadata and manually bound to a type which implements SortedMap (TreeMap) with an Addition.

For example, here is a constructor that takes a java.util.SortedMap:

public Foo (final TreeMap p0) 
{
  const string __id = "(Ljava/util/SortedMap;)V";
  if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero)
  	return;
  IntPtr native_p0 = JNIEnv.ToLocalJniHandle (p0);
  try {
	  JniArgumentValue* __args = stackalloc JniArgumentValue [1];
  	__args [0] = new JniArgumentValue (native_p0);
  	var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args);
  	SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef);
  	_members.InstanceMethods.FinishCreateInstance (__id, this, __args);
  } finally {
  	JNIEnv.DeleteLocalRef (native_p0);
  }
}
@jpobst jpobst added generator Issues binding a Java library (generator, class-parse, etc.) bug Component does not function as intended labels Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Component does not function as intended generator Issues binding a Java library (generator, class-parse, etc.)
Projects
None yet
Development

No branches or pull requests

1 participant