Skip to content

TypeDescriptor.forElementType() does not work for TypeDescriptor obtained via TypeDescriptor.valueOf() [SPR-7390] #12048

@spring-projects-issues

Description

@spring-projects-issues

Jon Kranes opened SPR-7390 and commented

Based on JavaDoc for TypeDescriptor.forElementType(), I expect the expression:

TypeDescriptor.valueOf(java.util.List.class).forElementType(String.class)

should produce a TypeDescriptor for parameterized List of type String, i.e. java.util.List<String>. However, the implementation for a TypeDescriptor that was not originally constructed from a Field or MethodParameter simply does:

return TypeDescriptor.valueOf(elementType);

The expected behavior is very useful as there appears to be no other way to programmatically construct a TypeDescriptor for a parameterized collection, without having reference to a Field or MethodParameter object. The workaround is to create or refer to a field or method in some arbitrary class in order to use the Field or MethodParameter constructors, but this is awkward and would be unnecessary if the forElementType worked as expected.

Simple unit test:

    @Test
    public void testForElementType() {
        TypeDescriptor td = TypeDescriptor.valueOf(java.util.List.class).forElementType(String.class);
        // Fails. getType() returns java.util.String
        assertEquals(java.util.List.class, td.getType()); 

        //Fails.  getElementType() returns null
        assertEquals(String.class, td.getElementType());  
    }

Affects: 3.0.3

Issue Links:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions