Hmm, you raise an interesting point. So I guess the situation is more variegated:
1) If you have a locale calculator that works per-request and does not have an app default, then it is definitely incorrect to call S.? out of a request context,
2) but if you have one that works app-wide then it should work -- but doesn't, unless you call S.init or one of those by yourself,
3) so my proposed error is not good.
It would be nice to catch uses of S.? outside of a request context when your intended behavior is that you only have per-request locales, so I guess if that is the desire then one should make their locale calculator log the error text, and the change to lift should be something more like:
def resourceBundles: List[ResourceBundle] = {
- _resBundle.value match {
- case Nil => {
+ _resBundle.box match {
+ case Full(bundles) if !bundles.isEmpty => bundles
+ case _ => {
_resBundle.set(LiftRules.resourceNames.flatMap(name => tryo(
List(ResourceBundle.getBundle(name, locale))
).openOr(
NamedPF.applyBox((name, locale), LiftRules.resourceBundleFactories.toList).map(List(_)) openOr Nil
)))
_resBundle.value
}
- case bundles => bundles
}
}
That is, if the _resBundle ThreadGlobal has not been initialized yet, or it's been initialized with the empty list, then do resource bundle loading. If it has been initialized with a non-empty list then use that.
I don't think this should interact badly with S.init, since S.init uses _resBundle.doWith(Nil) ... which will both overwrite any loaded "app-level" bundles with the empty list, but also restore them upon completion of the S scope.
-Ross