I'm a .net (c#) programmer, through and through, but work needed someone to port an API that I had recently written in C# to Java, so guess who got the job!
So for the last 3 days, I've been fighting an issue with Java and Eclipse 3.2 and my own code. I've been getting the dreaded NoClassDefFound exception, and been unable, completely unable, to debug eclipse. Basically, when I attempted to instantiate a particular class, the NoClassDefFound exception was thrown, even though other classes in the same package could be created! Bizzare, and nobody could figure it out, nor could I find anything on the internet.
Once I was able to narrow it down to that particular class, I removed all of the code from the class and slowly started to add it back until I found the code that was causing the break.
Turns out that Java uses the hashCode() method when it creates a class, and I happened to have a bug in my hashCode() method (a bug that resulted from the port from c# no less).
This:
(_deathDate==null ? 0: _deathDate).hashCode() ^
Is not valid. It should be:
(
_deathDate==null ? 0: _deathDate.hashCode()) ^
Just a simple miss placed parenthesis in the hash code creation, and NO WAY TO FIGURE IT OUT! You'd think I'd get an exception or SOMETHING that pointed me to the hashCode function, but there was nothing. All I could find was that the classPath had to, in some way, be messed up, which cost me quite a bit of time determining that my class path was, in fact, fine.
Does anybody know how Java uses the hashCode() on creation of an object? Anybody have any good documents on this?
Robert