[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-2628?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15651881#comment-15651881
 ] 

ASF GitHub Bot commented on ZOOKEEPER-2628:
-------------------------------------------

Github user lvfangmin commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/102#discussion_r87264725
  
    --- Diff: src/java/main/org/apache/zookeeper/server/DataTree.java ---
    @@ -1293,13 +1293,12 @@ public synchronized WatchesSummary 
getWatchesSummary() {
          * @param pwriter the output to write to
          */
         public void dumpEphemerals(PrintWriter pwriter) {
    -        Set<Long> keys = ephemerals.keySet();
             pwriter.println("Sessions with Ephemerals ("
    -                + keys.size() + "):");
    -        for (long k : keys) {
    -            pwriter.print("0x" + Long.toHexString(k));
    +                + ephemerals.keySet().size() + "):");
    +        for (Entry<Long, HashSet<String>> entry : ephemerals.entrySet()) {
    +            pwriter.print("0x" + Long.toHexString(entry.getKey()));
                 pwriter.println(":");
    -            HashSet<String> tmp = ephemerals.get(k);
    +            HashSet<String> tmp = entry.getValue();
    --- End diff --
    
    Usually, prefer to use the interface if we only use the methods defined in 
the interface, which makes it flexible (or less change needed) in case we want 
to use another Set implementation. 
    
    There is a best practice defined in Effective Java 2nd Edition, Item 52: 
Refer to objects by their interfaces:
    If appropriate interface types exist, then parameters, return values, and 
fields should all be declared using interface types. If you get into the habit 
of using interface types, your program will be much more flexible. It is 
entirely appropriate to refer to an object by a class if no appropriate 
interface exists.


> Investigate and fix findbug warnings
> ------------------------------------
>
>                 Key: ZOOKEEPER-2628
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2628
>             Project: ZooKeeper
>          Issue Type: Bug
>    Affects Versions: 3.5.2
>            Reporter: Michael Han
>             Fix For: 3.5.3
>
>
> Findbug tool used by Jenkins bot is upgraded to 3.0.1 from 2.0.3 according to 
> Infra team, and this leads to 20 new warnings produced by findbug. The 
> warning reports can be found on [pre commit 
> builds|https://builds.apache.org/job/PreCommit-ZOOKEEPER-Build/] with build 
> number >= 3513. These warnings need to be triaged and fixed if they are 
> legitimate.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to