Added null check for result of getContextPath