Skip to content

Commit

Permalink
One more fix for avoid NPE (eclipse-che#5121)
Browse files Browse the repository at this point in the history
Signed-off-by: Vitalii Parfonov <vparfonov@codenvy.com>
  • Loading branch information
Vitalii Parfonov committed May 18, 2017
1 parent ebb3a8c commit 258ba74
Showing 1 changed file with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void stop() {
}
}

boolean isStopped(){
boolean isStopped() {
return executor.isShutdown();
}

Expand All @@ -186,21 +186,23 @@ boolean isStopped(){
* directory
*/
public void register(Path dir) {
if (!Files.exists(dir)) {
LOG.debug("Trying to register directory '{}' but it does not exist", dir);
return;
}
LOG.debug("Registering directory '{}'", dir);
if (keys.values().contains(dir)) {
int previous = registrations.get(dir);
LOG.debug("Directory is already being watched, increasing watch counter, previous value: {}", previous);
registrations.put(dir, previous + 1);
} else {
if (Files.exists(dir)) {
try {
LOG.debug("Starting watching directory '{}'", dir);
WatchKey watchKey = dir.register(service, eventKinds, eventModifiers);
keys.put(watchKey, dir);
registrations.put(dir, 1);
} catch (IOException e) {
LOG.error("Can't register dir {} in file watch service", dir, e);
}
try {
LOG.debug("Starting watching directory '{}'", dir);
WatchKey watchKey = dir.register(service, eventKinds, eventModifiers);
keys.put(watchKey, dir);
registrations.put(dir, 1);
} catch (IOException e) {
LOG.error("Can't register dir {} in file watch service", dir, e);
}
}
}
Expand All @@ -210,9 +212,9 @@ public void register(Path dir) {
* method decreases by one registration counter that corresponds to
* directory specified by the argument. If registration counter comes to
* zero directory watching is totally cancelled.
*
* <p>
* If this method is called for not existing directory nothing happens.
*
* <p>
* If this method is called for not registered directory nothing happens.
*
* @param dir
Expand Down Expand Up @@ -324,8 +326,9 @@ private void run() {

private void resetAndRemove(WatchKey watchKey, Path dir) {
if (!watchKey.reset()) {
registrations.remove(dir);

if (dir != null) {
registrations.remove(dir);
}
keys.remove(watchKey);
}
}
Expand Down

0 comments on commit 258ba74

Please sign in to comment.