This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Servlets and the fly likes IllegalStateException -- How to handle this Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "IllegalStateException -- How to handle this" Watch "IllegalStateException -- How to handle this" New topic

IllegalStateException -- How to handle this

vishwanath nadimpally
Ranch Hand

Joined: Jan 25, 2005
Posts: 116
This is a piece of code I have

This method calls a method processRequest() which calls the stored procedures in a package and gets the output accordingly.

If there's an exception, the stored proc gives a 'P_OUT_REJECT_REASON_CODE' and the resultset in the form of a hashmap otherwise.

So on 'P_OUT_REJECT_REASON_CODE' I am redirecting to an error page which I have configured in a properties file and abstracted it as "rejectReasonPage".

Here I call a java class which builds the custom error message.

Also i am filtering any URL of form /myaccount/* to a AuthenticationFilter where I check the validity of the session.

My problem is when ever there's a 'P_OUT_REJECT_REASON_CODE' its throwing an IllegalStateException.It doesn't even get to the AuthenticationFilter.

I think the exception is because I have a 'return' after a 'forward' but how should I handle this situation?

Thanks for any help
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

I assume that whatever called that method -- maybe your doGet() method? -- doesn't realize that a forward took place, and proceeds to behave as if it could still handle the request.

What should you do instead? Well, your method is called "processRequest" but it doesn't do that. It might forward the request in some cases, but in the other cases it doesn't do any processing on the request. That's a signal that your code is in the wrong place. Either this method should be processing the request, forward or not, or it shouldn't be doing any processing, not even forwarding. Splitting the processing between this and somewhere else looks like a bad plan.
vishwanath nadimpally
Ranch Hand

Joined: Jan 25, 2005
Posts: 116
I am using this methods in different jsp's for calling different stored procs. Its not like it doesn't process the request.It calls the stored proc which is passed as a parameter form the jsp like this :

Here the name of the stored proc is abstracted out. I am using an xml to configure that.

So my RequestProcessor should call the stored proc and return the hashmap or if its an error should forward to an error page.
vishwanath nadimpally
Ranch Hand

Joined: Jan 25, 2005
Posts: 116
i still can't fix the problem.
I am including the error page in all the jsp's and commenting out the forwarding part in the RequestProcessor class, and this works fine. But this is not what I want.
Can some one help me with a better solution please.

[ June 09, 2006: Message edited by: vishwanath nadimpally ]
[ June 09, 2006: Message edited by: vishwanath nadimpally ]
I agree. Here's the link:
subject: IllegalStateException -- How to handle this
It's not a secret anymore!