You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original issue created by ogregoire on 2014-07-29 at 03:35 PM
When I call the following, the test case fails (see full test case in attachment).
new ClassSanityTester().testNulls(MyObject.class);
I get the following error: No exception thrown for parameter at index 0 from MyObjectTest$MyObject.public boolean MyObjectTest$MyObject.equals(java.lang.Object)[null] for class MyObjectTest$MyObject
Clearly, this indicates that it expects a call to "equals(Object)" to throw a NullPointerException. That method should never throw an exception but rather return true or false. The test seems to skip this assertion and I'm surprised this hasn't been reported earlier.
Please make it so ClassSanityTester#testNulls(Class) doesn't fail when equals is behaving correctly (see the test case where testEquals(MyObject.class succeeds).
On a side note, the text returned should be adapted as it mentions three times MyObjectTest$MyObject. That's 2 too many, and it renders the whole error message nearly not understandable.
The text was updated successfully, but these errors were encountered:
Okay, I found one issue on my side: the lack of online javadoc available. I had to check in the code online to find out that it's playing nice only if @Nullable is present.
I checked the front-page of Guava and no, there is no link at all to the testlib javadoc. I played a bit with urls and couldn't find any url for the testlib javadoc.
While it is possible to add @Nullable to equals for own code, it may not always be possible to do this for generated code. For example, the AutoValue team decided to not do this (google/auto#73).
Thus I think that NullPointerTester should special-case equals and behave correctly whether the annotation is present or not. After all, the JavaDoc of equals specifies explicitly that the parameter can be null.
kevinb9n
changed the title
ClassSanityTester.testNulls fails on equals
NullPointerTester should not require @Nullable on the param of an equals() override
Nov 10, 2015
Original issue created by ogregoire on 2014-07-29 at 03:35 PM
When I call the following, the test case fails (see full test case in attachment).
new ClassSanityTester().testNulls(MyObject.class);
I get the following error: No exception thrown for parameter at index 0 from MyObjectTest$MyObject.public boolean MyObjectTest$MyObject.equals(java.lang.Object)[null] for class MyObjectTest$MyObject
Clearly, this indicates that it expects a call to "equals(Object)" to throw a NullPointerException. That method should never throw an exception but rather return true or false. The test seems to skip this assertion and I'm surprised this hasn't been reported earlier.
Please make it so ClassSanityTester#testNulls(Class) doesn't fail when equals is behaving correctly (see the test case where testEquals(MyObject.class succeeds).
On a side note, the text returned should be adapted as it mentions three times MyObjectTest$MyObject. That's 2 too many, and it renders the whole error message nearly not understandable.
The text was updated successfully, but these errors were encountered: