You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by "Edward Ribeiro (JIRA)" <ji...@apache.org> on 2013/05/14 19:37:20 UTC
[jira] [Commented] (ZOOKEEPER-1610) Some classes are using == or !=
to compare Long/String objects instead of .equals()
[ https://issues.apache.org/jira/browse/ZOOKEEPER-1610?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13657253#comment-13657253 ]
Edward Ribeiro commented on ZOOKEEPER-1610:
-------------------------------------------
An alternative to refactor the lines of org/apache/zookeeper/server/quorum/flexible/QuorumHierarchical.java would be too make the for-each loop to unbox the sid to a primitive type as follows:
for (long sid: serverWeight.keySet()){
if (serverWeight.get(sid) != qm.serverWeight.get(sid))
return false;
}
for (long sid: groupWeight.keySet()){
if (groupWeight.get(sid) != qm.groupWeight.get(sid))
return false;
}
for (long sid: serverGroup.keySet()){
if (serverGroup.get(sid) != qm.serverGroup.get(sid))
return false;
}
Any of those two solutions (the one in the patch or the one above) will suffice to this specific case.
Cheers,
Edward
> Some classes are using == or != to compare Long/String objects instead of .equals()
> -----------------------------------------------------------------------------------
>
> Key: ZOOKEEPER-1610
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1610
> Project: ZooKeeper
> Issue Type: Bug
> Components: java client, quorum
> Affects Versions: 3.5.0, 3.4.5
> Reporter: Edward Ribeiro
> Assignee: Edward Ribeiro
> Priority: Trivial
> Attachments: ZOOKEEPER-1610.patch
>
>
> The classes org.apache.zookeeper.client.ZooKeeperSaslClient.java and
> org.apache.zookeeper.server.quorum.flexible.QuorumHierarchical.java compare Strings and/or Longs using referential equality.
> Usually, this is not a problem because the Longs are cached and Strings are interned, but I myself had problems with those kind of comparisons in the past because one production JVM didn't reused the objects.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira