[Demonstration 1]

[Buggy Method]
public Order getOrderById(Long orderId, boolean verify) {
    //Get the order
    Order order = orderRepository.findById(orderId).get();
    //validate that the accountId of the order belongs to the user
    if (verify) {
        try {
            validateCustomerId(order.getCustomerId());
        } catch (Exception e) {
            //TODO: Make this throw an exception so that feign can say that you're not authorized to look at these orders
            logger.error("FAILED VALIDATION");
            return null;
        }
    }
    //		if (order==null)
    //			return null;
    //		order.setTrackingURL(deliveryClient.getDeliveryByOrderId(order.getId()).getBody().getTrackingURL());
    return order;
}

[Buggy Hunk]
Order order = orderRepository.findById(orderId).get();

[Patch]
Order order = orderRepository.findById(orderId).orElse(null);

[Demonstration 3]

[Buggy Method]
@PostMapping("/department/create_course")
public String createCourse(@Valid Course course, BindingResult bindingResult, RedirectAttributes redirectAttributes) {
    if (bindingResult.hasErrors() && !bindingResult.hasFieldErrors("department")) {
        redirectAttributes.addFlashAttribute("course", course);
        redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.course", bindingResult);
    } else {
        try {
            departmentAdminService.registerCourse(course);
            redirectAttributes.addFlashAttribute("course_success", true);
        } catch (Exception e) {
            List<String> errors = new ArrayList<>();
            if (e instanceof DataIntegrityViolationException && e.getMessage().contains("PRIMARY_KEY")) {
                errors.add("Course with this code already exists");
            }
            redirectAttributes.addFlashAttribute("course", course);
            redirectAttributes.addFlashAttribute("course_errors", errors);
        }
    }
    return "redirect:/department";
}

[Buggy Hunk]
if (e instanceof DataIntegrityViolationException && e.getMessage().contains("PRIMARY_KEY")) {

[Patch]
if (e.getMessage().contains("PRIMARY")) {