You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "David Bosschaert (JIRA)" <ji...@apache.org> on 2019/01/18 14:34:00 UTC

[jira] [Commented] (FELIX-6031) Converter is not working properly when the target is an interface that extends others

    [ https://issues.apache.org/jira/browse/FELIX-6031?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16746348#comment-16746348 ] 

David Bosschaert commented on FELIX-6031:
-----------------------------------------

Fixed in [http://svn.apache.org/viewvc?view=revision&revision=1851622] - [~cvgaviao] could you please double check that its all good for you?

> Converter is not working properly when the target is an interface that extends others
> -------------------------------------------------------------------------------------
>
>                 Key: FELIX-6031
>                 URL: https://issues.apache.org/jira/browse/FELIX-6031
>             Project: Felix
>          Issue Type: Bug
>          Components: Converter
>    Affects Versions: converter-1.0.2
>            Reporter: Cristiano Gavião
>            Assignee: David Bosschaert
>            Priority: Critical
>             Fix For: converter-1.0.4
>
>
> I'm converting from a map to an interface and since that interface has not any direct method
>  it is not being considered a "map". But one of the interfaces that it extends has the required method named with the source's map key name.
> The problem is in the routine that identifies the interfaces in the method "getInterfaces0":
> {code:java}
> 	private static boolean isMapType(Class< ? > cls, boolean asJavaBean,
> 			boolean asDTO) {
> 		if (asDTO)
> 			return true;
> 		// All interface types that are not Collections are treated as maps
> 		if (Map.class.isAssignableFrom(cls))
> 			return true;
> 		*else if (getInterfaces(cls).size() > 0)*
> 			return true;
> 		else if (DTOUtil.isDTOType(cls))
> 			return true;
> 		else if (asJavaBean && isWriteableJavaBean(cls))
> 			return true;
> 		else
> 			return Dictionary.class.isAssignableFrom(cls);
> 	}
> {code}
> {code:java}
> 	private static Set<Class< ? >> getInterfaces(Class< ? > cls) {
> 		if (NO_MAP_VIEW_TYPES.contains(cls))
> 			return Collections.emptySet();
> 		Set<Class< ? >> interfaces = getInterfaces0(cls);
> 		for (Iterator<Class< ? >> it = interfaces.iterator(); it.hasNext();) {
> 			Class< ? > intf = it.next();
> 			if (intf.getDeclaredMethods().length == 0)
> 				it.remove();
> 		}
> 		interfaces.removeAll(NO_MAP_VIEW_TYPES);
> 		return interfaces;
> 	}
> {code}
> {code:java}
> 	private static Set<Class< ? >> getInterfaces0(Class< ? > cls) {
> 		if (cls == null)
> 			return Collections.emptySet();
> 		Set<Class< ? >> classes = new LinkedHashSet<>();
> 		if (cls.isInterface()) {
> 			classes.add(cls);
> 		} else {
> 			classes.addAll(Arrays.asList(cls.getInterfaces()));
> 		}
> 		classes.addAll(getInterfaces(cls.getSuperclass()));
> 		return classes;
> 	}
> {code}
> Below is my proposed fix that recursively takes all interfaces that the target extends:
> {code:java}
> 	private static Set<Class< ? >> getInterfaces0(Class< ? > cls) {
> 		if (cls == null)
> 			return Collections.emptySet();
> 		Set<Class< ? >> classes = new LinkedHashSet<>();
> 		if (cls.isInterface()) {
> 			classes.add(cls);
> 			if (cls.getInterfaces()!= null && cls.getInterfaces().length > 0) {
> 			    for (Class<?> intf : cls.getInterfaces()) {
>                     classes.addAll(getInterfaces0(intf));
>                 }
> 			}
> 		} else {
> 			classes.addAll(Arrays.asList(cls.getInterfaces()));
> 		}
> 		classes.addAll(getInterfaces(cls.getSuperclass()));
> 		return classes;
> 	}
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)