Program: 51537
Project: 51537
Buggy source:
/** 
 * Called when the Save this event button is pressed on the Edit event form
 * @param id - database ID of the Event to be modified
 * @return a redirect to the Events page which should show the list of Events with the modified event
 */
@Transactional public static Result updateEvent(Long id){
  Form<Event> eventForm=form(Event.class).bindFromRequest();
  if (eventForm.hasErrors()) {
    return badRequest(views.html.editEvent.render(id,eventForm,new Event(),makeProgramMap()));
  }
  Event newEventForm=eventForm.get();
  EiEvent event=JPA.em().find(EiEvent.class,id);
  Date currentDate=new Date();
  GregorianCalendar calendar=new GregorianCalendar();
  calendar.setTime(currentDate);
  XMLGregorianCalendar xCalendar=datatypeFactory.newXMLGregorianCalendar(calendar);
  xCalendar.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
  JAXBElement<SignalPayload> signalPayload=objectFactory.createSignalPayload(new SignalPayload(new PayloadFloat(1)));
  String contextName=JPA.em().find(Program.class,Long.parseLong(newEventForm.getMarketContext())).getProgramName();
  Intervals intervals=new Intervals();
  ArrayList<Interval> intervalList=new ArrayList<Interval>();
  for (int i=0; i < newEventForm.getIntervals(); i++) {
    intervalList.add(new Interval().withDuration(new DurationPropType().withDuration(new DurationValue().withValue(formatDuration(getDuration(event.getEiActivePeriod().getProperties().getDuration().getDuration().getValue()))))).withUid(new Uid().withText("String_Node_Str" + i)).withStreamPayloadBase(signalPayload));
  }
  intervals.setIntervals(intervalList);
  event.setEiActivePeriod(new EiActivePeriod().withProperties(new Properties().withDtstart(new Dtstart().withDateTime(new DateTime().withValue(event.getEiActivePeriod().getProperties().getDtstart().getDateTime().getValue().normalize()))).withDuration(new DurationPropType().withDuration(new DurationValue().withValue(formatDuration(getDuration(event.getEiActivePeriod().getProperties().getDuration().getDuration().getValue(),(int)newEventForm.getIntervals()))))).withTolerance(new Tolerance().withTolerate(new Tolerate().withStartafter(new DurationValue().withValue((formatDuration(getDuration("String_Node_Str"))))))).withXEiNotification(new DurationPropType().withDuration(new DurationValue().withValue((formatDuration(getDuration("String_Node_Str")))))).withXEiRampUp(new DurationPropType().withDuration(new DurationValue().withValue((formatDuration(getDuration("String_Node_Str")))))).withXEiRecovery(new DurationPropType().withDuration(new DurationValue().withValue((formatDuration(getDuration("String_Node_Str"))))))));
  event.setEiTarget(new EiTarget());
  event.setEventDescriptor(new EventDescriptor().withCreatedDateTime(new DateTime().withValue(xCalendar)).withEiMarketContext(new EiMarketContext().withMarketContext(new MarketContext().withValue(contextName))).withEventID(newEventForm.getEventID()).withEventStatus(updateStatus(event,(int)newEventForm.getIntervals())).withModificationNumber(event.getEventDescriptor().getModificationNumber() + 1).withPriority(newEventForm.getPriority()).withTestEvent("String_Node_Str").withVtnComment("String_Node_Str"));
  event.setEiEventSignals(new EiEventSignals().withEiEventSignals(new EiEventSignal().withCurrentValue(new CurrentValue().withPayloadFloat(new PayloadFloat().withValue(updateSignalPayload(event)))).withIntervals(new Intervals().withIntervals(intervalList)).withSignalID("String_Node_Str").withSignalName("String_Node_Str").withSignalType(SignalTypeEnumeratedType.LEVEL)));
  JPA.em().merge(event);
  flash("String_Node_Str","String_Node_Str");
  return redirect(routes.Events.events());
}

Fixed version (ground truth):
/** 
 * Called when the Save this event button is pressed on the Edit event form
 * @param id - database ID of the Event to be modified
 * @return a redirect to the Events page which should show the list of Events with the modified event
 */
@Transactional public static Result updateEvent(Long id){
  Form<Event> eventForm=form(Event.class).bindFromRequest();
  if (eventForm.hasErrors()) {
    return badRequest(views.html.editEvent.render(id,eventForm,new Event(),makeProgramMap()));
  }
  Event newEventForm=eventForm.get();
  EiEvent event=JPA.em().find(EiEvent.class,id);
  Date currentDate=new Date();
  GregorianCalendar calendar=new GregorianCalendar();
  calendar.setTime(currentDate);
  XMLGregorianCalendar xCalendar=datatypeFactory.newXMLGregorianCalendar(calendar);
  xCalendar.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
  JAXBElement<SignalPayload> signalPayload=objectFactory.createSignalPayload(new SignalPayload(new PayloadFloat(1)));
  String contextName=JPA.em().find(Program.class,Long.parseLong(newEventForm.getMarketContext())).getProgramName();
  Intervals intervals=new Intervals();
  ArrayList<Interval> intervalList=new ArrayList<Interval>();
  for (int i=0; i < newEventForm.getIntervals(); i++) {
    intervalList.add(new Interval().withDuration(new DurationPropType().withDuration(new DurationValue().withValue(formatDuration(getDuration(event))))).withUid(new Uid().withText("String_Node_Str" + i)).withStreamPayloadBase(signalPayload));
  }
  intervals.setIntervals(intervalList);
  event.setEiActivePeriod(new EiActivePeriod().withProperties(new Properties().withDtstart(new Dtstart().withDateTime(new DateTime().withValue(event.getEiActivePeriod().getProperties().getDtstart().getDateTime().getValue().normalize()))).withDuration(new DurationPropType().withDuration(new DurationValue().withValue(formatDuration(getDuration(event,(int)newEventForm.getIntervals()))))).withTolerance(new Tolerance().withTolerate(new Tolerate().withStartafter(new DurationValue().withValue((formatDuration(getDuration("String_Node_Str"))))))).withXEiNotification(new DurationPropType().withDuration(new DurationValue().withValue((formatDuration(getDuration("String_Node_Str")))))).withXEiRampUp(new DurationPropType().withDuration(new DurationValue().withValue((formatDuration(getDuration("String_Node_Str")))))).withXEiRecovery(new DurationPropType().withDuration(new DurationValue().withValue((formatDuration(getDuration("String_Node_Str"))))))));
  event.setEiTarget(new EiTarget());
  event.setEventDescriptor(new EventDescriptor().withCreatedDateTime(new DateTime().withValue(xCalendar)).withEiMarketContext(new EiMarketContext().withMarketContext(new MarketContext().withValue(contextName))).withEventID(newEventForm.getEventID()).withEventStatus(updateStatus(event,(int)newEventForm.getIntervals())).withModificationNumber(event.getEventDescriptor().getModificationNumber() + 1).withPriority(newEventForm.getPriority()).withTestEvent("String_Node_Str").withVtnComment("String_Node_Str"));
  event.setEiEventSignals(new EiEventSignals().withEiEventSignals(new EiEventSignal().withCurrentValue(new CurrentValue().withPayloadFloat(new PayloadFloat().withValue(updateSignalPayload(event)))).withIntervals(new Intervals().withIntervals(intervalList)).withSignalID("String_Node_Str").withSignalName("String_Node_Str").withSignalType(SignalTypeEnumeratedType.LEVEL)));
  JPA.em().merge(event);
  flash("String_Node_Str","String_Node_Str");
  return redirect(routes.Events.events());
}