Hi,
I had a look at contrib/extensions/feature-flags and I'm wondering
about how to cope with a potentially null ClientContext.
IIUC the usage scenario is
1) Call Features.createClientContext(...) somewhere
2) Rendering or other code can then call
Features.getCurrentClientContext().isEnabled("feature.name") for
example
But Features.getCurrentClientContext() can return null which would
cause an NPE at 2)
I see two ways to avoid requiring null checks on every call:
a) add a "required" argument:
ClientContext getCurrentClientContext(boolean required);
If required==true and no ClientContext is available, a descriptive
Exception is thrown.
b) If ClientContext hasn't been setup, getCurrentClientContext()
returns a NullClientContext that throws descriptive Exceptions when
used.
If we assume code that almost all calls to getCurrentClientContext()
expect a context to have been setup, that avoids the extra argument.
WDYT?
-Bertrand