From costin (at springsource):
I've experienced an issue with setting a Servlet Attribute before a Context is started.
I've noticed that the ContextHandler has two attribute maps which are used for retrieving ServletContexts attributes.
However, when a Context is started, its local map is created and setting an attribute before simply returns (suggesting that everything is okay).
However, getting the attribute names or removing an attribute throws a NPE since there is no null check:
setAttribute (line 1401):
if (_contextAttributes==null)
return;
getAttributeNames (line 1384) {
Enumeration e = _contextAttributes.getAttributeNames();
}
In my case, I'm trying to set an attribute before the context is started through the ServletContext and currently I can't. I can use the ContextHandler interface but that ties me to Jetty.
Would you consider using as fall back the _attributes field if _contextAttributes is null (context not started)? This way the current behaviour will be preserved meaning that listeners will be called only for attributes registered after the context is started.