Skip to content

GenericTypeResolver can throw null pointer exception when types cannot be resolved [SPR-8698] #13340

@spring-projects-issues

Description

@spring-projects-issues

!!Use pwebb rather than philw opened SPR-8698 and commented

The GenericTypeResolver can throw null pointer exception when types cannot be resolved, I think that it should simply return a null value.

java.lang.NullPointerException
	at java.lang.Class.isAssignableFrom(Native Method)
	at org.springframework.core.GenericTypeResolver.doResolveTypeArguments(GenericTypeResolver.java:209)
	at org.springframework.core.GenericTypeResolver.doResolveTypeArguments(GenericTypeResolver.java:181)
	at org.springframework.core.GenericTypeResolver.resolveTypeArguments(GenericTypeResolver.java:166)
	at org.springframework.core.GenericTypeResolver.resolveTypeArgument(GenericTypeResolver.java:145)

Here is a test to replicate:

@Test
public void resolvesNullIfNotResolvable() throws Exception {
	GenericClass<String> o = new GenericClass<String>();
	assertNull(GenericTypeResolver.resolveTypeArgument(o.getClass(), GenericClass.class));
}

static class GenericClass<T> {
}

I think the fix should be to add a null check on doResolveTypeArguments

private static Class[] doResolveTypeArguments(Class ownerClass, Type ifc, Class genericIfc) {
	if (ifc != null) {
		if (ifc instanceof ParameterizedType) {
		...

Affects: 3.0.6, 3.1 M2

Issue Links:

  • DATACMNS-104 Upgrade to Spring 3.0.7. ("is depended on by")

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