fix the null pointer exception and a database issue when you run an
analysis after switching workspace. this is related to mantis 3810 but
not reported or mentioned before