Skip to content

Commit

Permalink
core: fix NPE in TryCatchTemplate
Browse files Browse the repository at this point in the history
Motivation:

The TryCatchTemplate is meant to be composable, allowing different
components to "wrap" an existing TryCatchTemplate.  However, this
currently only works if the instantiated TryCatchTemplate overrides the
`execute` or `executeWithCancellable` methods.  "Out of the box" the
class results in a NPE.

Modification:

Update TryCatchTemplate so it doesn't throw NPE when neither the
`execute` or `executeWithCancellable` method is overridden.

Result:

No user or admin observable changes, but the code behaves more
correctly.

Target: master
Requires-notes: no
Requires-book: no
Patch: https://rb.dcache.org/r/13097/
Acked-by: Albert Rossi
Acked-by: Lea Morschel
  • Loading branch information
paulmillar committed Jul 28, 2021
1 parent 0c19f64 commit a6a096d
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import com.google.common.io.Closer;

import javax.annotation.Nonnull;

import java.io.Closeable;
import java.nio.channels.CompletionHandler;

Expand Down Expand Up @@ -174,9 +176,10 @@ protected void execute() throws Exception
* An implementation should not call {@code completed} or {@code setCancellable} from within
* {@code executeWithCancellable}.
*/
@Nonnull
protected Cancellable executeWithCancellable() throws Exception
{
return null;
return msg -> {};
}

/**
Expand Down

0 comments on commit a6a096d

Please sign in to comment.