-
Notifications
You must be signed in to change notification settings - Fork 139
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
RFE: issue (optional) warning when '==' is used on wrapper types #2176
Comments
What does javac report? |
While I sympathise with the "don't bloat the compiler with too much work" (that would make it slower etc), I doubt that the ECJ "Method can be static" optional problem is something a compiler should do as well, but causes fewer programming errors. In any case, javac (17) doesn't issue a warning for either using I don't propose to emit a warning always, but make it an option similar to |
Sure. If you (or anyone else) is interested to provide this feature, feel free to contribute. |
When comparing wrapper types or Strings using '==' this is done by reference instead of value. Usually this is in error (e.g. Long only caches values between -127 and +127). By flagging this as an optional warning or even error (configurable) these cases can be easily weeded out. Fixes eclipse-jdt#2176
When comparing wrapper types or Strings using '==' this is done by reference instead of value. Usually this is in error (e.g. Long only caches values between -127 and +127). By flagging this as an optional warning or even error (configurable) these cases can be easily weeded out. Fixes eclipse-jdt#2176
When comparing wrapper types or Strings using '==' this is done by reference instead of value. Usually this is in error (e.g. Long only caches values between -127 and +127). By flagging this as an optional warning or even error (configurable) these cases can be easily weeded out. Fixes eclipse-jdt#2176
When comparing wrapper types or Strings using '==' this is done by reference instead of value. Usually this is in error (e.g. Long only caches values between -127 and +127). By flagging this as an optional warning or even error (configurable) these cases can be easily weeded out. Fixes eclipse-jdt#2176
Well, here you go! |
When comparing wrapper types or Strings using '==' this is done by reference instead of value. Usually this is in error (e.g. Long only caches values between -127 and +127). By flagging this as an optional warning or even error (configurable) these cases can be easily weeded out. Fixes eclipse-jdt#2176
When comparing wrapper types or Strings using '==' this is done by reference instead of value. Usually this is in error (e.g. Long only caches values between -127 and +127). By flagging this as an optional warning or even error (configurable) these cases can be easily weeded out. Fixes eclipse-jdt#2176
The PR builds correctly, I'd love some feedback on whether it is complete, hits the correct spots and suitability for adoption. |
When comparing wrapper types or Strings using '==' this is done by reference instead of value. Usually this is in error (e.g. Long only caches values between -127 and +127). By flagging this as an optional warning or even error (configurable) these cases can be easily weeded out. Fixes eclipse-jdt#2176
When comparing wrapper types or Strings using '==' this is done by reference instead of value. Usually this is in error (e.g. Long only caches values between -127 and +127). By flagging this as an optional warning or even error (configurable) these cases can be easily weeded out. Fixes eclipse-jdt#2176
I would like that Eclipse (similar to IDEA) would issue an optional warning when one uses the following construct:
Because (as apparently we don't all know) Long is a wrapper class and using
==
only works for Long values between -127 and 127 due to caching (similarly for the other wrapper types).This would at least uncover one such instance in our code base, of which I suspect to find a greater number alas.
The text was updated successfully, but these errors were encountered: