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

TypeDescriptor does not check generics in equals method (for ConversionService caching) #31672

Closed
nstdio opened this issue Nov 24, 2023 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@nstdio
Copy link

nstdio commented Nov 24, 2023

Affects: 6.0.14


The type descriptors of java.util.Optional<java.lang.Integer> and java.util.Optional<java.lang.String> are considered equal.

    var r1 = ResolvableType.forClassWithGenerics(Optional.class, Integer.class);
    var r2 = ResolvableType.forClassWithGenerics(Optional.class, String.class);

    var t1 = new TypeDescriptor(r1, null, null);
    var t2 = new TypeDescriptor(r2, null, null);
    
    assertNotEquals(r1, r2); // passes
    assertNotEquals(t1, t2); // fails

I encountered it in context of GenericConversionService caching. Let's say we have two distinct ConditionalGenericConverter as follows
(1) sourceType=Pojo, targetType=Optional<Integer>
(2) sourceType=Pojo, targetType=Optional<String>

The GenericConversionService service is able to cache only one of converters mentioned above. Let's assume we successfully used (1) converter. When we want to convert using (2) converter the GenericConversionService uses (1) converter which causes class cast exception later.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 24, 2023
@jhoeller jhoeller added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 24, 2023
@jhoeller jhoeller self-assigned this Nov 24, 2023
@jhoeller jhoeller added this to the 6.1.2 milestone Nov 24, 2023
@jhoeller jhoeller changed the title TypeDescriptor does not check generics in equals method. TypeDescriptor does not check generics in equals method (for ConversionService caching) Nov 24, 2023
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-6.0.x labels Nov 24, 2023
jhoeller added a commit that referenced this issue Nov 24, 2023
jhoeller added a commit that referenced this issue Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants