Program: 188926
Project: 188926
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public Representation put(Representation rep){
  authenticate();
  Representation toreturn=null;
  if (rep.getMediaType().equals(MediaType.APPLICATION_XML)) {
    JaxbObject<Processing> jo=new JaxbObject<Processing>();
    Processing p=null;
    try {
      String text=rep.getText();
      p=(Processing)XmlTools.unMarshal(jo,new Processing(),text);
    }
 catch (    IOException e) {
      e.printStackTrace();
      throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,e);
    }
catch (    SAXException ex) {
      ex.printStackTrace();
      throw new ResourceException(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY,ex);
    }
    try {
      Log.info("String_Node_Str" + p.getSwAccession());
      ProcessingService ps=BeanFactory.getProcessingServiceBean();
      Processing processing=(Processing)testIfNull(ps.findBySWAccession(p.getSwAccession()));
      Log.debug("String_Node_Str" + registration.getEmailAddress());
      processing.givesPermission(registration);
      if (p.getOwner() != null) {
        processing.setOwner(BeanFactory.getRegistrationServiceBean().findByEmailAddress(p.getOwner().getEmailAddress()));
      }
 else {
        processing.setOwner(registration);
      }
      processing.setStatus(p.getStatus() == null ? "String_Node_Str" : p.getStatus());
      processing.setTaskGroup(p.isTaskGroup());
      if (p.getRunStartTimestamp() != null) {
        processing.setRunStartTimestamp(p.getRunStartTimestamp());
      }
      if (p.getRunStopTimestamp() != null) {
        processing.setRunStopTimestamp(p.getRunStopTimestamp());
      }
      if (p.getFiles() != null) {
        if (processing.getFiles() == null) {
          processing.setFiles(p.getFiles());
        }
 else {
          processing.getFiles().addAll(p.getFiles());
        }
      }
      if (p.getIUS() != null) {
        HashSet<IUS> set=new HashSet<IUS>();
        IUSService is=BeanFactory.getIUSServiceBean();
        for (        IUS i : p.getIUS()) {
          IUS newI=is.findBySWAccession(i.getSwAccession());
          if (newI != null && newI.givesPermission(registration)) {
            set.add(newI);
          }
 else           if (newI == null) {
            Log.info("String_Node_Str" + i);
          }
        }
        if (processing.getIUS() == null) {
          processing.setIUS(set);
        }
 else {
          processing.getIUS().addAll(set);
        }
      }
      if (p.getLanes() != null) {
        HashSet<Lane> set=new HashSet<Lane>();
        LaneService ls=BeanFactory.getLaneServiceBean();
        for (        Lane l : p.getLanes()) {
          Lane newL=ls.findBySWAccession(l.getSwAccession());
          if (newL != null && newL.givesPermission(registration)) {
            set.add(newL);
          }
 else           if (newL == null) {
            Log.info("String_Node_Str" + l);
          }
        }
        if (processing.getLanes() == null) {
          processing.setLanes(set);
        }
 else {
          processing.getLanes().addAll(set);
        }
      }
      if (p.getSamples() != null) {
        HashSet<Sample> set=new HashSet<Sample>();
        SampleService ss=BeanFactory.getSampleServiceBean();
        for (        Sample s : p.getSamples()) {
          Sample newS=ss.findBySWAccession(s.getSwAccession());
          if (newS != null && newS.givesPermission(registration)) {
            set.add(newS);
          }
 else           if (newS == null) {
            Log.info("String_Node_Str" + s);
          }
        }
        if (processing.getSamples() == null) {
          processing.setSamples(set);
        }
 else {
          processing.getSamples().addAll(set);
        }
      }
      if (p.getSequencerRuns() != null) {
        HashSet<SequencerRun> set=new HashSet<SequencerRun>();
        SequencerRunService srs=BeanFactory.getSequencerRunServiceBean();
        for (        SequencerRun sr : p.getSequencerRuns()) {
          SequencerRun newSR=srs.findBySWAccession(sr.getSwAccession());
          if (newSR != null && newSR.givesPermission(registration)) {
            set.add(newSR);
          }
 else           if (newSR == null) {
            Log.info("String_Node_Str" + sr);
          }
        }
        if (processing.getSequencerRuns() == null) {
          processing.setSequencerRuns(set);
        }
 else {
          processing.getSequencerRuns().addAll(set);
        }
      }
      if (p.getStudies() != null) {
        HashSet<Study> set=new HashSet<Study>();
        StudyService srs=BeanFactory.getStudyServiceBean();
        for (        Study sr : p.getStudies()) {
          Study newS=srs.findBySWAccession(sr.getSwAccession());
          if (newS != null && newS.givesPermission(registration)) {
            set.add(newS);
          }
 else           if (newS == null) {
            Log.info("String_Node_Str" + sr);
          }
        }
        if (processing.getSequencerRuns() == null) {
          processing.setStudies(set);
        }
 else {
          processing.getStudies().addAll(set);
        }
      }
      if (p.getChildren() != null || p.getParents() != null) {
        HashSet<Processing> childSet=new HashSet<Processing>();
        for (        Processing proc : p.getChildren()) {
          Processing newProc=ps.findBySWAccession(proc.getSwAccession());
          if (newProc != null && newProc.givesPermission(registration)) {
            childSet.add(newProc);
          }
 else           if (newProc == null) {
            Log.info("String_Node_Str" + proc);
          }
        }
        if (processing.getChildren() == null) {
          processing.setChildren(childSet);
        }
 else {
          processing.getChildren().addAll(childSet);
        }
        HashSet<Processing> parentSet=new HashSet<Processing>();
        for (        Processing proc : p.getParents()) {
          Processing newProc=ps.findBySWAccession(proc.getSwAccession());
          if (newProc != null && newProc.givesPermission(registration)) {
            parentSet.add(newProc);
          }
 else           if (newProc == null) {
            Log.info("String_Node_Str" + proc);
          }
        }
        if (processing.getParents() == null) {
          processing.setParents(parentSet);
        }
 else {
          processing.getParents().addAll(parentSet);
        }
      }
      if (p.getWorkflowRun() != null && (processing.getWorkflowRun() == null || p.getWorkflowRun().getSwAccession() != processing.getWorkflowRun().getSwAccession())) {
        WorkflowRunService wrs=BeanFactory.getWorkflowRunServiceBean();
        WorkflowRun newWr=wrs.findBySWAccession(p.getWorkflowRun().getSwAccession());
        if (newWr != null && newWr.givesPermission(registration)) {
          processing.setWorkflowRun(newWr);
        }
 else         if (newWr == null) {
          Log.info("String_Node_Str" + p.getWorkflowRun());
        }
      }
      if (p.getWorkflowRunByAncestorWorkflowRunId() != null && (processing.getWorkflowRunByAncestorWorkflowRunId() == null || p.getWorkflowRunByAncestorWorkflowRunId().getSwAccession() != processing.getWorkflowRunByAncestorWorkflowRunId().getSwAccession())) {
        WorkflowRunService wrs=BeanFactory.getWorkflowRunServiceBean();
        WorkflowRun newWr=wrs.findBySWAccession(p.getWorkflowRunByAncestorWorkflowRunId().getSwAccession());
        if (newWr != null && newWr.givesPermission(registration)) {
          processing.setWorkflowRunByAncestorWorkflowRunId(newWr);
        }
 else         if (newWr == null) {
          Log.info("String_Node_Str" + p.getWorkflowRunByAncestorWorkflowRunId());
        }
      }
      if (p.getProcessingAttributes() != null && !p.getProcessingAttributes().isEmpty()) {
        processing.getProcessingAttributes().clear();
        for (        ProcessingAttribute pa : p.getProcessingAttributes()) {
          pa.setProcessing(processing);
          processing.getProcessingAttributes().add(pa);
        }
      }
      ps.update(registration,processing);
      if (p.getFiles() != null) {
        addNewFiles(p);
      }
      if (p.getIUS() != null) {
        addNewIUSes(p);
      }
      if (p.getLanes() != null) {
        addNewLanes(p);
      }
      if (p.getSequencerRuns() != null) {
        addNewSequencerRuns(p);
      }
      if (p.getStudies() != null) {
        addNewStudies(p);
      }
      if (p.getExperiments() != null) {
        addNewExperiments(p);
      }
      if (p.getSamples() != null) {
        addNewSamples(p);
      }
      if (p.getChildren() != null || p.getParents() != null) {
        addNewRelationships(p);
      }
      if (p.getWorkflowRun() != null) {
        MetadataDB mdb=DBAccess.get();
        try {
          ReturnValue ret=mdb.update_processing_workflow_run(p.getProcessingId(),p.getWorkflowRun().getSwAccession());
          if (ret.getExitStatus() != ReturnValue.SUCCESS) {
            throw new ResourceException(Status.SERVER_ERROR_INTERNAL,"String_Node_Str" + ret.getExitStatus());
          }
        }
  finally {
          this.closeConnectionStatementResultSet(mdb,null);
          DBAccess.close();
        }
      }
      if (p.getWorkflowRunByAncestorWorkflowRunId() != null) {
        MetadataDB mdb=DBAccess.get();
        try {
          mdb.add_workflow_run_ancestor(p.getWorkflowRunByAncestorWorkflowRunId().getSwAccession(),p.getProcessingId());
        }
  finally {
          this.closeConnectionStatementResultSet(mdb,null);
          DBAccess.close();
        }
      }
      ReturnValue newProcessing=Processing.clone(p), ret;
      MetadataDB mdb=DBAccess.get();
      try {
        ret=DBAccess.get().update_processing_event(p.getProcessingId(),newProcessing);
      }
  finally {
        this.closeConnectionStatementResultSet(mdb,null);
        DBAccess.close();
      }
      if (ret.getExitStatus() != ReturnValue.SUCCESS) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL,"String_Node_Str" + ret.getExitStatus());
      }
      Hibernate3DtoCopier copier=new Hibernate3DtoCopier();
      Document line=XmlTools.marshalToDocument(jo,copier.hibernate2dto(processing));
      toreturn=XmlTools.getRepresentation(line);
      getResponse().setEntity(toreturn);
      getResponse().setStatus(Status.SUCCESS_CREATED);
    }
 catch (    SecurityException e) {
      getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN,e);
    }
catch (    Exception e) {
      e.printStackTrace();
      getResponse().setStatus(Status.SERVER_ERROR_INTERNAL,e);
    }
 finally {
      DBAccess.close();
    }
  }
 else {
    throw new ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE);
  }
  return toreturn;
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public Representation put(Representation rep){
  authenticate();
  Representation toreturn=null;
  if (rep.getMediaType().equals(MediaType.APPLICATION_XML)) {
    JaxbObject<Processing> jo=new JaxbObject<Processing>();
    Processing p=null;
    try {
      String text=rep.getText();
      p=(Processing)XmlTools.unMarshal(jo,new Processing(),text);
    }
 catch (    IOException e) {
      e.printStackTrace();
      throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,e);
    }
catch (    SAXException ex) {
      ex.printStackTrace();
      throw new ResourceException(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY,ex);
    }
    try {
      Log.info("String_Node_Str" + p.getSwAccession());
      ProcessingService ps=BeanFactory.getProcessingServiceBean();
      Processing processing=(Processing)testIfNull(ps.findBySWAccession(p.getSwAccession()));
      Log.debug("String_Node_Str" + registration.getEmailAddress());
      processing.givesPermission(registration);
      if (p.getOwner() != null) {
        processing.setOwner(BeanFactory.getRegistrationServiceBean().findByEmailAddress(p.getOwner().getEmailAddress()));
      }
 else {
        processing.setOwner(registration);
      }
      processing.setStatus(p.getStatus() == null ? "String_Node_Str" : p.getStatus());
      processing.setTaskGroup(p.isTaskGroup());
      if (p.getRunStartTimestamp() != null) {
        processing.setRunStartTimestamp(p.getRunStartTimestamp());
      }
      if (p.getRunStopTimestamp() != null) {
        processing.setRunStopTimestamp(p.getRunStopTimestamp());
      }
      if (p.getFiles() != null) {
        if (processing.getFiles() == null) {
          processing.setFiles(p.getFiles());
        }
 else {
          processing.getFiles().addAll(p.getFiles());
        }
      }
      if (p.getIUS() != null) {
        HashSet<IUS> set=new HashSet<IUS>();
        IUSService is=BeanFactory.getIUSServiceBean();
        for (        IUS i : p.getIUS()) {
          IUS newI=is.findBySWAccession(i.getSwAccession());
          if (newI != null && newI.givesPermission(registration)) {
            set.add(newI);
          }
 else           if (newI == null) {
            Log.info("String_Node_Str" + i);
          }
        }
        if (processing.getIUS() == null) {
          processing.setIUS(set);
        }
 else {
          processing.getIUS().addAll(set);
        }
      }
      if (p.getLanes() != null) {
        HashSet<Lane> set=new HashSet<Lane>();
        LaneService ls=BeanFactory.getLaneServiceBean();
        for (        Lane l : p.getLanes()) {
          Lane newL=ls.findBySWAccession(l.getSwAccession());
          if (newL != null && newL.givesPermission(registration)) {
            set.add(newL);
          }
 else           if (newL == null) {
            Log.info("String_Node_Str" + l);
          }
        }
        if (processing.getLanes() == null) {
          processing.setLanes(set);
        }
 else {
          processing.getLanes().addAll(set);
        }
      }
      if (p.getSamples() != null) {
        HashSet<Sample> set=new HashSet<Sample>();
        SampleService ss=BeanFactory.getSampleServiceBean();
        for (        Sample s : p.getSamples()) {
          Sample newS=ss.findBySWAccession(s.getSwAccession());
          if (newS != null && newS.givesPermission(registration)) {
            set.add(newS);
          }
 else           if (newS == null) {
            Log.info("String_Node_Str" + s);
          }
        }
        if (processing.getSamples() == null) {
          processing.setSamples(set);
        }
 else {
          processing.getSamples().addAll(set);
        }
      }
      if (p.getSequencerRuns() != null) {
        HashSet<SequencerRun> set=new HashSet<SequencerRun>();
        SequencerRunService srs=BeanFactory.getSequencerRunServiceBean();
        for (        SequencerRun sr : p.getSequencerRuns()) {
          SequencerRun newSR=srs.findBySWAccession(sr.getSwAccession());
          if (newSR != null && newSR.givesPermission(registration)) {
            set.add(newSR);
          }
 else           if (newSR == null) {
            Log.info("String_Node_Str" + sr);
          }
        }
        if (processing.getSequencerRuns() == null) {
          processing.setSequencerRuns(set);
        }
 else {
          processing.getSequencerRuns().addAll(set);
        }
      }
      if (p.getStudies() != null) {
        HashSet<Study> set=new HashSet<Study>();
        StudyService srs=BeanFactory.getStudyServiceBean();
        for (        Study sr : p.getStudies()) {
          Study newS=srs.findBySWAccession(sr.getSwAccession());
          if (newS != null && newS.givesPermission(registration)) {
            set.add(newS);
          }
 else           if (newS == null) {
            Log.info("String_Node_Str" + sr);
          }
        }
        if (processing.getSequencerRuns() == null) {
          processing.setStudies(set);
        }
 else {
          processing.getStudies().addAll(set);
        }
      }
      if (p.getChildren() != null || p.getParents() != null) {
        HashSet<Processing> childSet=new HashSet<Processing>();
        for (        Processing proc : p.getChildren()) {
          Processing newProc=ps.findBySWAccession(proc.getSwAccession());
          if (newProc != null && newProc.givesPermission(registration)) {
            childSet.add(newProc);
          }
 else           if (newProc == null) {
            Log.info("String_Node_Str" + proc);
          }
        }
        if (processing.getChildren() == null) {
          processing.setChildren(childSet);
        }
 else {
          processing.getChildren().addAll(childSet);
        }
        HashSet<Processing> parentSet=new HashSet<Processing>();
        for (        Processing proc : p.getParents()) {
          Processing newProc=ps.findBySWAccession(proc.getSwAccession());
          if (newProc != null && newProc.givesPermission(registration)) {
            parentSet.add(newProc);
          }
 else           if (newProc == null) {
            Log.info("String_Node_Str" + proc);
          }
        }
        if (processing.getParents() == null) {
          processing.setParents(parentSet);
        }
 else {
          processing.getParents().addAll(parentSet);
        }
      }
      if (p.getWorkflowRun() != null && (processing.getWorkflowRun() == null || p.getWorkflowRun().getSwAccession() != processing.getWorkflowRun().getSwAccession())) {
        WorkflowRunService wrs=BeanFactory.getWorkflowRunServiceBean();
        WorkflowRun newWr=wrs.findBySWAccession(p.getWorkflowRun().getSwAccession());
        if (newWr != null && newWr.givesPermission(registration)) {
          processing.setWorkflowRun(newWr);
        }
 else         if (newWr == null) {
          Log.info("String_Node_Str" + p.getWorkflowRun());
        }
      }
      if (p.getWorkflowRunByAncestorWorkflowRunId() != null && (processing.getWorkflowRunByAncestorWorkflowRunId() == null || p.getWorkflowRunByAncestorWorkflowRunId().getSwAccession() != processing.getWorkflowRunByAncestorWorkflowRunId().getSwAccession())) {
        WorkflowRunService wrs=BeanFactory.getWorkflowRunServiceBean();
        WorkflowRun newWr=wrs.findBySWAccession(p.getWorkflowRunByAncestorWorkflowRunId().getSwAccession());
        if (newWr != null && newWr.givesPermission(registration)) {
          processing.setWorkflowRunByAncestorWorkflowRunId(newWr);
        }
 else         if (newWr == null) {
          Log.info("String_Node_Str" + p.getWorkflowRunByAncestorWorkflowRunId());
        }
      }
      if (p.getProcessingAttributes() != null && !p.getProcessingAttributes().isEmpty()) {
        for (        ProcessingAttribute pa : p.getProcessingAttributes()) {
          pa.setProcessing(processing);
          processing.getProcessingAttributes().add(pa);
        }
      }
      ps.update(registration,processing);
      if (p.getFiles() != null) {
        addNewFiles(p);
      }
      if (p.getIUS() != null) {
        addNewIUSes(p);
      }
      if (p.getLanes() != null) {
        addNewLanes(p);
      }
      if (p.getSequencerRuns() != null) {
        addNewSequencerRuns(p);
      }
      if (p.getStudies() != null) {
        addNewStudies(p);
      }
      if (p.getExperiments() != null) {
        addNewExperiments(p);
      }
      if (p.getSamples() != null) {
        addNewSamples(p);
      }
      if (p.getChildren() != null || p.getParents() != null) {
        addNewRelationships(p);
      }
      if (p.getWorkflowRun() != null) {
        MetadataDB mdb=DBAccess.get();
        try {
          ReturnValue ret=mdb.update_processing_workflow_run(p.getProcessingId(),p.getWorkflowRun().getSwAccession());
          if (ret.getExitStatus() != ReturnValue.SUCCESS) {
            throw new ResourceException(Status.SERVER_ERROR_INTERNAL,"String_Node_Str" + ret.getExitStatus());
          }
        }
  finally {
          this.closeConnectionStatementResultSet(mdb,null);
          DBAccess.close();
        }
      }
      if (p.getWorkflowRunByAncestorWorkflowRunId() != null) {
        MetadataDB mdb=DBAccess.get();
        try {
          mdb.add_workflow_run_ancestor(p.getWorkflowRunByAncestorWorkflowRunId().getSwAccession(),p.getProcessingId());
        }
  finally {
          this.closeConnectionStatementResultSet(mdb,null);
          DBAccess.close();
        }
      }
      ReturnValue newProcessing=Processing.clone(p), ret;
      MetadataDB mdb=DBAccess.get();
      try {
        ret=DBAccess.get().update_processing_event(p.getProcessingId(),newProcessing);
      }
  finally {
        this.closeConnectionStatementResultSet(mdb,null);
        DBAccess.close();
      }
      if (ret.getExitStatus() != ReturnValue.SUCCESS) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL,"String_Node_Str" + ret.getExitStatus());
      }
      Hibernate3DtoCopier copier=new Hibernate3DtoCopier();
      Document line=XmlTools.marshalToDocument(jo,copier.hibernate2dto(processing));
      toreturn=XmlTools.getRepresentation(line);
      getResponse().setEntity(toreturn);
      getResponse().setStatus(Status.SUCCESS_CREATED);
    }
 catch (    SecurityException e) {
      getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN,e);
    }
catch (    Exception e) {
      e.printStackTrace();
      getResponse().setStatus(Status.SERVER_ERROR_INTERNAL,e);
    }
 finally {
      DBAccess.close();
    }
  }
 else {
    throw new ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE);
  }
  return toreturn;
}