Program: 25526
Project: 25526
Buggy source:
public static void render(final List<TileSpec> tileSpecs,final BufferedImage targetImage,final double x,final double y,final double meshCellSize,final double scale,final boolean areaOffset,final int numberOfThreads,final boolean skipInterpolation,final boolean doFilter,final boolean binaryMask,final boolean excludeMask,final ImageProcessorCache imageProcessorCache,final Integer backgroundRGBColor,final Double renderMinIntensity,final Double renderMaxIntensity) throws IllegalArgumentException {
  final int targetWidth=targetImage.getWidth();
  final int targetHeight=targetImage.getHeight();
  final double[] min=new double[2];
  final double[] max=new double[2];
  final Graphics2D targetGraphics=targetImage.createGraphics();
  if (backgroundRGBColor != null) {
    targetGraphics.setBackground(new Color(backgroundRGBColor));
    targetGraphics.clearRect(0,0,targetWidth,targetHeight);
  }
  LOG.debug("String_Node_Str",tileSpecs.size(),numberOfThreads);
  final long tileLoopStart=System.currentTimeMillis();
  int tileSpecIndex=0;
  long tileSpecStart;
  long loadMipStop;
  long filterStop;
  long loadMaskStop;
  long ctListCreationStop;
  long meshCreationStop;
  long sourceCreationStop;
  long targetCreationStop;
  long mapInterpolatedStop;
  long drawImageStop;
  for (  final TileSpec ts : tileSpecs) {
    tileSpecStart=System.currentTimeMillis();
    final CoordinateTransformList<CoordinateTransform> ctl=createRenderTransform(ts,areaOffset,scale,x,y);
    Map.Entry<Integer,ImageAndMask> mipmapEntry;
    ImageAndMask imageAndMask=null;
    ImageProcessor widthAndHeightProcessor=null;
    int width=ts.getWidth();
    int height=ts.getHeight();
    boolean convertTo16Bit=(ts.getMaxIntensity() > 255);
    if ((width < 0) || (height < 0)) {
      mipmapEntry=ts.getFirstMipmapEntry();
      imageAndMask=mipmapEntry.getValue();
      widthAndHeightProcessor=imageProcessorCache.get(imageAndMask.getImageUrl(),0,false,convertTo16Bit);
      width=widthAndHeightProcessor.getWidth();
      height=widthAndHeightProcessor.getHeight();
    }
    final double s=Utils.sampleAverageScale(ctl,width,height,meshCellSize);
    int mipmapLevel=Utils.bestMipmapLevel(s);
    int downSampleLevels=0;
    final ImageProcessor ipMipmap;
    if (widthAndHeightProcessor == null) {
      mipmapEntry=ts.getFloorMipmapEntry(mipmapLevel);
      imageAndMask=mipmapEntry.getValue();
      final int currentMipmapLevel=mipmapEntry.getKey();
      if (currentMipmapLevel < mipmapLevel) {
        downSampleLevels=mipmapLevel - currentMipmapLevel;
      }
 else {
        mipmapLevel=currentMipmapLevel;
      }
      ipMipmap=imageProcessorCache.get(imageAndMask.getImageUrl(),downSampleLevels,false,convertTo16Bit);
    }
 else     if (mipmapLevel > 0) {
      downSampleLevels=mipmapLevel;
      ipMipmap=imageProcessorCache.get(imageAndMask.getImageUrl(),downSampleLevels,false,convertTo16Bit);
    }
 else {
      ipMipmap=widthAndHeightProcessor;
    }
    loadMipStop=System.currentTimeMillis();
    if (ipMipmap.getWidth() == 0 || ipMipmap.getHeight() == 0) {
      LOG.debug("String_Node_Str",imageAndMask.getImageUrl());
      continue;
    }
    if (doFilter) {
      final double mipmapScale=1.0 / (1 << mipmapLevel);
      vtnf1.process(ipMipmap,mipmapScale);
      vtnf2.process(ipMipmap,mipmapScale);
      nlcf.process(ipMipmap,mipmapScale);
    }
    filterStop=System.currentTimeMillis();
    ImageProcessor maskSourceProcessor;
    final String maskUrl=imageAndMask.getMaskUrl();
    if ((maskUrl != null) && (!excludeMask)) {
      maskSourceProcessor=imageProcessorCache.get(maskUrl,downSampleLevels,true,false);
    }
 else {
      maskSourceProcessor=null;
    }
    loadMaskStop=System.currentTimeMillis();
    final CoordinateTransformList<CoordinateTransform> ctlMipmap=new CoordinateTransformList<>();
    ctlMipmap.add(Utils.createScaleLevelTransform(mipmapLevel));
    ctlMipmap.add(ctl);
    ctListCreationStop=System.currentTimeMillis();
    final RenderTransformMesh mesh=new RenderTransformMesh(ctlMipmap,(int)(width / meshCellSize + 0.5),ipMipmap.getWidth(),ipMipmap.getHeight());
    mesh.bounds(min,max);
    final int tx=(int)Math.max(0,Math.min(targetWidth,min[0]));
    final int ty=(int)Math.max(0,Math.min(targetHeight,min[1]));
    final int w=(int)(Math.min(targetWidth,max[0]) - tx) + 1;
    final int h=(int)(Math.min(targetHeight,max[1]) - ty) + 1;
    if (w <= 0 || h <= 0) {
      LOG.debug("String_Node_Str",ts);
      continue;
    }
    mesh.translateTarget(-tx,-ty);
    mesh.updateAffines();
    meshCreationStop=System.currentTimeMillis();
    final ImageProcessorWithMasks source=new ImageProcessorWithMasks(ipMipmap,maskSourceProcessor,null);
    if ((maskSourceProcessor != null) && (source.mask == null)) {
      LOG.warn("String_Node_Str" + ipMipmap.getWidth() + "String_Node_Str"+ ipMipmap.getHeight()+ "String_Node_Str"+ maskSourceProcessor.getWidth()+ "String_Node_Str"+ maskSourceProcessor.getHeight());
      maskSourceProcessor=null;
    }
    sourceCreationStop=System.currentTimeMillis();
    final ImageProcessor tp=ipMipmap.createProcessor(w,h);
    final ImageProcessor maskTargetProcessor;
    if (maskSourceProcessor != null)     maskTargetProcessor=new ByteProcessor(w,h);
 else     maskTargetProcessor=null;
    final ImageProcessorWithMasks target=new ImageProcessorWithMasks(tp,maskTargetProcessor,null);
    targetCreationStop=System.currentTimeMillis();
    final RenderTransformMeshMappingWithMasks mapping=new RenderTransformMeshMappingWithMasks(mesh);
    final String mapType;
    if (skipInterpolation) {
      mapType="String_Node_Str";
      mapping.map(source,target,numberOfThreads);
    }
 else {
      mapType="String_Node_Str";
      mapping.mapInterpolated(source,target,numberOfThreads);
    }
    mapInterpolatedStop=System.currentTimeMillis();
    final BufferedImage image=targetToARGBImage(target,ts,binaryMask,renderMinIntensity,renderMaxIntensity);
    targetGraphics.drawImage(image,tx,ty,null);
    drawImageStop=System.currentTimeMillis();
    LOG.debug("String_Node_Str",tileSpecIndex,drawImageStop - tileSpecStart,loadMipStop - tileSpecStart,downSampleLevels,filterStop - loadMipStop,loadMaskStop - filterStop,ctListCreationStop - loadMaskStop,meshCreationStop - ctListCreationStop,sourceCreationStop - meshCreationStop,targetCreationStop - sourceCreationStop,mapType,mapInterpolatedStop - targetCreationStop,drawImageStop - mapInterpolatedStop,imageProcessorCache.size());
    tileSpecIndex++;
  }
  targetGraphics.dispose();
  LOG.debug("String_Node_Str",tileSpecs.size(),System.currentTimeMillis() - tileLoopStart);
}

Fixed version (ground truth):
public static void render(final List<TileSpec> tileSpecs,final BufferedImage targetImage,final double x,final double y,final double meshCellSize,final double scale,final boolean areaOffset,final int numberOfThreads,final boolean skipInterpolation,final boolean doFilter,final boolean binaryMask,final boolean excludeMask,final ImageProcessorCache imageProcessorCache,final Integer backgroundRGBColor,final Double renderMinIntensity,final Double renderMaxIntensity) throws IllegalArgumentException {
  final int targetWidth=targetImage.getWidth();
  final int targetHeight=targetImage.getHeight();
  final double[] min=new double[2];
  final double[] max=new double[2];
  final Graphics2D targetGraphics=targetImage.createGraphics();
  if (backgroundRGBColor != null) {
    targetGraphics.setBackground(new Color(backgroundRGBColor));
    targetGraphics.clearRect(0,0,targetWidth,targetHeight);
  }
  LOG.debug("String_Node_Str",tileSpecs.size(),numberOfThreads);
  final long tileLoopStart=System.currentTimeMillis();
  int tileSpecIndex=0;
  long tileSpecStart;
  long loadMipStop;
  long filterStop;
  long loadMaskStop;
  long ctListCreationStop;
  long meshCreationStop;
  long sourceCreationStop;
  long targetCreationStop;
  long mapInterpolatedStop;
  long drawImageStop;
  for (  final TileSpec ts : tileSpecs) {
    tileSpecStart=System.currentTimeMillis();
    final CoordinateTransformList<CoordinateTransform> ctl=createRenderTransform(ts,areaOffset,scale,x,y);
    Map.Entry<Integer,ImageAndMask> mipmapEntry;
    ImageAndMask imageAndMask=null;
    ImageProcessor widthAndHeightProcessor=null;
    int width=ts.getWidth();
    int height=ts.getHeight();
    final boolean convertTo16Bit=(ts.getMaxIntensity() > 255);
    if ((width < 0) || (height < 0)) {
      mipmapEntry=ts.getFirstMipmapEntry();
      imageAndMask=mipmapEntry.getValue();
      widthAndHeightProcessor=imageProcessorCache.get(imageAndMask.getImageUrl(),0,false,convertTo16Bit);
      width=widthAndHeightProcessor.getWidth();
      height=widthAndHeightProcessor.getHeight();
    }
    final double s=Utils.sampleAverageScale(ctl,width,height,meshCellSize);
    int mipmapLevel=Utils.bestMipmapLevel(s);
    int downSampleLevels=0;
    final ImageProcessor ipMipmap;
    if (widthAndHeightProcessor == null) {
      mipmapEntry=ts.getFloorMipmapEntry(mipmapLevel);
      imageAndMask=mipmapEntry.getValue();
      final int currentMipmapLevel=mipmapEntry.getKey();
      if (currentMipmapLevel < mipmapLevel) {
        downSampleLevels=mipmapLevel - currentMipmapLevel;
      }
 else {
        mipmapLevel=currentMipmapLevel;
      }
      ipMipmap=imageProcessorCache.get(imageAndMask.getImageUrl(),downSampleLevels,false,convertTo16Bit);
    }
 else     if (mipmapLevel > 0) {
      downSampleLevels=mipmapLevel;
      ipMipmap=imageProcessorCache.get(imageAndMask.getImageUrl(),downSampleLevels,false,convertTo16Bit);
    }
 else {
      ipMipmap=widthAndHeightProcessor;
    }
    loadMipStop=System.currentTimeMillis();
    if (ipMipmap.getWidth() == 0 || ipMipmap.getHeight() == 0) {
      LOG.debug("String_Node_Str",imageAndMask.getImageUrl());
      continue;
    }
    if (doFilter) {
      final double mipmapScale=1.0 / (1 << mipmapLevel);
      vtnf1.process(ipMipmap,mipmapScale);
      vtnf2.process(ipMipmap,mipmapScale);
      nlcf.process(ipMipmap,mipmapScale);
    }
    filterStop=System.currentTimeMillis();
    ImageProcessor maskSourceProcessor;
    final String maskUrl=imageAndMask.getMaskUrl();
    if ((maskUrl != null) && (!excludeMask)) {
      maskSourceProcessor=imageProcessorCache.get(maskUrl,downSampleLevels,true,false);
    }
 else {
      maskSourceProcessor=null;
    }
    loadMaskStop=System.currentTimeMillis();
    final CoordinateTransformList<CoordinateTransform> ctlMipmap=new CoordinateTransformList<>();
    ctlMipmap.add(Utils.createScaleLevelTransform(mipmapLevel));
    ctlMipmap.add(ctl);
    ctListCreationStop=System.currentTimeMillis();
    final RenderTransformMesh mesh=new RenderTransformMesh(ctlMipmap,(int)(width / meshCellSize + 0.5),ipMipmap.getWidth(),ipMipmap.getHeight());
    mesh.bounds(min,max);
    final int tx=(int)Math.max(0,Math.min(targetWidth,min[0]));
    final int ty=(int)Math.max(0,Math.min(targetHeight,min[1]));
    final int w=(int)(Math.min(targetWidth,max[0]) - tx) + 1;
    final int h=(int)(Math.min(targetHeight,max[1]) - ty) + 1;
    if (w <= 0 || h <= 0) {
      LOG.debug("String_Node_Str",ts);
      continue;
    }
    mesh.translateTarget(-tx,-ty);
    mesh.updateAffines();
    meshCreationStop=System.currentTimeMillis();
    final ImageProcessorWithMasks source=new ImageProcessorWithMasks(ipMipmap,maskSourceProcessor,null);
    if ((maskSourceProcessor != null) && (source.mask == null)) {
      LOG.warn("String_Node_Str" + ipMipmap.getWidth() + "String_Node_Str"+ ipMipmap.getHeight()+ "String_Node_Str"+ maskSourceProcessor.getWidth()+ "String_Node_Str"+ maskSourceProcessor.getHeight());
      maskSourceProcessor=null;
    }
    sourceCreationStop=System.currentTimeMillis();
    final ImageProcessor tp=ipMipmap.createProcessor(w,h);
    final ImageProcessor maskTargetProcessor;
    if (maskSourceProcessor != null)     maskTargetProcessor=new ByteProcessor(w,h);
 else     maskTargetProcessor=null;
    final ImageProcessorWithMasks target=new ImageProcessorWithMasks(tp,maskTargetProcessor,null);
    targetCreationStop=System.currentTimeMillis();
    final RenderTransformMeshMappingWithMasks mapping=new RenderTransformMeshMappingWithMasks(mesh);
    final String mapType;
    if (skipInterpolation) {
      mapType="String_Node_Str";
      mapping.map(source,target,numberOfThreads);
    }
 else {
      mapType="String_Node_Str";
      mapping.mapInterpolated(source,target,numberOfThreads);
    }
    mapInterpolatedStop=System.currentTimeMillis();
    final BufferedImage image=targetToARGBImage(target,ts,binaryMask,renderMinIntensity,renderMaxIntensity);
    targetGraphics.drawImage(image,tx,ty,null);
    drawImageStop=System.currentTimeMillis();
    LOG.debug("String_Node_Str",tileSpecIndex,drawImageStop - tileSpecStart,loadMipStop - tileSpecStart,downSampleLevels,filterStop - loadMipStop,loadMaskStop - filterStop,ctListCreationStop - loadMaskStop,meshCreationStop - ctListCreationStop,sourceCreationStop - meshCreationStop,targetCreationStop - sourceCreationStop,mapType,mapInterpolatedStop - targetCreationStop,drawImageStop - mapInterpolatedStop,imageProcessorCache.size());
    tileSpecIndex++;
  }
  targetGraphics.dispose();
  LOG.debug("String_Node_Str",tileSpecs.size(),System.currentTimeMillis() - tileLoopStart);
}