Program: 77884
Project: 77884
Buggy source:
@Override public BufferedImage applyGreenscreen(BufferedImage srcImg,Background background) throws ServiceException {
  LOGGER.debug("String_Node_Str");
  if (srcImg == null || background == null) {
    LOGGER.error("String_Node_Str",srcImg,background);
    throw new ServiceException("String_Node_Str");
  }
  Mat srcImgMat;
  try {
    srcImgMat=imageHandler.convertBufferedImgToMat(srcImg);
  }
 catch (  ImageHandlingException e) {
    LOGGER.error("String_Node_Str",e);
    throw new ServiceException("String_Node_Str");
  }
  Mat backgroundMat=getCachedBackground(srcImg,background);
  Mat yccFGMat=new Mat(srcImgMat.rows(),srcImgMat.cols(),CvType.CV_8UC3);
  Imgproc.cvtColor(srcImgMat,yccFGMat,Imgproc.COLOR_RGB2YCrCb);
  double[] rgbKeyColor=srcImgMat.get(0,800);
  double[] yccKeyColor=yccFGMat.get(0,800);
  double[] tolerances=calcTolerances(yccFGMat,yccKeyColor);
  LOGGER.debug("String_Node_Str",tolerances);
  Mat resultMat=new Mat(srcImgMat.rows(),srcImgMat.cols(),CvType.CV_8UC3);
  for (int x=0; x < srcImgMat.rows(); x++) {
    for (int y=0; y < srcImgMat.cols(); y++) {
      double[] yccFGColor=yccFGMat.get(x,y);
      double[] rgbFGColor=srcImgMat.get(x,y);
      double mask=calculateMask(yccFGColor,yccKeyColor,tolerances);
      mask=1 - mask;
      double[] rgbBGColor=backgroundMat.get(x,y);
      double[] rgbNewColor=new double[3];
      double[] greenScreenColor=(int)mask == 1 ? rgbFGColor : rgbKeyColor;
      for (int i=0; i < 3; i++) {
        rgbNewColor[i]=max(rgbFGColor[i] - mask * greenScreenColor[i],0) + mask * rgbBGColor[i];
      }
      resultMat.put(x,y,rgbNewColor);
    }
  }
  BufferedImage newImage;
  try {
    newImage=imageHandler.convertMatToBufferedImg(resultMat);
  }
 catch (  ImageHandlingException e) {
    LOGGER.error("String_Node_Str",e);
    throw new ServiceException("String_Node_Str");
  }
  return newImage;
}

Fixed version (ground truth):
@Override public BufferedImage applyGreenscreen(BufferedImage srcImg,Background background) throws ServiceException {
  LOGGER.debug("String_Node_Str");
  if (srcImg == null || background == null) {
    LOGGER.error("String_Node_Str",srcImg,background);
    throw new ServiceException("String_Node_Str");
  }
  Mat srcImgMat;
  try {
    srcImgMat=imageHandler.convertBufferedImgToMat(srcImg);
  }
 catch (  ImageHandlingException e) {
    LOGGER.error("String_Node_Str",e);
    throw new ServiceException("String_Node_Str");
  }
  Mat backgroundMat=getCachedBackground(srcImg,background);
  Mat yccFGMat=new Mat(srcImgMat.rows(),srcImgMat.cols(),CvType.CV_8UC3);
  Imgproc.cvtColor(srcImgMat,yccFGMat,Imgproc.COLOR_RGB2YCrCb);
  double[] rgbKeyColor=srcImgMat.get(0,0);
  double[] yccKeyColor=yccFGMat.get(0,0);
  double[] tolerances=calcTolerances(yccFGMat,yccKeyColor);
  LOGGER.debug("String_Node_Str",tolerances);
  Mat resultMat=new Mat(srcImgMat.rows(),srcImgMat.cols(),CvType.CV_8UC3);
  for (int x=0; x < srcImgMat.rows(); x++) {
    for (int y=0; y < srcImgMat.cols(); y++) {
      double[] yccFGColor=yccFGMat.get(x,y);
      double[] rgbFGColor=srcImgMat.get(x,y);
      double mask=calculateMask(yccFGColor,yccKeyColor,tolerances);
      mask=1 - mask;
      double[] rgbBGColor=backgroundMat.get(x,y);
      double[] rgbNewColor=new double[3];
      double[] greenScreenColor=(int)mask == 1 ? rgbFGColor : rgbKeyColor;
      for (int i=0; i < 3; i++) {
        rgbNewColor[i]=max(rgbFGColor[i] - mask * greenScreenColor[i],0) + mask * rgbBGColor[i];
      }
      resultMat.put(x,y,rgbNewColor);
    }
  }
  BufferedImage newImage;
  try {
    newImage=imageHandler.convertMatToBufferedImg(resultMat);
  }
 catch (  ImageHandlingException e) {
    LOGGER.error("String_Node_Str",e);
    throw new ServiceException("String_Node_Str");
  }
  return newImage;
}