I have created a CommonServiceImpl, it is responsible for removal of session in spring boot project. But I get a Potential null pointer access error by getAoccur please help me get rid of this error.
@Service public class CommonServiceImpl implements CommonService {
HttpSession session=((HttpServletRequest)RequestContextHolder.getRequestAttributes()).getSession();
if (session != null) {
// Remove the success and error message attributes from the session
session.removeAttribute("succMsg");
session.removeAttribute("errorMsg");
}
}
The Potential null pointer access: The method getRequestAttributes() may return nullJava. How can I rid of this issue?