You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Cristiano Gavião (JIRA)" <ji...@apache.org> on 2019/01/17 11:01:00 UTC

[jira] [Updated] (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:all-tabpanel ]

Cristiano Gavião updated FELIX-6031:
------------------------------------
    Description: 
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}

  was:
I'm converting from a map to an interface and since that interface has 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}



> 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
>            Priority: Critical
>
> 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)