-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Document that assert[Not]Same
should not be used with primitive types
#3358
Comments
Technically speaking, The Javadoc clearly states the following:
And the error message even shows that there are two distinct
If we want So the question to answer is whether we want to introduce those overloaded variants. |
Technically speaking you are correct, yes. Good point on the error message, I can still imagine developers unaware of the caching would be confused about why two of the seemingly same primitive values result in different references in that case, which could mislead them into thinking their implementation is wrong and a lot of time wasted in debugging. In the end it comes down to whether JUnit users would expect I could be missing something of course, but I think it would hurt JUnit users more not to have overloaded |
We'll likely discuss this topic within the team during an upcoming team call; however, if someone invokes
For equality, we have If we do decide to introduce primitive type overloads for |
As a side note, |
|
Team decision: Document that |
Agreed. The
In most cases I would say yes, unless you want to verify a primitive datatype is used, as
This was one approach I was thinking of as well. One option to take it further could be to throw an |
That's not possible without introducing overloaded variants for all affected primitive types. |
assertSame
fails with primitive type values outside the autobox cacheassertSame
should not be used with primitive types
I have changed this issue's title to align with the current action item. |
assertSame
should not be used with primitive typesassert[Not]Same
should not be used with primitive types
Steps to reproduce
Run the following Test Case:
Context
This is a similar issue to: assertj/assertj#2887
It appears to be the same kind of autoboxing caching issue due to
Object
being used inassertSame
. This also means that, as mentioned in the issue, it not only affects this exact case, but also any case mentioned in JLS section 5.1.7:This means that for example, the following case is also affected:
Deliverables
The text was updated successfully, but these errors were encountered: