<commit_before>package pl.matsuo.gitlab.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import pl.matsuo.gitlab.data.BuildInfo;
import pl.matsuo.gitlab.data.ProjectInfo;
import pl.matsuo.gitlab.data.UserInfo;
import pl.matsuo.gitlab.exception.ResourceNotFoundException;
import pl.matsuo.gitlab.hook.PartialBuildInfo;
import pl.matsuo.gitlab.service.db.Database;

import static org.springframework.http.HttpStatus.*;
import static org.springframework.web.bind.annotation.RequestMethod.*;
import static pl.matsuo.gitlab.util.PushEventUtil.*;


/**
 * Created by marek on 04.07.15.
 */
@Controller
@RequestMapping("/s")
public class CodeStatisticsController {


  @Autowired
  Database db;


  @RequestMapping(value = "/{user}", method = GET)
  @ResponseStatus(OK)
  public @ResponseBody
  UserInfo user(@PathVariable("user") String user) {
    return db.get(user, UserInfo.class);
  }


  @RequestMapping(value = "/{user}/{project}", method = GET)
  @ResponseStatus(OK)
  public @ResponseBody
  ProjectInfo project(@PathVariable("user") String user,
                 @PathVariable("project") String project) {
    return db.get(subPath(user, project), ProjectInfo.class);
  }


  @RequestMapping(value = "/{user}/{project}/{branch}", method = GET)
  @ResponseStatus(OK)
  public @ResponseBody
  Object branch(@PathVariable("user") String user,
                   @PathVariable("project") String project,
                   @PathVariable("branch") String branch) {
    String data = db.get(subPath(user, project, branch), String.class);

    if (data.contains("{")) {
      // returns BuildInfo
      return db.get(subPath(user, project, branch), BuildInfo.class);
    } else {
      // returns commit reference
      return data;
    }
  }
<commit_msg>Prevent NPE when no data was passed<commit_after>package pl.matsuo.gitlab.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import pl.matsuo.gitlab.data.BuildInfo;
import pl.matsuo.gitlab.data.ProjectInfo;
import pl.matsuo.gitlab.data.UserInfo;
import pl.matsuo.gitlab.exception.ResourceNotFoundException;
import pl.matsuo.gitlab.hook.PartialBuildInfo;
import pl.matsuo.gitlab.service.db.Database;

import static org.springframework.http.HttpStatus.*;
import static org.springframework.web.bind.annotation.RequestMethod.*;
import static pl.matsuo.gitlab.util.PushEventUtil.*;


/**
 * Created by marek on 04.07.15.
 */
@Controller
@RequestMapping("/s")
public class CodeStatisticsController {


  @Autowired
  Database db;


  @RequestMapping(value = "/{user}", method = GET)
  @ResponseStatus(OK)
  public @ResponseBody
  UserInfo user(@PathVariable("user") String user) {
    return db.get(user, UserInfo.class);
  }


  @RequestMapping(value = "/{user}/{project}", method = GET)
  @ResponseStatus(OK)
  public @ResponseBody
  ProjectInfo project(@PathVariable("user") String user,
                 @PathVariable("project") String project) {
    return db.get(subPath(user, project), ProjectInfo.class);
  }


  @RequestMapping(value = "/{user}/{project}/{branch}", method = GET)
  @ResponseStatus(OK)
  public @ResponseBody
  Object branch(@PathVariable("user") String user,
                   @PathVariable("project") String project,
                   @PathVariable("branch") String branch) {
    String data = db.get(subPath(user, project, branch), String.class);

    if (data != null && data.contains("{")) {
      // returns BuildInfo
      return db.get(subPath(user, project, branch), BuildInfo.class);
    } else {
      // returns commit reference
      return data;
    }
  }

{'fraction_non_alphanumeric': 0.1269689737470167, 'fraction_numerical': 0.002863961813842482, 'mean_word_length': 4.311787072243346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3634968', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1210, 'n_words': 244}