Hello to everybody...first post in the forum that infact I follow since a long time ago...
i have a problem with a wrapper of the FacesServlet engine, that I had to build to catch an exception, here the code:
I don't undestain why it gives me a nullPointerException on the "FacesContext context = FacesContext.getCurrentInstance()".
Moreover, i tryed to build inside the catch block also a new webpage using the response, but when i call the method "response.getWriter();" an other IllegalStateException is thrown.
You are doing something very peculiar, aggregating on the FacesServlet. Usually, one would subclass it, instead.
The FacesContext is not a construct that has an extended lifespan. It is created when a request comes in, used to process the request and create a response, and then discarded (destroyed) once the response has been sent back to the requester. So the reason your code fails is that the FacesContext has not yet been created.
In actual practice, altering the FacesServlet is not the best way to handle FacesExceptions. Ideally the application logic will intercept Exceptions before they get thrown upstream to the FacesServlet. When that is not possible, it is better to set error traps in the web.xml file.
An IDE is no substitute for an Intelligent Developer.