Skip to content

Commit adf4e78

Browse files
eolivellianmolnar
authored andcommitted
ZOOKEEPER-3223: Configure Spotbugs - on branch 3.4
- add spotbugs configuration (default) - make build pass spotbugs Fix errors: [ERROR] Increment of volatile field org.apache.zookeeper.server.quorum.AuthFastLeaderElection.logicalclock in org.apache.zookeeper.server.quorum.AuthFastLeaderElection.leaveInstance() [org.apache.zookeeper.server.quorum.AuthFastLeaderElection] At AuthFastLeaderElection.java:[line 780] VO_VOLATILE_INCREMENT [ERROR] Increment of volatile field org.apache.zookeeper.server.quorum.AuthFastLeaderElection.logicalclock in org.apache.zookeeper.server.quorum.AuthFastLeaderElection.lookForLeader() [org.apache.zookeeper.server.quorum.AuthFastLeaderElection] At AuthFastLeaderElection.java:[line 854] VO_VOLATILE_INCREMENT [ERROR] Switch statement found in org.apache.zookeeper.server.quorum.AuthFastLeaderElection$Messenger$WorkerReceiver.run() where default case is missing [org.apache.zookeeper.server.quorum.AuthFastLeaderElection$Messenger$WorkerReceiver] At AuthFastLeaderElection.java:[lines 270-278] SF_SWITCH_NO_DEFAULT [ERROR] Switch statement found in org.apache.zookeeper.server.quorum.AuthFastLeaderElection$Messenger$WorkerSender.process(AuthFastLeaderElection$ToSend) where default case is missing [org.apache.zookeeper.server.quorum.AuthFastLeaderElection$Messenger$WorkerSender] At AuthFastLeaderElection.java:[lines 468-700] SF_SWITCH_NO_DEFAULT [ERROR] Unread field: org.apache.zookeeper.server.quorum.LearnerSessionTracker.expirer [org.apache.zookeeper.server.quorum.LearnerSessionTracker] At LearnerSessionTracker.java:[line 45] URF_UNREAD_FIELD [ERROR] org.apache.zookeeper.server.quorum.QuorumPeer.writeLongToFile(String, long) may fail to close stream [org.apache.zookeeper.server.quorum.QuorumPeer] At QuorumPeer.java:[line 1387] OS_OPEN_STREAM [ERROR] Inconsistent synchronization of org.apache.zookeeper.server.upgrade.DataNodeV1.data; locked 50% of time [org.apache.zookeeper.server.upgrade.DataNodeV1, org.apache.zookeeper.server.upgrade.DataNodeV1, org.apache.zookeeper.server.upgrade.UpgradeSnapShotV1, org.apache.zookeeper.server.upgrade.DataNodeV1, org.apache.zookeeper.server.upgrade.DataTreeV1, org.apache.zookeeper.server.upgrade.DataTreeV1] Unsynchronized access at DataNodeV1.java:[line 98]Unsynchronized access at DataNodeV1.java:[line 91]Unsynchronized access at UpgradeSnapShotV1.java:[line 270]Synchronized access at DataNodeV1.java:[line 118]Synchronized access at DataTreeV1.java:[line 263]Synchronized access at DataTreeV1.java:[line 283] IS2_INCONSISTENT_SYNC [ERROR] Dead store to $L9 in org.apache.zookeeper.server.upgrade.DataTreeV1.processTxn(TxnHeader, Record) [org.apache.zookeeper.server.upgrade.DataTreeV1] At DataTreeV1.java:[line 417] DLS_DEAD_LOCAL_STORE [ERROR] Switch statement found in org.apache.zookeeper.server.upgrade.DataTreeV1.processTxn(TxnHeader, Record) where default case is missing [org.apache.zookeeper.server.upgrade.DataTreeV1] At DataTreeV1.java:[lines 392-417] SF_SWITCH_NO_DEFAULT [ERROR] org.apache.zookeeper.server.upgrade.DataTreeV1.dumpEphemerals() makes inefficient use of keySet iterator instead of entrySet iterator [org.apache.zookeeper.server.upgrade.DataTreeV1] At DataTreeV1.java:[line 545] WMI_WRONG_MAP_ITERATOR [ERROR] Inconsistent synchronization of org.apache.zookeeper.recipes.leader.LeaderElectionSupport.hostName; locked 60% of time [org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport] Unsynchronized access at LeaderElectionSupport.java:[line 441]Unsynchronized access at LeaderElectionSupport.java:[line 445]Synchronized access at LeaderElectionSupport.java:[line 185]Synchronized access at LeaderElectionSupport.java:[line 186]Synchronized access at LeaderElectionSupport.java:[line 138]Synchronized access at LeaderElectionSupport.java:[line 387] IS2_INCONSISTENT_SYNC [ERROR] Inconsistent synchronization of org.apache.zookeeper.recipes.leader.LeaderElectionSupport.leaderOffer; locked 53% of time [org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport, org.apache.zookeeper.recipes.leader.LeaderElectionSupport] Unsynchronized access at LeaderElectionSupport.java:[line 201]Unsynchronized access at LeaderElectionSupport.java:[line 203]Unsynchronized access at LeaderElectionSupport.java:[line 218]Unsynchronized access at LeaderElectionSupport.java:[line 339]Unsynchronized access at LeaderElectionSupport.java:[line 273]Unsynchronized access at LeaderElectionSupport.java:[line 240]Synchronized access at LeaderElectionSupport.java:[line 165]Synchronized access at LeaderElectionSupport.java:[line 167]Synchronized access at LeaderElectionSupport.java:[line 168]Synchronized access at LeaderElectionSupport.java:[line 183]Synchronized access at LeaderElectionSupport.java:[line 185]Synchronized access at LeaderElectionSupport.java:[line 186]Synchronized access at LeaderElectionSupport.java:[line 190]Synchronized access at LeaderElectionSupport.java:[line 387] IS2_INCONSISTENT_SYNC [ERROR] org.apache.zookeeper.recipes.leader.LeaderOffer$IdComparator implements Comparator but not Serializable [org.apache.zookeeper.recipes.leader.LeaderOffer$IdComparator] At LeaderOffer.java:[lines 75-79] SE_COMPARATOR_SHOULD_BE_SERIALIZABLE [INFO] Author: Enrico Olivelli <eolivelli@apache.org> Reviewers: andor@apache.org Closes apache#764 from eolivelli/fix/ZOOKEEPER-3223-branch-3.4 and squashes the following commits: 488925d [Enrico Olivelli] Upgrade to spotbugs 3.1.9 66f43cd [Enrico Olivelli] Suppress IS2_INCONSISTENT_SYNC on DataNodeV1#data 716e269 [Enrico Olivelli] revert synchronized blocks on core code 13415fb [Enrico Olivelli] Remove unused imports 8079261 [Enrico Olivelli] Fix recipes and disable spotbugs on contrib b6dac05 [Enrico Olivelli] Fix spotbugs errors febc57b [Enrico Olivelli] ZOOKEEPER-3223: Configure Spotbugs
1 parent 00db0cc commit adf4e78

File tree

21 files changed

+183
-73
lines changed

21 files changed

+183
-73
lines changed

build.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ xmlns:cs="antlib:com.puppycrawl.tools.checkstyle">
2727
<!-- Dependency versions -->
2828
<!-- ====================================================== -->
2929
<property name="slf4j.version" value="1.7.25"/>
30+
<property name="spotbugsannotations.version" value="3.1.9"/>
3031

3132
<property name="wagon-http.version" value="2.4"/>
3233
<property name="maven-ant-tasks.version" value="2.1.3"/>

excludeFindBugsFilter.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<FindBugsFilter>
4+
<!-- this work work on JDK11 https://github.com/spotbugs/spotbugs-maven-plugin/issues/92 -->
5+
<Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"/>
6+
7+
<!-- this problem is to be addressed in ZOOKEEPER-3227 -->
8+
<Bug pattern="DM_DEFAULT_ENCODING"/>
9+
10+
<!-- not really a problem -->
11+
<Bug pattern="DM_EXIT"/>
12+
13+
</FindBugsFilter>
14+

ivy.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<dependencies>
4545
<dependency org="org.slf4j" name="slf4j-api" rev="${slf4j.version}"/>
4646
<dependency org="org.slf4j" name="slf4j-log4j12" rev="${slf4j.version}" transitive="false"/>
47-
47+
<dependency org="com.github.spotbugs" name="spotbugs-annotations" rev="${spotbugsannotations.version}" />
4848
<dependency org="org.apache.maven.wagon" name="wagon-http" rev="${wagon-http.version}"
4949
conf="mvn-ant-task->default"/>
5050
<dependency org="org.apache.maven" name="maven-ant-tasks" rev="${maven-ant-tasks.version}"

pom.xml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281
<commons-lang.version>2.4</commons-lang.version>
282282
<apache-directory-server.version>2.0.0-M15</apache-directory-server.version>
283283
<apache-directory-api.version>1.0.0-M20</apache-directory-api.version>
284+
<spotbugsannotations.version>3.1.9</spotbugsannotations.version>
284285
</properties>
285286

286287
<dependencyManagement>
@@ -654,6 +655,13 @@
654655
</exclusion>
655656
</exclusions>
656657
</dependency>
658+
<dependency>
659+
<groupId>com.github.spotbugs</groupId>
660+
<artifactId>spotbugs-annotations</artifactId>
661+
<version>${spotbugsannotations.version}</version>
662+
<scope>provided</scope>
663+
<optional>true</optional>
664+
</dependency>
657665
</dependencies>
658666
</dependencyManagement>
659667

@@ -710,6 +718,14 @@
710718
<artifactId>maven-install-plugin</artifactId>
711719
<version>3.0.0-M1</version>
712720
</plugin>
721+
<plugin>
722+
<groupId>com.github.spotbugs</groupId>
723+
<artifactId>spotbugs-maven-plugin</artifactId>
724+
<version>3.1.9</version>
725+
<configuration>
726+
<excludeFilterFile>excludeFindBugsFilter.xml</excludeFilterFile>
727+
</configuration>
728+
</plugin>
713729
</plugins>
714730
</pluginManagement>
715731

@@ -737,7 +753,11 @@
737753
</execution>
738754
</executions>
739755
</plugin>
740-
</plugins>
756+
<plugin>
757+
<groupId>com.github.spotbugs</groupId>
758+
<artifactId>spotbugs-maven-plugin</artifactId>
759+
</plugin>
760+
</plugins>
741761
</build>
742762

743763
<reporting>

zookeeper-contrib/pom.xml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,25 @@
3434
<description>
3535
Contrib projects to Apache ZooKeeper
3636
</description>
37-
37+
<build>
38+
<pluginManagement>
39+
<plugins>
40+
<plugin>
41+
<groupId>com.github.spotbugs</groupId>
42+
<artifactId>spotbugs-maven-plugin</artifactId>
43+
<version>3.1.9</version>
44+
<configuration>
45+
<!-- No spotbugs for contri modules -->
46+
<skip>true</skip>
47+
</configuration>
48+
</plugin>
49+
</plugins>
50+
</pluginManagement>
51+
</build>
3852
<modules>
3953
<module>zookeeper-contrib-loggraph</module>
4054
<module>zookeeper-contrib-rest</module>
4155
<module>zookeeper-contrib-zooinspector</module>
4256
</modules>
4357

44-
</project>
58+
</project>

zookeeper-jute/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@
145145
</execution>
146146
</executions>
147147
</plugin>
148+
<plugin>
149+
<!-- spotbugs does not make sense for generated code -->
150+
<groupId>com.github.spotbugs</groupId>
151+
<artifactId>spotbugs-maven-plugin</artifactId>
152+
<configuration>
153+
<skip>true</skip>
154+
</configuration>
155+
</plugin>
148156
</plugins>
149157
</build>
150158

zookeeper-recipes/zookeeper-recipes-election/src/main/java/org/apache/zookeeper/recipes/leader/LeaderElectionSupport.java

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,27 +180,37 @@ private void makeOffer() throws KeeperException, InterruptedException {
180180
state = State.OFFER;
181181
dispatchEvent(EventType.OFFER_START);
182182

183-
leaderOffer = new LeaderOffer();
184-
185-
leaderOffer.setHostName(hostName);
186-
leaderOffer.setNodePath(zooKeeper.create(rootNodeName + "/" + "n_",
187-
hostName.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
183+
LeaderOffer newLeaderOffer = new LeaderOffer();
184+
byte[] hostnameBytes;
185+
synchronized (this) {
186+
newLeaderOffer.setHostName(hostName);
187+
hostnameBytes = hostName.getBytes();
188+
newLeaderOffer.setNodePath(zooKeeper.create(rootNodeName + "/" + "n_",
189+
hostnameBytes, ZooDefs.Ids.OPEN_ACL_UNSAFE,
188190
CreateMode.EPHEMERAL_SEQUENTIAL));
189-
190-
logger.debug("Created leader offer {}", leaderOffer);
191-
191+
leaderOffer = newLeaderOffer;
192+
}
193+
194+
logger.debug("Created leader offer {}", newLeaderOffer);
195+
192196
dispatchEvent(EventType.OFFER_COMPLETE);
193197
}
198+
199+
private synchronized LeaderOffer getLeaderOffer() {
200+
return leaderOffer;
201+
}
194202

195203
private void determineElectionStatus() throws KeeperException,
196204
InterruptedException {
197205

198206
state = State.DETERMINE;
199207
dispatchEvent(EventType.DETERMINE_START);
200208

201-
String[] components = leaderOffer.getNodePath().split("/");
209+
LeaderOffer currentLeaderOffer = getLeaderOffer();
210+
211+
String[] components = currentLeaderOffer.getNodePath().split("/");
202212

203-
leaderOffer.setId(Integer.valueOf(components[components.length - 1]
213+
currentLeaderOffer.setId(Integer.valueOf(components[components.length - 1]
204214
.substring("n_".length())));
205215

206216
List<LeaderOffer> leaderOffers = toLeaderOffers(zooKeeper.getChildren(
@@ -215,7 +225,7 @@ private void determineElectionStatus() throws KeeperException,
215225
for (int i = 0; i < leaderOffers.size(); i++) {
216226
LeaderOffer leaderOffer = leaderOffers.get(i);
217227

218-
if (leaderOffer.getId().equals(this.leaderOffer.getId())) {
228+
if (leaderOffer.getId().equals(currentLeaderOffer.getId())) {
219229
logger.debug("There are {} leader offers. I am {} in line.",
220230
leaderOffers.size(), i);
221231

@@ -238,7 +248,7 @@ private void becomeReady(LeaderOffer neighborLeaderOffer)
238248
dispatchEvent(EventType.READY_START);
239249

240250
logger.info("{} not elected leader. Watching node:{}",
241-
leaderOffer.getNodePath(), neighborLeaderOffer.getNodePath());
251+
getLeaderOffer().getNodePath(), neighborLeaderOffer.getNodePath());
242252

243253
/*
244254
* Make sure to pass an explicit Watcher because we could be sharing this
@@ -270,7 +280,7 @@ private void becomeLeader() {
270280
state = State.ELECTED;
271281
dispatchEvent(EventType.ELECTED_START);
272282

273-
logger.info("Becoming leader with node:{}", leaderOffer.getNodePath());
283+
logger.info("Becoming leader with node:{}", getLeaderOffer().getNodePath());
274284

275285
dispatchEvent(EventType.ELECTED_COMPLETE);
276286
}
@@ -336,7 +346,7 @@ private List<LeaderOffer> toLeaderOffers(List<String> strings)
336346
@Override
337347
public void process(WatchedEvent event) {
338348
if (event.getType().equals(Watcher.Event.EventType.NodeDeleted)) {
339-
if (!event.getPath().equals(leaderOffer.getNodePath())
349+
if (!event.getPath().equals(getLeaderOffer().getNodePath())
340350
&& state != State.STOP) {
341351
logger.debug(
342352
"Node {} deleted. Need to run through the election process.",
@@ -384,8 +394,8 @@ public void removeListener(LeaderElectionAware listener) {
384394

385395
@Override
386396
public String toString() {
387-
return "{ state:" + state + " leaderOffer:" + leaderOffer + " zooKeeper:"
388-
+ zooKeeper + " hostName:" + hostName + " listeners:" + listeners
397+
return "{ state:" + state + " leaderOffer:" + getLeaderOffer() + " zooKeeper:"
398+
+ zooKeeper + " hostName:" + getHostName() + " listeners:" + listeners
389399
+ " }";
390400
}
391401

@@ -437,11 +447,11 @@ public void setZooKeeper(ZooKeeper zooKeeper) {
437447
* The hostname of this process. Mostly used as a convenience for logging and
438448
* to respond to {@link #getLeaderHostName()} requests.
439449
*/
440-
public String getHostName() {
450+
public synchronized String getHostName() {
441451
return hostName;
442452
}
443453

444-
public void setHostName(String hostName) {
454+
public synchronized void setHostName(String hostName) {
445455
this.hostName = hostName;
446456
}
447457

zookeeper-recipes/zookeeper-recipes-election/src/main/java/org/apache/zookeeper/recipes/leader/LeaderOffer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.zookeeper.recipes.leader;
1818

19+
import java.io.Serializable;
1920
import java.util.Comparator;
2021

2122
/**
@@ -72,7 +73,8 @@ public void setHostName(String hostName) {
7273
* Compare two instances of {@link LeaderOffer} using only the {code}id{code}
7374
* member.
7475
*/
75-
public static class IdComparator implements Comparator<LeaderOffer> {
76+
public static final class IdComparator
77+
implements Comparator<LeaderOffer>, Serializable {
7678

7779
@Override
7880
public int compare(LeaderOffer o1, LeaderOffer o2) {

zookeeper-recipes/zookeeper-recipes-lock/pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
<type>test-jar</type>
4848
<scope>test</scope>
4949
</dependency>
50+
<dependency>
51+
<groupId>com.github.spotbugs</groupId>
52+
<artifactId>spotbugs-annotations</artifactId>
53+
<version>3.1.9</version>
54+
<scope>provided</scope>
55+
<optional>true</optional>
56+
</dependency>
5057
</dependencies>
5158

5259
<build>
@@ -71,4 +78,4 @@
7178
</plugins>
7279
</build>
7380

74-
</project>
81+
</project>

zookeeper-recipes/zookeeper-recipes-lock/src/main/java/org/apache/zookeeper/recipes/lock/WriteLock.java

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.apache.zookeeper.recipes.lock;
1919

20+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2021
import org.slf4j.Logger;
2122
import org.slf4j.LoggerFactory;
2223
import org.apache.zookeeper.KeeperException;
@@ -85,15 +86,15 @@ public WriteLock(ZooKeeper zookeeper, String dir, List<ACL> acl,
8586
* return the current locklistener
8687
* @return the locklistener
8788
*/
88-
public LockListener getLockListener() {
89+
public synchronized LockListener getLockListener() {
8990
return this.callback;
9091
}
9192

9293
/**
9394
* register a different call back listener
9495
* @param callback the call back instance
9596
*/
96-
public void setLockListener(LockListener callback) {
97+
public synchronized void setLockListener(LockListener callback) {
9798
this.callback = callback;
9899
}
99100

@@ -201,7 +202,9 @@ private void findPrefixInChildren(String prefix, ZooKeeper zookeeper, String dir
201202
* obtaining the lock
202203
* @return if the command was successful or not
203204
*/
204-
public boolean execute() throws KeeperException, InterruptedException {
205+
@SuppressFBWarnings(value = "NP_NULL_PARAM_DEREF_NONVIRTUAL",
206+
justification = "findPrefixInChildren will assign a value to this.id")
207+
public final boolean execute() throws KeeperException, InterruptedException {
205208
do {
206209
if (id == null) {
207210
long sessionId = zookeeper.getSessionId();
@@ -210,45 +213,44 @@ public boolean execute() throws KeeperException, InterruptedException {
210213
// in the middle of creating the znode
211214
findPrefixInChildren(prefix, zookeeper, dir);
212215
idName = new ZNodeName(id);
213-
}
214-
if (id != null) {
215-
List<String> names = zookeeper.getChildren(dir, false);
216-
if (names.isEmpty()) {
217-
LOG.warn("No children in: " + dir + " when we've just " +
218-
"created one! Lets recreate it...");
219-
// lets force the recreation of the id
220-
id = null;
221-
} else {
222-
// lets sort them explicitly (though they do seem to come back in order ususally :)
223-
SortedSet<ZNodeName> sortedNames = new TreeSet<ZNodeName>();
224-
for (String name : names) {
225-
sortedNames.add(new ZNodeName(dir + "/" + name));
216+
}
217+
List<String> names = zookeeper.getChildren(dir, false);
218+
if (names.isEmpty()) {
219+
LOG.warn("No children in: " + dir + " when we've just " +
220+
"created one! Lets recreate it...");
221+
// lets force the recreation of the id
222+
id = null;
223+
} else {
224+
// lets sort them explicitly (though they do seem to come back in order ususally :)
225+
SortedSet<ZNodeName> sortedNames = new TreeSet<ZNodeName>();
226+
for (String name : names) {
227+
sortedNames.add(new ZNodeName(dir + "/" + name));
228+
}
229+
ownerId = sortedNames.first().getName();
230+
SortedSet<ZNodeName> lessThanMe = sortedNames.headSet(idName);
231+
if (!lessThanMe.isEmpty()) {
232+
ZNodeName lastChildName = lessThanMe.last();
233+
lastChildId = lastChildName.getName();
234+
if (LOG.isDebugEnabled()) {
235+
LOG.debug("watching less than me node: " + lastChildId);
226236
}
227-
ownerId = sortedNames.first().getName();
228-
SortedSet<ZNodeName> lessThanMe = sortedNames.headSet(idName);
229-
if (!lessThanMe.isEmpty()) {
230-
ZNodeName lastChildName = lessThanMe.last();
231-
lastChildId = lastChildName.getName();
232-
if (LOG.isDebugEnabled()) {
233-
LOG.debug("watching less than me node: " + lastChildId);
234-
}
235-
Stat stat = zookeeper.exists(lastChildId, new LockWatcher());
236-
if (stat != null) {
237-
return Boolean.FALSE;
238-
} else {
239-
LOG.warn("Could not find the" +
240-
" stats for less than me: " + lastChildName.getName());
241-
}
237+
Stat stat = zookeeper.exists(lastChildId, new LockWatcher());
238+
if (stat != null) {
239+
return Boolean.FALSE;
242240
} else {
243-
if (isOwner()) {
244-
if (callback != null) {
245-
callback.lockAcquired();
246-
}
247-
return Boolean.TRUE;
241+
LOG.warn("Could not find the" +
242+
" stats for less than me: " + lastChildName.getName());
243+
}
244+
} else {
245+
if (isOwner()) {
246+
LockListener lockListener = getLockListener();
247+
if (lockListener != null) {
248+
lockListener.lockAcquired();
248249
}
250+
return Boolean.TRUE;
249251
}
250252
}
251-
}
253+
}
252254
}
253255
while (id == null);
254256
return Boolean.FALSE;
@@ -292,5 +294,6 @@ public boolean isOwner() {
292294
public String getId() {
293295
return this.id;
294296
}
297+
295298
}
296299

0 commit comments

Comments
 (0)