[JAVA-1574] Confusing local variable name in BaseCluster Created: 28/Nov/14  Updated: 11/Sep/19  Resolved: 25/Nov/15

Status: Closed
Project: Java Driver
Component/s: Internal
Affects Version/s: None
Fix Version/s: 3.2.0

Type: Task Priority: Major - P3
Reporter: Ross Lawley Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Whilst debugging async I noticed:

        final CountDownLatch current = phase.getAndSet(new CountDownLatch(1));
        current.countDown();

https://github.com/mongodb/mongo-java-driver/blob/master/src/main/com/mongodb/BaseCluster.java#L192-L193

getAndSet returns the previous value - so is the countdown wrong or should it be the new phase thats counted down?



 Comments   
Comment by Jeffrey Yemin [ 07/Dec/15 ]

The 3.2.0 driver, which contains a fix for this issue, has been released today.

Comment by Githook User [ 25/Nov/15 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-1574: Inline local variable with a confusing name
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/755cfc9c0c92ed1a035378039c16364611661f4b

Comment by Ross Lawley [ 28/Nov/14 ]

ok getAndSet returns the old latch and not the newly set one which is why the name "current" is confusing as its the previous latch thats counted down.

Propose change to:

phase.getAndSet(new CountDownLatch(1)).countDown();

Comment by Jeffrey Yemin [ 28/Nov/14 ]

This code is correct. Operations needing a server are waiting on the current latch so that's the one that needs to be counted down.

Generated at Thu Feb 08 08:54:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.