Skip to content

[TypeDescriptor] Unable to obtain nested generic from ? at level 1 [SPR-11898] #16517

@spring-projects-issues

Description

@spring-projects-issues

Edge Dalmacio opened SPR-11898 and commented

I'm trying to set an entry of a Map thru BeanWrapper via the code below. But I'm getting an IllegalStateException. This used to work back in 3.2.x, but doesn't work on 4.0.x.

I've attached a sample project to show the issue. Simply switch to Spring 3.2.x to see that it works.

public interface Context<D> {
   D getData();
}
...
public class ContextImpl<D> implements Context<D> {
   private final D data;
   public ContextImpl(D data) {
      this.data = data;
   }
   public D getData() {
      return this.data;
   }
}
...
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(context);
bw.setPropertyValue("data['message']", "it works!");
...
java.lang.IllegalStateException: Unable to obtain nested generic from ? at level 1
	at org.springframework.core.convert.TypeDescriptor.nested(TypeDescriptor.java:704)
	at org.springframework.core.convert.TypeDescriptor.nested(TypeDescriptor.java:676)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1040)
	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:902)
	at typedescriptor.issue.ContextImplTest.setProperty(ContextImplTest.java:25)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Affects: 4.0 GA

Attachments:

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