Skip to content

Inadequate implementation of GenericConversionService.findConverterByClassPair(Class, Class) [SPR-6297] #10963

Closed
@spring-projects-issues

Description

@spring-projects-issues

Oliver Becker opened SPR-6297 and commented

The algorithm implemented in GenericFormatterRegistry.findConverterByClassPair(Class, Class) apparently goes up the superinterface and superclass hierarchy to find a proper converter for a given source type. However, since the DefaultConversionService registers an ObjectToStringConverter, this converter will be preferred over specialized converters for interfaces.

Consider the following situation: class X implements the interface I which in turn is a subinterface of J. There is a special converter for J-to-String.
The classQueue will be filled in this case with

  • X
  • I (from X.getInterfaces())
  • Object (from X.getSuperclass())
  • J (from I.getInterfaces())

Since Object appears before J the generic ObjectToStringConverter will be used here instead of the more specific converter for J.

A more appropriate algorithm should probably consider first all interfaces before using the superclasses. In any case the ObjectToStringConverter should always be the last converter to be used.


Affects: 3.0 RC1

Sub-tasks:

Issue Links:

Referenced from: commits 010e72c

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions