Announcement Announcement Module
Collapse
No announcement yet.
Original must not be null / failed to convert property value of type Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Original must not be null / failed to convert property value of type

    Argh! Delivery in two days and I'm fighting with this problem... drives me crazy.

    My working environment is Eclipse, Java JDK 1.5. I use Maven to manage the dependencies. I have Spring 2.5.4.

    As part of my JUnit test suite I have the following bean file:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    [...]
    	<!-- Sets the logger singleton. Notice the self reference; for the
    	object, the attribute 'instance' is set to itself. -->
        <bean id="Logger" class="utilities.SystemLogger">
        	<property name = "instance" ref = "Logger"/>
        </bean>
    
        <bean id="ConsistencyCheckerErrorHandler" class="errorHandler.ErrorHandler"/>
    
        <bean id="DatabaseConnection" class="consistencychecker.DatabaseConnector">
        	<property name = "databaseConnectionUrl" value="jdbc:mysql://localhost/dabystestdatabase"/>
        	<property name = "databaseConnectionUser" value="root"/>
        	<property name = "databaseConnectionPass" value="pathfinder"/>    
        	<property name = "driverName" value = "com.mysql.jdbc.Driver"/>
        </bean>
     
        <bean id="ConsistencyCheckerEngine" class="consistencychecker.Engine">
        <property name = "rules">
        	<list>
     	
    	<!-- This rule shall fail -->
    	<bean id="FixedValueEqualNullAgainstField3" class="consistencychecker.CheckRuleFixedValue">
    		<property name = "table" value = "table1"/>
    		<property name = "field" value = "field3"/>
    		<property name = "value" value = "null"/>		
    		<property name = "connector" ref = "DatabaseConnection"/>	
    	</bean>
    	
    	<!-- This rule shall pass -->
    	<bean id="FixedValueEqualNullAgainstField4" class="consistencychecker.CheckRuleFixedValue">
          	<property name = "table" value = "table1"/>
    		<property name = "field" value = "field4"/>
    		<property name = "value" value = "null"/>		
    		<property name = "connector" ref = "DatabaseConnection"/>
    	</bean>	
    
    	<!-- This rule shall fail -->
    	<bean id="FixedValueEqualNullAgainstField6" class="consistencychecker.CheckRuleFixedValue">
          	<property name = "table" value = "table1"/>
    		<property name = "field" value = "field6"/>
    		<property name = "value" value = "null"/>		
    		<property name = "connector" ref = "DatabaseConnection"/>
    	</bean>	
    
    	<!-- This rule shall pass -->
    	<bean id="FixedValueEqual2AgainstField2" class="consistencychecker.CheckRuleFixedValue">
          	<property name = "table" value = "table1"/>
    		<property name = "field" value = "field2"/>
    		<property name = "value" value = "2"/>		
    		<property name = "connector" ref = "DatabaseConnection"/>
    	</bean>	
    	
    	<!-- This rule shall fail -->
    	<bean id="FixedValueEqual2AgainstField6" class="consistencychecker.CheckRuleFixedValue">
          	<property name = "table" value = "table1"/>
    		<property name = "field" value = "field6"/>
    		<property name = "value" value = "2"/>		
    		<property name = "connector" ref = "DatabaseConnection"/>
    	</bean>
    	
    	<!-- This rule shall pass -->
    	<bean id="MandatoryAgainstField2" class="consistencychecker.CheckRuleMandatory">
          	<property name = "table" value = "table1"/>
    		<property name = "field" value = "field2"/>
    		<property name = "value" value = "2"/>		
    		<property name = "connector" ref = "DatabaseConnection"/>
    	</bean>		
    	
    	<!-- This rule shall fail -->
    	<bean id="MandatoryAgainstField6" class="consistencychecker.CheckRuleMandatory">
          	<property name = "table" value = "table1"/>
    		<property name = "field" value = "field6"/>
    		<property name = "value" value = "2"/>		
    		<property name = "connector" ref = "DatabaseConnection"/>
    	</bean>		
    
     			
        	</list>
        	</property>
        </bean>
     
     
         <bean id="ConsistencyCheckerContext" class="consistencychecker.Context">
        	<property name = "engine" ref="ConsistencyCheckerEngine"/>
        </bean>
     
     
    </beans>

    When I try to assemble the system as part of the JUnit tests I get the error message:


    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ConsistencyCheckerContext' defined in file [C:\Documents and Settings\KrygervillemosG.GROUPINFRA\workspace\DABYS\src\consistencychecker\ConsistencyCheckerAssembly.xml]: Cannot resolve reference to bean 'ConsistencyCheckerEngine' while setting bean property 'engine'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ConsistencyCheckerEngine' defined in file [C:\Documents and Settings\KrygervillemosG.GROUPINFRA\workspace\DABYS\src\consistencychecker\ConsistencyCheckerAssembly.xml]: Cannot create inner bean 'FixedValueEqualNullAgainstField3' of type [consistencychecker.CheckRuleFixedValue] while setting bean property 'rules' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'FixedValueEqualNullAgainstField3' defined in file [C:\Documents and Settings\KrygervillemosG.GROUPINFRA\workspace\DABYS\src\consistencychecker\ConsistencyCheckerAssembly.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [java.lang.String] for property 'table'; nested exception is java.lang.IllegalArgumentException: Original must not be null
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1244)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1008)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at consistencychecker.ContextTest.setUp(ContextTest.java:40)
    	at junit.framework.TestCase.runBare(TestCase.java:132)
    	at junit.framework.TestResult$1.protect(TestResult.java:110)
    	at junit.framework.TestResult.runProtected(TestResult.java:128)
    	at junit.framework.TestResult.run(TestResult.java:113)
    	at junit.framework.TestCase.run(TestCase.java:124)
    	at junit.framework.TestSuite.runTest(TestSuite.java:232)
    	at junit.framework.TestSuite.run(TestSuite.java:227)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    I have been fighting this for a while now and havnt got a clue. Any hints, ideas or suggestions would be very welcome.

  • #2
    Ok, solved it. Phew.

    Apparently Spring dont like you to do 'fluent interfaces', e.g. setters of the type:
    public int setValue(int newValue) {
    value = newValue;
    return newValue;
    }
    For each attribute with such a setter I got the reported error. Changing the code to:
    public void setValue(int newValue) {
    value = newValue;
    }
    Solved the problem...

    Comment


    • #3
      Yes that's true. As far as now such setters go against JavaBean specification, and it is a Spring's reason not to support them, but anyway they are so convinient sometimes ... .

      Probably, deserves filing of enchancement request in JIRA.

      Originally posted by Villemos View Post
      Ok, solved it. Phew.

      Apparently Spring dont like you to do 'fluent interfaces', e.g. setters of the type:


      For each attribute with such a setter I got the reported error. Changing the code to:


      Solved the problem...

      Comment


      • #4
        My problem was missing setters

        I got the same error message for a bean without setters. I wanted an imutable object, and had the properties set in the constructor. When adding setters the error disappeared. I thought spring should support this, so it could be something else that was wrong with my code, but at least the problem disappeared when I put in the setters...

        Comment


        • #5
          Originally posted by Plastics View Post
          I got the same error message for a bean without setters. I wanted an imutable object, and had the properties set in the constructor. When adding setters the error disappeared. I thought spring should support this, so it could be something else that was wrong with my code, but at least the problem disappeared when I put in the setters...
          Am I right assuming that you tried to inject the properties to the object of class that gets them via constructor using <property> element at the context description?

          Comment


          • #6
            This same is encountered when using a different interface on the getter than on the setter

            Code:
            public UserDetailService getCobamUserDetailsService()
              {
                return this.cobamUserDetailsService;
              }
            
            public void setCobamUserDetailsService(ICOBAMUserDetailService userDetailsService)
              {
                this.cobamUserDetailsService = userDetailsService;
              }
            where ICOBAMUserDetailService extends UserDetailService

            Fixed it by changing both methods to use ICOBAMUserDetailService

            Comment


            • #7
              Apparently Spring dont like you to do 'fluent interfaces', e.g. setters of the type:
              Code:
              public int setValue(int newValue) {
              value = newValue;
              return newValue;
              }

              The example you've provided IS NOT a fluent interface.

              This is a fluent interface:

              Code:
              public class Foo
              {
                  private int bar;
              
                  public Foo setBar(int bar)
                  {
                      this.bar = bar;
                      return this;
                  }
              }
              A fluent interface is typically used for MethodChaining.

              Comment


              • #8
                protected setters also result in this message

                I received this "Original must not be null" message when my setter method was classified protected instead of public.

                Comment

                Working...
                X