QuickTip : Spring 2.0 testing: java.lang.NoSuchMethodError: org.springframework.util.ObjectUtils.nullSafeToString

Posted on Wednesday, December 5, 2007

5


Today while writing a test for one of the project modules I got the following stacktrace

java.lang.NoSuchMethodError: org.springframework.util.ObjectUtils.nullSafeToString(Ljava/lang/Object;)Ljava/lang/String;
at org.springframework.test.AbstractSpringContextTests.contextKeyString(AbstractSpringContextTests.java :133)
at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:100)
at org.springframework.test.AbstractSingleSpringConte xtTests.setUp(AbstractSingleSpringContextTests.jav a:75)
at junit.framework.TestCase.runBare(TestCase.java:125 )

after spending over an hour trying to debug it came out that I was using 2 versions of spring-mock i.e.

spring-mock-2.0.6.jar and spring-mock-1.2.8.jar

Apparently Spring 2.x has the version of nullSafeToString where it has the following method

public static String nullSafeToString(Object obj) in ObjectUtils

and Spring 1.x does not have this method.

Hence once i removed the older Spring-mock the tests started working fine.

About these ads
Posted in: Java