Skip to content

Commit b39610e

Browse files
committed
Context: add sys prop to override strictness
If you want context creation to be lax by default, you can now set scijava.context.strict=false and the fail-fast behavior will be disabled by default.
1 parent 32f0fe4 commit b39610e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/main/java/org/scijava/Context.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@
5858
*/
5959
public class Context implements Disposable {
6060

61+
// -- Constants --
62+
63+
/**
64+
* System property indicating whether the context should fail fast when
65+
* is attempts to instantiate a required service which is invalid or missing.
66+
* If this property is set to "false" then the context creation will attempt
67+
* to continue even when a required service cannot be instantiated. Otherwise,
68+
* the constructor will throw an {@link IllegalArgumentException} in that situation.
69+
*/
70+
public static final String STRICT_PROPERTY = "scijava.context.strict";
71+
6172
// -- Fields --
6273

6374
/** Index of the application context's services. */
@@ -393,7 +404,7 @@ private String createMissingServiceMessage(
393404
}
394405

395406
private static boolean strict() {
396-
return true;
407+
return !"false".equals(System.getProperty(STRICT_PROPERTY));
397408
}
398409

399410
}

0 commit comments

Comments
 (0)