This is an interview question.
The interview is over, but this question is still on my mind.
I can't ask the interviewer, as I did not get the job.
Scenario:
- put object of class C1 in to a cache with key "a"
Later code:
C1 c1FromCache = (C1) cache.get("a");
This code throws a ClassCastException.
What can the reasons be?
I said because someone else put another object with the same key and so overwrote it. I was told no, think of other possibilities.
I said maybe the jar defining class C1 was not available on this node (not sure if this would result in a class cast or a ClassNotFoundException, but I was grasping for any lead now. Then I said maybe wrong version of class? They said the same jar of class C1 is there in all nodes).
Edit/ Add Asked if the get was throwing the ClassCast but was told no. after that i told him my action to resolve such an issue would be to drop in a test jsp that would mimic the actions and put better logging (stack trace) after the exception. that was the 2nd part of the question (why and what would you do if this happened in production)
Does anyone else have any ideas about why a cache get would result in a cast issue?