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.