-
Notifications
You must be signed in to change notification settings - Fork 392
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
[Improvement] LockManager.java comparison using reference equality instead of value equality #2166
Comments
In most cases, it is better to use the Objects.equals() method. Because the Objects.equals() method is safer when dealing with null values, it can correctly handle cases where both parameters are null without throwing a NullPointerException. In the LockManager class, logically speaking, identifier should not be null, so I think identifier.equals(ROOT) is sufficient. What do you think? Can I fix it with this idea? @justinmclean |
Either is an improvement over the current code; I trust your judgment as to which is better. |
@justinmclean @YxAc |
@yuqi1129 , I didn't get what you mean. Can you offer more details? thx |
What if a user creates a metalake with the name "/", obviously, it equals to the |
if a user creates a metalake with the name "/", we expect return the root TreeLock? isn't it? |
No, it's not the ROOT node. ROOT stands for the real root of the tree. Currently, we haven't banned users from naming metalake as '/'. |
if we use ==, it indeed not return the ROOT node, but i thought we should return the ROOT node, otherwise it's confused here. if ==(reference equality) is deliberately used here to distinguish whether it is the real ROOT node, so this problem can be turned off? @yuqi1129 |
Yes, I use |
If there was a good reason for using reference equality and it was deliberately done, then a comment should be added stating why this was done. |
… ReferenceEquality error-prone
What would you like to be improved?
In LockManager.java:230: warning: [ReferenceEquality] Comparison using reference equality instead of value equality
if (identifier == ROOT) {
See https://errorprone.info/bugpattern/ReferenceEquality
How should we improve?
Does it mean 'if (Objects.equals(identifier, ROOT)) {' or 'if (identifier.equals(ROOT)) {'?
The text was updated successfully, but these errors were encountered: