Hi,

I use the OSGi Converter to convert a proxy of an Interface to a Map and I get 
an exception:

org.osgi.util.converter.ConversionException: Cannot convert null to interface 
java.util.Map
at 
org.osgi.util.converter.ConvertingImpl.convertToMapType(ConvertingImpl.java:650)
at org.osgi.util.converter.ConvertingImpl.to(ConvertingImpl.java:187)
at 
org.osgi.util.converter.CustomConverterImpl$ConvertingWrapper.to(CustomConverterImpl.java:176)
at 
org.osgi.util.converter.CustomConverterImpl$ConvertingWrapper.to(CustomConverterImpl.java:144)
...

I don't know if it is a bug or not? Here is what I am doing:

1- I have two interfaces:
public interface ParentType
{
  String test();
}

public interface ChildType extends ParentType
{
  // Marker interface
}

2- I instantiate my proxy:
ChildType proxy = createProxy(); // My proxy return a constant "test" when 
test() is invoked.

3- I try to convert and get the exception: 
converter.convert(proxy).sourceAs(ChildType.class).to(new 
TypeReference<Map<String, Object>>() {/**/}));

If I add a method to ChildType ('String qq();') the conversion works.

Here is what I have found while debugging:
1- The converter tries to determine if my source is a map type 
(ConvertingImpl.isMapType)
2- For this, it calls the method ConvertingImpl.getInterfaces0(Class< ? > cls) 
with cls=ChildType.class. For ChildType be considered as a map type, this 
method should return a set of interfaces that contains ParentType.class (which 
has public method) but it doesn't. Indeed, implemented/extended interfaces are 
added to the result only if `cls` is not an interface, I don't really 
understand why?

Sorry if this mail is a bit obscure and specific, I didn't find an other place 
to ask...

You can find a repository demonstrating the issue here: 
https://github.com/cdelg/demo-converter-bug-or-not

Thanks for help.

Clément.
_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to