Buggy code:
@ GET @ Produces ( MediaType . APPLICATION_JSON ) @ Path ( "//{branchId}//{groupId}" ) public List < Reservation > show ( @ PathParam ( "branchId" ) int branchId , @ PathParam ( "groupId" ) long groupId ) { } @ GET @ Produces ( MediaType . APPLICATION_JSON ) @ Path ( "//" ) public List < Reservation > index ( @ Context SecurityContext context ) { } @ GET @ Produces ( MediaType . APPLICATION_JSON ) @ Path ( "//{branchId}" ) public List < Reservation > index ( @ PathParam ( "branchId" ) int branchId , @ QueryParam ( "startTime" ) long startTime , @ DefaultValue ( "0" ) @ QueryParam ( "endTime" ) long endTime ) { } private Date timestampToDate ( long timestamp ) { } @ POST @ Consumes ( MediaType . APPLICATION_JSON ) @ Produces ( MediaType . APPLICATION_JSON ) public Reservation create ( ReservationInfo reservationInfo , @ Context SecurityContext context , @ Context HttpServletRequest request ) { } @ PUT @ Consumes ( MediaType . APPLICATION_JSON ) @ Produces ( MediaType . APPLICATION_JSON ) public Response update ( ReservationUpdateData data , @ Context HttpServletRequest request ) { long groupId = data . getGroupId ( ) ; String operation = data . getOperation ( ) ; List < Reservation > reservations = reservationEJB . findReservations ( groupId ) ; if ( operation . equals ( "startRental" ) ) { if ( ( reservations . get ( 0 ) . getStatus ( ) ) != ( ReservationStatus . SCHEDULED ) ) { throw new WebServiceException ( "The<seq2seq4repair_space>status<seq2seq4repair_space>of<seq2seq4repair_space>this<seq2seq4repair_space>reservation<seq2seq4repair_space>has<seq2seq4repair_space>been<seq2seq4repair_space>modified<seq2seq4repair_space>&<seq2seq4repair_space>refreshed.<seq2seq4repair_space>Please<seq2seq4repair_space>check<seq2seq4repair_space>again" ) ; } if ( ! ( reservations . get ( 0 ) . isFullyPaid ( ) ) ) { throw new WebServiceException ( "Please<seq2seq4repair_space>make<seq2seq4repair_space>the<seq2seq4repair_space>payment<seq2seq4repair_space>first<seq2seq4repair_space>before<seq2seq4repair_space>starting<seq2seq4repair_space>the<seq2seq4repair_space>rental" ) ; } if ( reservationEJB . isEligibleForRent ( reservations ) ) { reservationEJB . updateInventories ( reservations , RENTED ) ; reservationEJB . updateStatus ( reservations , STARTED ) ; } else { throw new WebServiceException ( "You<seq2seq4repair_space>can't<seq2seq4repair_space>start<seq2seq4repair_space>renting<seq2seq4repair_space>on<seq2seq4repair_space>this<seq2seq4repair_space>reservation.<seq2seq4repair_space>Please<seq2seq4repair_space>make<seq2seq4repair_space>sure<seq2seq4repair_space>all<seq2seq4repair_space>inventories<seq2seq4repair_space>reserved<seq2seq4repair_space>are<seq2seq4repair_space>available" ) ; } } else if ( operation . equals ( "finishRental" ) ) { if ( ( reservations . get ( 0 ) . getStatus ( ) ) != ( ReservationStatus . STARTED ) ) { throw new WebServiceException ( "The<seq2seq4repair_space>status<seq2seq4repair_space>of<seq2seq4repair_space>this<seq2seq4repair_space>reservation<seq2seq4repair_space>has<seq2seq4repair_space>been<seq2seq4repair_space>modified<seq2seq4repair_space>&<seq2seq4repair_space>refreshed.<seq2seq4repair_space>Please<seq2seq4repair_space>check<seq2seq4repair_space>again" ) ; } reservationEJB . updateInventories ( reservations , RETURNED ) ; reservationEJB . updateStatus ( reservations , FINISHED ) ; Inventory inventory = reservations . get ( 0 ) . getInventory ( ) ; List < String > busyEmployeeIds = userAgendaEJB . findReservedUsersByDate ( inventory . getOwner ( ) . getId ( ) , reservations . get ( 0 ) . getStartTime ( ) , reservations . get ( 0 ) . getEndTime ( ) ) ; Branch branch = branchEJB . findBranch ( inventory . getOwner ( ) . getId ( ) ) ; List < User > allEmployees = branch . getUsers ( ) ; for ( User employee : allEmployees ) { if ( ! ( busyEmployeeIds . contains ( employee . getId ( ) ) ) ) { List < UserRole > roles = userEJB . findAllAssignedRoles ( employee . getId ( ) ) ; List < String > rolesStr = new LinkedList < String > ( ) ; for ( UserRole role : roles ) { rolesStr . add ( role . getRoleName ( ) ) ; System . out . println ( role . getRoleName ( ) ) ; } if ( rolesStr . contains ( "technician" ) ) { SimpleDateFormat sdf = new SimpleDateFormat ( "EEE,<seq2seq4repair_space>MMM<seq2seq4repair_space>d,<seq2seq4repair_space>yyyy<seq2seq4repair_space>h:mm<seq2seq4repair_space>a" ) ; sdf . setTimeZone ( TimeZone . getTimeZone ( branch . getTimezone ( ) ) ) ; String baseUrl = ( ( ( ( request . getScheme ( ) ) + ":////" ) + ( request . getServerName ( ) ) ) + ":" ) + ( request . getServerPort ( ) ) ; String basePath = request . getContextPath ( ) ; StringBuffer reservationsSummary = new StringBuffer ( ) ; reservationsSummary . append ( "<ol>" ) ; for ( Reservation r : reservations ) { String inventoryName = r . getInventory ( ) . getName ( ) ; String entityType = "" ; reservationsSummary . append ( "<li>" ) ; if ( ( r . getInventory ( ) ) instanceof CarInventory ) { entityType = "car" ; } else if ( ( r . getInventory ( ) ) instanceof BabySeatInventory ) { entityType = "baby_seat" ; } else if ( ( r . getInventory ( ) ) instanceof GpsInventory ) { entityType = "gps" ; } reservationsSummary . append ( ( ( ( ( ( ( ( ( ( ( ( "<a<seq2seq4repair_space>href='" + baseUrl ) + basePath ) + "//inventories//index.jsf#//" ) + ( branch . getId ( ) ) ) + "//inventories//" ) + ( r . getInventory ( ) . getId ( ) ) ) + "//detail?entity=" ) + entityType ) + "'>" ) + inventoryName ) + "<//a>" ) ) ; reservationsSummary . append ( "<//li>" ) ; } reservationsSummary . append ( "<//ol>" ) ; EmailServices . sendEmail ( employee . getEmail ( ) , "New<seq2seq4repair_space>technician<seq2seq4repair_space>service<seq2seq4repair_space>request" , ( ( "<p>" + ( reservationsSummary . toString ( ) ) ) + "<//p>" ) ) ; } } } } else if ( operation . equals ( "cancelRental" ) ) { if ( ( reservations . get ( 0 ) . getStatus ( ) ) != ( ReservationStatus . SCHEDULED ) ) { throw new WebServiceException ( "The<seq2seq4repair_space>status<seq2seq4repair_space>of<seq2seq4repair_space>this<seq2seq4repair_space>reservation<seq2seq4repair_space>has<seq2seq4repair_space>been<seq2seq4repair_space>modified<seq2seq4repair_space>&<seq2seq4repair_space>refreshed.<seq2seq4repair_space>Please<seq2seq4repair_space>check<seq2seq4repair_space>again" ) ; } reservationEJB . updateInventories ( reservations , AVAILABLE ) ; reservationEJB . updateStatus ( reservations , CANCELED ) ; <START_BUG> userAgendaEJB . deleteUserAgendaByTitle ( ( ( ( String . valueOf ( data . getBranchId ( ) ) ) + "-" ) + ( String . valueOf ( data . getGroupId ( ) ) ) ) ) ; <END_BUG> } else if ( operation . equals ( "markFullyPaid" ) ) { if ( ( reservations . get ( 0 ) . isFullyPaid ( ) ) || ( ( reservations . get ( 0 ) . getStatus ( ) ) == ( ReservationStatus . CANCELED ) ) ) { throw new WebServiceException ( "The<seq2seq4repair_space>status<seq2seq4repair_space>of<seq2seq4repair_space>this<seq2seq4repair_space>reservation<seq2seq4repair_space>has<seq2seq4repair_space>been<seq2seq4repair_space>modified<seq2seq4repair_space>&<seq2seq4repair_space>refreshed.<seq2seq4repair_space>Please<seq2seq4repair_space>check<seq2seq4repair_space>again" ) ; } reservationEJB . markAsFullyPaid ( reservations ) ; }

Fix:
userAgendaEJB . deleteUserAgendaByTitle ( ( ( ( ( ( ( ( String . valueOf ( data . getBranchId ( ) ) ) + "-" ) + ( String . valueOf ( data . getGroupId ( ) ) ) ) + "-" ) + ( reservations . get ( 0 ) . getCustomer ( ) . getUser ( ) . getFirstName ( ) ) ) + "<seq2seq4repair_space>" ) + ( reservations . get ( 0 ) . getCustomer ( ) . getUser ( ) . getLastName ( ) ) ) ) ;