<commit_before>package com.bt.controllers;

import com.bt.dao.*;
import com.bt.domain.ImagePosted;
import com.bt.domain.PhoneNumber;
import com.bt.domain.User;
import com.bt.domain.UserRole;
import com.google.gson.Gson;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@RestController
public class UserController {
    private static final Logger logger = Logger.getLogger(UserController.class);

    @ResponseBody
    @RequestMapping(value="/login",method=RequestMethod.POST)
    public ResponseEntity loginUser(HttpServletRequest req, HttpServletResponse res, @RequestBody String user){

        Gson gson = new Gson();

        User userInfo = gson.fromJson(user, User.class);

        ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
        UserDao userDao = (UserDaoImpl) ac.getBean("userDaoImpl");

        User loggedInUser = userDao.login(userInfo.getEmail(), userInfo.getPassword());

        System.out.println(loggedInUser);

        loggedInUser.setPassword(null);

        HttpSession session = req.getSession();

        session.setAttribute("user", loggedInUser);

        return new ResponseEntity(gson.toJson(userInfo.getEmail()), HttpStatus.OK);
    }

    @ResponseBody
    @RequestMapping(value="/register",method=RequestMethod.POST)
    public ResponseEntity registerUser(HttpServletRequest req, HttpServletResponse res, @RequestBody String user){
        Gson gson = new Gson();

        User userInfo = gson.fromJson(user, User.class);
        System.out.println(userInfo.toString());
        logger.info(userInfo.toString());

        ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
        UserDao userDao = (UserDaoImpl) ac.getBean("userDaoImpl");
        UserRoleDao urDao = (UserRoleDaoImpl) ac.getBean("userRoleDaoImpl");

        UserRole ur = urDao.getUserRoleById(2);
        userInfo.setUserRole(ur);
        userDao.persistUser(userInfo);

        HttpSession session = req.getSession();

        session.setAttribute("user", userInfo);
        System.out.print(userInfo);

        //userInfo.setPassword(null);

        return new ResponseEntity(gson.toJson(userInfo.getEmail()), HttpStatus.OK);
    }

    @ResponseBody
    @RequestMapping(value="/postImage",method=RequestMethod.POST)
    public ResponseEntity postImage(HttpServletRequest req, HttpServletResponse res, @RequestBody String postImage){
        Gson gson = new Gson();

        ImagePosted newImage = gson.fromJson(postImage, ImagePosted.class);
        logger.info(newImage.toString());
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("user");

        newImage.setPoster(user);
        ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
        ImagePostedDao iDao = (ImagePostedDaoImpl) ac.getBean("imagePostedDaoImpl");

        iDao.persistImagePosted(newImage);
        return new ResponseEntity(gson.toJson(user.getEmail()), HttpStatus.OK);
    }
}<commit_msg>got rid of errors inviovling null user session<commit_after>package com.bt.controllers;

import com.bt.dao.*;
import com.bt.domain.ImagePosted;
import com.bt.domain.PhoneNumber;
import com.bt.domain.User;
import com.bt.domain.UserRole;
import com.google.gson.Gson;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@RestController
public class UserController {
    private static final Logger logger = Logger.getLogger(UserController.class);

    @ResponseBody
    @RequestMapping(value="/login",method=RequestMethod.POST)
    public ResponseEntity loginUser(HttpServletRequest req, HttpServletResponse res, @RequestBody String user){

        Gson gson = new Gson();

        User userInfo = gson.fromJson(user, User.class);

        ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
        UserDao userDao = (UserDaoImpl) ac.getBean("userDaoImpl");

        User loggedInUser = userDao.login(userInfo.getEmail(), userInfo.getPassword());

        System.out.println(loggedInUser);

        loggedInUser.setPassword(null);

        HttpSession session = req.getSession();

        session.setAttribute("user", loggedInUser);

        return new ResponseEntity(gson.toJson(userInfo.getEmail()), HttpStatus.OK);
    }

    @ResponseBody
    @RequestMapping(value="/register",method=RequestMethod.POST)
    public ResponseEntity registerUser(HttpServletRequest req, HttpServletResponse res, @RequestBody String user){
        Gson gson = new Gson();

        User userInfo = gson.fromJson(user, User.class);
        System.out.println(userInfo.toString());
        logger.info(userInfo.toString());

        ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
        UserDao userDao = (UserDaoImpl) ac.getBean("userDaoImpl");
        UserRoleDao urDao = (UserRoleDaoImpl) ac.getBean("userRoleDaoImpl");

        UserRole ur = urDao.getUserRoleById(2);
        userInfo.setUserRole(ur);
        userDao.persistUser(userInfo);

        HttpSession session = req.getSession();

        session.setAttribute("user", userInfo);
        System.out.print(userInfo);

        //userInfo.setPassword(<PASSWORD>);

        return new ResponseEntity(gson.toJson(userInfo.getEmail()), HttpStatus.OK);
    }

    @ResponseBody
    @RequestMapping(value="/postImage",method=RequestMethod.POST)
    public ResponseEntity postImage(HttpServletRequest req, HttpServletResponse res, @RequestBody String postImage){
        Gson gson = new Gson();

        ImagePosted newImage = gson.fromJson(postImage, ImagePosted.class);
        logger.info(newImage.toString());
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("user");
        if(user!=null) {
            newImage.setPoster(user);
            ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
            ImagePostedDao iDao = (ImagePostedDaoImpl) ac.getBean("imagePostedDaoImpl");

            iDao.persistImagePosted(newImage);
            return new ResponseEntity(gson.toJson(user.getEmail()), HttpStatus.OK);
        }
        return null;
    }
}
{'fraction_non_alphanumeric': 0.1089930151338766, 'fraction_numerical': 0.0005820721769499418, 'mean_word_length': 3.9588744588744587, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1687365', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1896, 'n_words': 358}