This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi, I am initializing many objects in the init and doPost method of my servlet and storing it in a hashmap. If object instantiation fails i am not proceeding further and logging appropriate error message and show the user "Some internal error occured" and stop the processing. These objects will be used down the line in my java classes.
1) Please suggest if this approach is fine to show user this message? 2)I am only inserting it in hashmap and making sure it is not-null while inserting. So Do i need to do null checking for these objects after retrieving it from the hashmap?
Would you do anything if it was null? If not, does it matter if you crash with a null pointer or some other error. Even though it can't be null, someone may change the code in the future.
I will not able to proceed if any of those objects are null. So i will end up in the same message as "Internal Error". i do understand your point about someone changing the code. But it will really create a mess in my code . I think i might end up checking nulls. Any suggestion for making it bit cleaner.
Thanks and regards, Karan
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Null checking required for objects created by me before?