Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
Avoid NPE in the scheduled future.
Browse files Browse the repository at this point in the history
see #106

Signed-off-by: Stéphane Galland <[email protected]>
  • Loading branch information
gallandarakhneorg committed Nov 29, 2015
1 parent f367cf1 commit 890804a
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class JdkJanusScheduledFutureTask<V> implements JanusScheduledFutureTask<V> {
* @param task - the JRE task that must be wrapped into the particular Janus implementation.
*/
JdkJanusScheduledFutureTask(RunnableScheduledFuture<V> task) {
assert (task != null);
this.task = task;
}

Expand All @@ -71,8 +72,12 @@ public String toString() {
*
* @param thread - thread which is running this task.
*/
void setThread(Thread thread) {
this.thread = new WeakReference<>(thread);
synchronized void setThread(Thread thread) {
if (thread == null) {
this.thread = null;
} else {
this.thread = new WeakReference<>(thread);
}
}

/** Report the exception if one.
Expand All @@ -99,13 +104,13 @@ void reportException(Thread thread) {
}

@Override
public Thread getThread() {
return this.thread.get();
public synchronized Thread getThread() {
return (this.thread == null) ? null : this.thread.get();
}

@Override
public boolean isCurrentThread() {
return Thread.currentThread() == this.thread.get();
return Thread.currentThread() == getThread();
}

@Override
Expand Down

0 comments on commit 890804a

Please sign in to comment.