org.springframework.beans.NullValueInNestedPathException: Invalid property 'arrayTwo[0]' of bean class [com.test.TestForm]: Cannot access indexed value of property referenced in indexed property path 'arrayTwo[0]': returned null

Spring JIRA | Shishir K Singh | 1 decade ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Not sure if this is abug or I am doing something wrong: public class TestForm { private Boolean testBoolean; private String[] arrayOne; private String[] arrayTwo; public TestForm() {} public String[] getArrayOne() { return this.arrayOne; } public void setArrayOne(String[] arrayOne) { this.arrayOne = arrayOne; } public String[] getArrayTwo() { return this.arrayTwo; } public void setArrayTwo(String[] arrayTwo) { this.arrayTwo = arrayTwo; } public Boolean getTestBoolean() { return this.testBoolean; } public void setTestBoolean(Boolean testBoolean) { this.testBoolean = testBoolean; } } --------------------------------------------- And my test case is : --------------------------------------------- public void testBindWithInitializer() throws ServletException { ServletContext sc = new MockServletContext(); MockHttpServletRequest request = new MockHttpServletRequest(sc); request.addParameter("testBoolean", "true"); request.addParameter("arrayTwo", "arraytwo_1,arraytwo_2"); TestForm form = new TestForm(); Errors errors = BindUtils.bind(request,form, "form", new BindInitializer() { public void initBinder(ServletRequest request, ServletRequestDataBinder binder) { binder.registerCustomEditor(String[].class,"arrayTwo",new StringArrayPropertyEditor()); } }); assertTrue("arraytwo length", form.getArrayTwo().length == 2); } I get the following error : Testcase: testBindWithInitializer took 0.12 sec Caused an ERROR Invalid property 'arrayTwo[0]' of bean class [com.test.TestForm]: Cannot access indexed value of property referenced in indexed property path 'arrayTwo[0]': returned null org.springframework.beans.NullValueInNestedPathException: Invalid property 'arrayTwo[0]' of bean class [com.test.TestForm]: Cannot access indexed value of property referenced in indexed property path 'arrayTwo[0]': returned null at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:499) at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:484) at org.springframework.beans.BeanWrapperImpl.getPropertyType(BeanWrapperImpl.java:917) at org.springframework.validation.BindException.resolveMessageCodes(BindException.java:162) at org.springframework.validation.DataBinder.bind(DataBinder.java:229) at org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:92) at org.springframework.web.bind.BindUtils.bind(BindUtils.java:65) at com.test.TestMail.testBindWithInitializer(TestMail.java:82) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at junit.extensions.TestDecorator.basicRun(TestDecorator.java:22) at junit.extensions.TestSetup$1.protect(TestSetup.java:19) at junit.extensions.TestSetup.run(TestSetup.java:23) at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:377) at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:135)

    Spring JIRA | 1 decade ago | Shishir K Singh
    org.springframework.beans.NullValueInNestedPathException: Invalid property 'arrayTwo[0]' of bean class [com.test.TestForm]: Cannot access indexed value of property referenced in indexed property path 'arrayTwo[0]': returned null
  2. 0

    Not sure if this is abug or I am doing something wrong: public class TestForm { private Boolean testBoolean; private String[] arrayOne; private String[] arrayTwo; public TestForm() {} public String[] getArrayOne() { return this.arrayOne; } public void setArrayOne(String[] arrayOne) { this.arrayOne = arrayOne; } public String[] getArrayTwo() { return this.arrayTwo; } public void setArrayTwo(String[] arrayTwo) { this.arrayTwo = arrayTwo; } public Boolean getTestBoolean() { return this.testBoolean; } public void setTestBoolean(Boolean testBoolean) { this.testBoolean = testBoolean; } } --------------------------------------------- And my test case is : --------------------------------------------- public void testBindWithInitializer() throws ServletException { ServletContext sc = new MockServletContext(); MockHttpServletRequest request = new MockHttpServletRequest(sc); request.addParameter("testBoolean", "true"); request.addParameter("arrayTwo", "arraytwo_1,arraytwo_2"); TestForm form = new TestForm(); Errors errors = BindUtils.bind(request,form, "form", new BindInitializer() { public void initBinder(ServletRequest request, ServletRequestDataBinder binder) { binder.registerCustomEditor(String[].class,"arrayTwo",new StringArrayPropertyEditor()); } }); assertTrue("arraytwo length", form.getArrayTwo().length == 2); } I get the following error : Testcase: testBindWithInitializer took 0.12 sec Caused an ERROR Invalid property 'arrayTwo[0]' of bean class [com.test.TestForm]: Cannot access indexed value of property referenced in indexed property path 'arrayTwo[0]': returned null org.springframework.beans.NullValueInNestedPathException: Invalid property 'arrayTwo[0]' of bean class [com.test.TestForm]: Cannot access indexed value of property referenced in indexed property path 'arrayTwo[0]': returned null at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:499) at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:484) at org.springframework.beans.BeanWrapperImpl.getPropertyType(BeanWrapperImpl.java:917) at org.springframework.validation.BindException.resolveMessageCodes(BindException.java:162) at org.springframework.validation.DataBinder.bind(DataBinder.java:229) at org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:92) at org.springframework.web.bind.BindUtils.bind(BindUtils.java:65) at com.test.TestMail.testBindWithInitializer(TestMail.java:82) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at junit.extensions.TestDecorator.basicRun(TestDecorator.java:22) at junit.extensions.TestSetup$1.protect(TestSetup.java:19) at junit.extensions.TestSetup.run(TestSetup.java:23) at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:377) at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:135)

    Spring JIRA | 1 decade ago | Shishir K Singh
    org.springframework.beans.NullValueInNestedPathException: Invalid property 'arrayTwo[0]' of bean class [com.test.TestForm]: Cannot access indexed value of property referenced in indexed property path 'arrayTwo[0]': returned null

    Root Cause Analysis

    1. org.springframework.beans.NullValueInNestedPathException

      Invalid property 'arrayTwo[0]' of bean class [com.test.TestForm]: Cannot access indexed value of property referenced in indexed property path 'arrayTwo[0]': returned null

      at org.springframework.beans.BeanWrapperImpl.getPropertyValue()
    2. Spring Beans
      BeanWrapperImpl.getPropertyType
      1. org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:499)
      2. org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:484)
      3. org.springframework.beans.BeanWrapperImpl.getPropertyType(BeanWrapperImpl.java:917)
      3 frames
    3. Spring Context
      DataBinder.bind
      1. org.springframework.validation.BindException.resolveMessageCodes(BindException.java:162)
      2. org.springframework.validation.DataBinder.bind(DataBinder.java:229)
      2 frames
    4. Spring
      BindUtils.bind
      1. org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:92)
      2. org.springframework.web.bind.BindUtils.bind(BindUtils.java:65)
      2 frames
    5. com.test
      TestMail.testBindWithInitializer
      1. com.test.TestMail.testBindWithInitializer(TestMail.java:82)
      1 frame
    6. Java RT
      DelegatingMethodAccessorImpl.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      3 frames
    7. JUnit
      TestSetup.run
      1. junit.extensions.TestDecorator.basicRun(TestDecorator.java:22)
      2. junit.extensions.TestSetup$1.protect(TestSetup.java:19)
      3. junit.extensions.TestSetup.run(TestSetup.java:23)
      3 frames
    8. org.eclipse.ant
      InternalAntRunner.main
      1. org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:377)
      2. org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:135)
      2 frames