Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractMethodError thrown by EqualsVerifier #52

Closed
GoogleCodeExporter opened this issue Mar 29, 2015 · 2 comments
Closed

AbstractMethodError thrown by EqualsVerifier #52

GoogleCodeExporter opened this issue Mar 29, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Unzip the attached file containg a Netbeans project.
2. Run JUnit tests (ErrorMessageXMLTest).


What is the expected output? What do you see instead?

Both tests passing.

Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 1,593 sec

Instead I'm getting this:

Testcase: testGetXMLAsString(eqbugdemo.ErrorMessageXMLTest):    Caused an ERROR
$javax.xml.bind.Marshaller$$EnhancerByCGLIB$$59e68469.marshal(Ljava/lang/Object;
Ljava/io/Writer;)V
java.lang.AbstractMethodError: 
$javax.xml.bind.Marshaller$$EnhancerByCGLIB$$59e68469.marshal(Ljava/lang/Object;
Ljava/io/Writer;)V
    at eqbugdemo.ErrorMessageXML.marshall(ErrorMessageXML.java:57)
    at eqbugdemo.GenericXML.getXMLAsString(GenericXML.java:12)
    at eqbugdemo.ErrorMessageXMLTest.testGetXMLAsString(ErrorMessageXMLTest.java:33)


Test eqbugdemo.ErrorMessageXMLTest FAILED

What version of the product are you using? On what operating system?

1.0.2 on Windows XP

Please provide any additional information below.

The workaround I have found is to switch the order of testGetXMLAsString() and 
testEqualsContract() methods in the unit test. When testEqualsContract is 
executed AFTER testGetXMLAsString there is no error and both tests pass 
successfully. This may also be a hint to you.

Best regards,
Konrad Ciborowski
Kraków, Poland

Original issue reported on code.google.com by [email protected] on 14 Dec 2011 at 11:57

Attachments:

@GoogleCodeExporter
Copy link
Author

Hi Konrad,

Thanks for documenting the issue so thoroughly.

What happens, is this. In order to see whether fields in a class are used in 
the equals method, EqualsVerifier will create instances of the appropriate 
type, and assign them to the fields. It does this for all fields, including 
static fields. (The only exception are static final fields.) So, it does this 
also for ErrorMessageXML's marshaller field, which is static.

Of course, once assigned, the new values doesn't "go away". So EqualsVerifier's 
marshaller instance is carried over to the next test. The null check in the 
marshall method will return false, and EqualsVerifier's dummy instance is then 
used. This is what causes the AbstractMethodError, because 
javax.xml.bind.Marshaller is an interface, which is abstract. It doesn't have 
anything to do with the fact that ErrorMessageXML is a subclass of an abstract 
class, by the way; if you remove the superclass and move getXMLAsString to 
ErrorMessageXML, you get exactly the same error.

I consider it a bug that EqualsVerifier doesn't leave classes in their original 
state once it's done with them. However, in practice, it only rarely causes 
problems, and there are easy workarounds. Therefore, I will give this a low 
priority, which means that I intend to find a solution for this, but I don't 
know when I will do so. It will probably not be in the next release. I will put 
up some documentation in the coming days.

Some of the ways you can work around this issue:
* Make marshaller non-static.
* Assign a marshaller directly, and make it final.
* In testEqualsContract, assign null to the marshaller field. You'll have to 
use reflection to do that, though, so this is not a very nice option, but I 
think it's the best if you don't want to change marshaller's modifiers.
* Rely on the ordering of the unit tests, as you are doing now. This is kind of 
dangerous, because JUnit doesn't guarantee that the tests are run in order. 
This might change in the next version.

Hope this helps!

Regards,
Jan

Original comment by [email protected] on 14 Dec 2011 at 9:49

  • Changed state: Accepted
  • Added labels: Priority-Low
  • Removed labels: Priority-Medium

@GoogleCodeExporter
Copy link
Author

I have fixed this issue. Version 1.1 is available now.

Original comment by [email protected] on 11 Feb 2012 at 11:50

  • Changed state: Fixed
  • Added labels: ****
  • Removed labels: ****

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant