null pointer exception at <component>.beforeClientResponse

I’m getting a null pointer exception sporadically at this point of beforeClientResponse:

super.beforeClientResponse(initial);
HashMap<String, Object> styleA = new HashMap<String,Object>();
styleA.putAll(ctrl.getStyles());
getState().width = width;
getState().height = height;

getState().ns = (Integer) styleA.get(“ns”); <===== null ptr exception.

not sure why it happens not on a regular basis.

Well, clearly your ctrl.getStyles() (whatever that is) sometimes does not include the key “ns”. Impossible to say anything else without knowing more about the code.

I guess my real question is when is beforeClientReponse called? It seems like it wasn’t consistent in all cases otherwise I would get this null ptr exception all the time which I don’t even if I follow the same steps in my program, “step A, step B, etc”. I found this on one of the vaadin wiki’s :

Please note that beforeClientResponse will only be called for components that the framework thinks might have changes, e.g. because they have recently been attached, their getState() method has been called or they have been marked as dirty using markAsDirty().

I don’t have any of hte above mentioned happening.

Actually, I might have resolved it. I put a flag in the beforeClientResponse to indicate that the state changed for a particular state var and not any other vars.