Skip to content

Commit a71ebdf

Browse files
committed
Fix a bug with Cancelable#cancel(String)
The various implementations of this method (which are all copy-pasted from one another, due to Java's single inheritance limitations) all suffered from the same bug: calling `cancel(null)` would not actually cancel the operation. Actually, this was the intended design (so you could potentially "uncancel" an operation), but I decided that: 1. Uncanceling is not something anyone should need to do; 2. It violates the PoLA for `cancel(null)` not to cancel things; 3. The ModuleRunner calls `cancel(e.getMessage())` from a caught ModuleException, which wouldn't actually cancel the module execution if the exception had a null message, which it did thanks to the AbstractInputHarvester doing `throw new ModuleCanceledException()`.
1 parent 9c19ffc commit a71ebdf

File tree

5 files changed

+6
-5
lines changed

5 files changed

+6
-5
lines changed

src/main/java/org/scijava/command/ContextCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public boolean isCanceled() {
9696
/** Cancels the command execution, with the given reason for doing so. */
9797
@Override
9898
public void cancel(final String reason) {
99-
cancelReason = reason;
99+
cancelReason = reason == null ? "" : reason;
100100
}
101101

102102
@Override

src/main/java/org/scijava/command/DynamicCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public boolean isCanceled() {
131131

132132
@Override
133133
public void cancel(final String reason) {
134-
cancelReason = reason;
134+
cancelReason = reason == null ? "" : reason;
135135
}
136136

137137
@Override

src/main/java/org/scijava/command/ModuleCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ public boolean isCanceled() {
9292

9393
@Override
9494
public void cancel(final String reason) {
95-
cancelReason = reason;
95+
cancelReason = reason == null ? "" : reason;
9696
}
97+
9798
@Override
9899
public String getCancelReason() {
99100
return cancelReason;

src/main/java/org/scijava/module/process/AbstractPreprocessorPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public boolean isCanceled() {
5353

5454
@Override
5555
public void cancel(final String reason) {
56-
cancelReason = reason;
56+
cancelReason = reason == null ? "" : reason;
5757
}
5858

5959
@Override

src/main/java/org/scijava/ui/AbstractInputHarvesterPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public boolean isCanceled() {
8989

9090
@Override
9191
public void cancel(final String reason) {
92-
cancelReason = reason;
92+
cancelReason = reason == null ? "" : reason;
9393
}
9494

9595
@Override

0 commit comments

Comments
 (0)