Skip to content

Commit 17ead5d

Browse files
committed
OpenArgument: make all services optional
And do not handle the argument if any are missing. This pattern reduces the likelihood of plugin initialization errors when the context does not contain all needed services.
1 parent 9c9add3 commit 17ead5d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/main/java/org/scijava/io/console/OpenArgument.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@
5151
@Plugin(type = ConsoleArgument.class)
5252
public class OpenArgument extends AbstractConsoleArgument {
5353

54-
@Parameter
54+
@Parameter(required = false)
5555
private IOService ioService;
5656

57-
@Parameter
57+
@Parameter(required = false)
5858
private DisplayService displayService;
5959

60-
@Parameter
60+
@Parameter(required = false)
6161
private LogService log;
6262

6363
// -- Constructor --
@@ -80,7 +80,14 @@ public void handle(final LinkedList<String> args) {
8080
displayService.createDisplay(o);
8181
}
8282
catch (IOException exc) {
83-
log.error(exc);
83+
if (log != null) log.error(exc);
8484
}
8585
}
86+
87+
// -- Typed methods --
88+
89+
@Override
90+
public boolean supports(final LinkedList<String> args) {
91+
return ioService != null && displayService != null && super.supports(args);
92+
}
8693
}

0 commit comments

Comments
 (0)