This code is to check if the user is already registered to the application or not ,and I am getting null pointer exception while checking if the similar username exists in the database
@ResponseStatus(HttpStatus.CREATED)
@PostMapping("/register")
public String registeruser(HttpServletRequest request, @RequestBody UserDetails requestData) {
String userName = requestData.getUsername();
System.out.println("checking user");
System.out.println(userName);
System.out.println(uDao.existsById(userName));// I AM GETTING ERROR HERE
if ((uDao.existsById(userName))) {
throw new UserAlreadyExistException("You have already registered. please log in");
}
String userRole = (String) request.getSession().getAttribute("role");
if (!userRole.equalsIgnoreCase("productmaster") || !userRole.equalsIgnoreCase("admin")||!userRole.equalsIgnoreCase("Retailer")) {
throw new InvalidUserRoleException("you are not authorized to add the products");
}
@SuppressWarnings("unused")
boolean newuser = true;
UserDetails user = new UserDetails(requestData.getUsername(), requestData.getPassword()),requestData.getUserRole());
if (newuser = uservice.add(user)) {
return "User successfully added";
}
return "User is not added";
}