views:

265

answers:

3

I have implemented successfully the reflectionEquals method, with a list of excluded fields.

return  EqualsBuilder.reflectionEquals(this, obj, new String[] {"files", "notes", "status"});

However, I recently compiled my program on Java 1.5 and now I get the following error when the program hits the above line:

java.lang.NoSuchMethodError: org.apache.commons.lang.builder.EqualsBuilder.= reflectionEquals(Ljava/lang/Object;Ljava/lang/Object;[Ljava/lang/String;)Z

If anyone has an insight on why the method does not exist at runtime, I would appreciate it

A: 

You may have an older version on your runtime classpath.

Get the latest version of Apache Commons Lang

Mike Pone
+1  A: 

This is likely a var args problem. Be sure to recompile everything in java 1.5 and be sure you are running it on java 1.5, and be sure you reference the same jar at compilation as at runtime.

Yishai
I doubt that, since his last argument is an array of a type other than Object. You usually get the problem when using Object[] or when you use null (which might cause ambiguous constructors)
mihi
+5  A: 

Every NoSuchMethodError that I've ever encountered has (eventually) been found to be a mismatch between the version of an external library on the classpath at compile time vs. the version of the library on the classpath at runtime (i.e. - in this case, you would have a different version of apache commons on your classpath when the application is compiled than when it is running.)

The method was definitely there when your code was compiled - or a compiler error would've been thrown.

Check the versions of commons-lang.jar on your classpaths - I'm betting you'll find a mismatch.

It's worth noting that this is NOT a MISSING jar file - that would throw a ClassNotFoundException (maybe eventually followed by a NoClassDefFoundError.)

Jared