Skip to content

Commit

Permalink
nearline-storage: fix NPE on error path
Browse files Browse the repository at this point in the history
Motivation:
The AbstractBlockingNearlineStorage.Task#run uses thread bind-release
mechanist to associate a task with a thread. Finally, a catch block is
used to process uncaught exception with the bound thread. However, the
`release` call between releases the bound thread, which is a source of
NPE:

```
try {
  bind(); // thread = Thread.currentThread()

  ...

  release(); // thread = null;

} catch( Throwable t) {
  thread.uncaughtException(thread, e);
}
```

java.lang.NullPointerException: null
        at org.dcache.pool.nearline.AbstractBlockingNearlineStorage$Task.run(AbstractBlockingNearlineStorage.java:390)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)

Modification:
make sure that uncaughtException is executed by current thread,
independent of it's binding state. Change the variable name to avoid
method variable and class field name conflict.

Result:
No NPE

Ref: #6426
Acked-by: Marina Sahakyan
Target: master, 8.2, 8.1, 8.0, 7.2
Require-book: no
Require-notes: yes
(cherry picked from commit b708a6c)
Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
  • Loading branch information
kofemann authored and mksahakyan committed Nov 16, 2022
1 parent 4c432f2 commit b663601
Showing 1 changed file with 3 additions and 3 deletions.
Expand Up @@ -348,9 +348,9 @@ private synchronized boolean activate() {
}

public void run() {
Thread currentThread = Thread.currentThread();
try {
Thread thread = Thread.currentThread();
if (bind(thread)) {
if (bind(currentThread)) {
boolean isSuccess = false;
T result = null;
try {
Expand Down Expand Up @@ -386,7 +386,7 @@ public void run() {
}
}
} catch (Throwable e) {
thread.getUncaughtExceptionHandler().uncaughtException(thread, e);
currentThread.getUncaughtExceptionHandler().uncaughtException(currentThread, e);
}
}

Expand Down

0 comments on commit b663601

Please sign in to comment.