Program: 25590
Project: 25590
Buggy source:
public static void render(final List<TileSpec> tileSpecs,final BufferedImage targetImage,final double x,final double y,final double triangleSize,final double scale,final boolean areaOffset,final int numberOfThreads,final boolean skipInterpolation,final boolean doFilter) throws IllegalArgumentException {
  final Graphics2D targetGraphics=targetImage.createGraphics();
  LOG.debug("String_Node_Str",tileSpecs.size(),numberOfThreads);
  final long tileLoopStart=System.currentTimeMillis();
  int tileSpecIndex=0;
  long tileSpecStart;
  long loadMipStop;
  long scaleMipStop;
  long loadMaskStop;
  long ctListCreationStop;
  long meshCreationStop;
  long sourceCreationStop;
  long targetCreationStop;
  long mapInterpolatedStop;
  long drawImageStop;
  final ByteProcessorCache byteProcessorCache=new ByteProcessorCache();
  ByteProcessor bpMaskSource;
  ByteProcessor bpMaskTarget;
  for (  final TileSpec ts : tileSpecs) {
    tileSpecStart=System.currentTimeMillis();
    final CoordinateTransformList<CoordinateTransform> ctl=ts.createTransformList();
    final AffineModel2D scaleAndOffset=new AffineModel2D();
    if (areaOffset) {
      final double offset=(1 - scale) * 0.5;
      scaleAndOffset.set((float)scale,0,0,(float)scale,-(float)(x * scale + offset),-(float)(y * scale + offset));
    }
 else {
      scaleAndOffset.set((float)scale,0,0,(float)scale,-(float)(x * scale),-(float)(y * scale));
    }
    ctl.add(scaleAndOffset);
    Map.Entry<Integer,ImageAndMask> mipmapEntry;
    ImageAndMask imageAndMask=null;
    ImageProcessor ip=null;
    int width=ts.getWidth();
    int height=ts.getHeight();
    if ((width < 0) || (height < 0)) {
      mipmapEntry=ts.getFirstMipmapEntry();
      imageAndMask=mipmapEntry.getValue();
      final ImagePlus imp=getImagePlusForMipmap(imageAndMask);
      ip=imp.getProcessor();
      width=imp.getWidth();
      height=imp.getHeight();
    }
    final double s=Utils.sampleAverageScale(ctl,width,height,triangleSize);
    int mipmapLevel=Utils.bestMipmapLevel(s);
    Integer downSampleLevels=null;
    final ImageProcessor ipMipmap;
    if (ip == null) {
      mipmapEntry=ts.getFloorMipmapEntry(mipmapLevel);
      imageAndMask=mipmapEntry.getValue();
      final ImagePlus imp=getImagePlusForMipmap(imageAndMask);
      loadMipStop=System.currentTimeMillis();
      ip=imp.getProcessor();
      final int currentMipmapLevel=mipmapEntry.getKey();
      if (currentMipmapLevel >= mipmapLevel) {
        mipmapLevel=currentMipmapLevel;
        ipMipmap=ip;
        LOG.debug("String_Node_Str",mipmapLevel);
      }
 else {
        downSampleLevels=mipmapLevel - currentMipmapLevel;
        LOG.debug("String_Node_Str",currentMipmapLevel,mipmapLevel);
        ipMipmap=Downsampler.downsampleImageProcessor(ip,downSampleLevels);
      }
    }
 else {
      loadMipStop=System.currentTimeMillis();
      downSampleLevels=mipmapLevel;
      LOG.debug("String_Node_Str",mipmapLevel);
      ipMipmap=Downsampler.downsampleImageProcessor(ip,downSampleLevels);
    }
    if (doFilter) {
      final double mipmapScale=1.0 / (1 << mipmapLevel);
      vtnf1.process(ipMipmap,mipmapScale);
      vtnf2.process(ipMipmap,mipmapScale);
      nlcf.process(ipMipmap,mipmapScale);
    }
    final ImageProcessor tp=ipMipmap.createProcessor(targetImage.getWidth(),targetImage.getHeight());
    scaleMipStop=System.currentTimeMillis();
    bpMaskSource=null;
    bpMaskTarget=null;
    final String maskUrl=imageAndMask.getMaskUrl();
    if (maskUrl != null) {
      bpMaskSource=byteProcessorCache.getProcessor(maskUrl,downSampleLevels);
      if (bpMaskSource != null) {
        bpMaskTarget=new ByteProcessor(tp.getWidth(),tp.getHeight());
      }
    }
    loadMaskStop=System.currentTimeMillis();
    final CoordinateTransformList<CoordinateTransform> ctlMipmap=new CoordinateTransformList<CoordinateTransform>();
    ctlMipmap.add(Utils.createScaleLevelTransform(mipmapLevel));
    ctlMipmap.add(ctl);
    ctListCreationStop=System.currentTimeMillis();
    final CoordinateTransformMesh mesh=new CoordinateTransformMesh(ctlMipmap,(int)(width / triangleSize + 0.5),ipMipmap.getWidth(),ipMipmap.getHeight());
    meshCreationStop=System.currentTimeMillis();
    final ImageProcessorWithMasks source=new ImageProcessorWithMasks(ipMipmap,bpMaskSource,null);
    if ((bpMaskTarget != null) && (source.mask == null)) {
      LOG.warn("String_Node_Str" + ipMipmap.getWidth() + "String_Node_Str"+ ipMipmap.getHeight()+ "String_Node_Str"+ bpMaskSource.getWidth()+ "String_Node_Str"+ bpMaskSource.getHeight());
      bpMaskTarget=null;
    }
    sourceCreationStop=System.currentTimeMillis();
    final ImageProcessorWithMasks target=new ImageProcessorWithMasks(tp,bpMaskTarget,null);
    targetCreationStop=System.currentTimeMillis();
    final TransformMeshMappingWithMasks<TransformMesh> mapping=new TransformMeshMappingWithMasks<TransformMesh>(mesh);
    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();
    tp.setMinAndMax(ts.getMinIntensity(),ts.getMaxIntensity());
    final ColorProcessor cp=tp.convertToColorProcessor();
    final int[] cpPixels=(int[])cp.getPixels();
    final byte[] alphaPixels;
    if (bpMaskTarget != null) {
      alphaPixels=(byte[])bpMaskTarget.getPixels();
    }
 else {
      alphaPixels=(byte[])target.outside.getPixels();
    }
    for (int i=0; i < cpPixels.length; ++i) {
      cpPixels[i]&=0x00ffffff | (alphaPixels[i] << 24);
    }
    final BufferedImage image=new BufferedImage(cp.getWidth(),cp.getHeight(),BufferedImage.TYPE_INT_ARGB);
    final WritableRaster raster=image.getRaster();
    raster.setDataElements(0,0,cp.getWidth(),cp.getHeight(),cpPixels);
    targetGraphics.drawImage(image,0,0,null);
    drawImageStop=System.currentTimeMillis();
    LOG.debug("String_Node_Str",tileSpecIndex,drawImageStop - tileSpecStart,loadMipStop - tileSpecStart,downSampleLevels,scaleMipStop - loadMipStop,loadMaskStop - scaleMipStop,ctListCreationStop - loadMaskStop,meshCreationStop - ctListCreationStop,sourceCreationStop - meshCreationStop,targetCreationStop - sourceCreationStop,mapType,mapInterpolatedStop - targetCreationStop,drawImageStop - mapInterpolatedStop);
    tileSpecIndex++;
  }
  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 triangleSize,final double scale,final boolean areaOffset,final int numberOfThreads,final boolean skipInterpolation,final boolean doFilter) throws IllegalArgumentException {
  final Graphics2D targetGraphics=targetImage.createGraphics();
  LOG.debug("String_Node_Str",tileSpecs.size(),numberOfThreads);
  final long tileLoopStart=System.currentTimeMillis();
  int tileSpecIndex=0;
  long tileSpecStart;
  long loadMipStop;
  long scaleMipStop;
  long loadMaskStop;
  long ctListCreationStop;
  long meshCreationStop;
  long sourceCreationStop;
  long targetCreationStop;
  long mapInterpolatedStop;
  long drawImageStop;
  final ByteProcessorCache byteProcessorCache=new ByteProcessorCache();
  ByteProcessor bpMaskSource;
  ByteProcessor bpMaskTarget;
  for (  final TileSpec ts : tileSpecs) {
    tileSpecStart=System.currentTimeMillis();
    final CoordinateTransformList<CoordinateTransform> ctl=new CoordinateTransformList<CoordinateTransform>();
    for (    final CoordinateTransform t : ts.getTransformList().getList(null))     ctl.add(t);
    final AffineModel2D scaleAndOffset=new AffineModel2D();
    if (areaOffset) {
      final double offset=(1 - scale) * 0.5;
      scaleAndOffset.set((float)scale,0,0,(float)scale,-(float)(x * scale + offset),-(float)(y * scale + offset));
    }
 else {
      scaleAndOffset.set((float)scale,0,0,(float)scale,-(float)(x * scale),-(float)(y * scale));
    }
    ctl.add(scaleAndOffset);
    Map.Entry<Integer,ImageAndMask> mipmapEntry;
    ImageAndMask imageAndMask=null;
    ImageProcessor ip=null;
    int width=ts.getWidth();
    int height=ts.getHeight();
    if ((width < 0) || (height < 0)) {
      mipmapEntry=ts.getFirstMipmapEntry();
      imageAndMask=mipmapEntry.getValue();
      final ImagePlus imp=getImagePlusForMipmap(imageAndMask);
      ip=imp.getProcessor();
      width=imp.getWidth();
      height=imp.getHeight();
    }
    final double s=Utils.sampleAverageScale(ctl,width,height,triangleSize);
    int mipmapLevel=Utils.bestMipmapLevel(s);
    Integer downSampleLevels=null;
    final ImageProcessor ipMipmap;
    if (ip == null) {
      mipmapEntry=ts.getFloorMipmapEntry(mipmapLevel);
      imageAndMask=mipmapEntry.getValue();
      final ImagePlus imp=getImagePlusForMipmap(imageAndMask);
      loadMipStop=System.currentTimeMillis();
      ip=imp.getProcessor();
      final int currentMipmapLevel=mipmapEntry.getKey();
      if (currentMipmapLevel >= mipmapLevel) {
        mipmapLevel=currentMipmapLevel;
        ipMipmap=ip;
        LOG.debug("String_Node_Str",mipmapLevel);
      }
 else {
        downSampleLevels=mipmapLevel - currentMipmapLevel;
        LOG.debug("String_Node_Str",currentMipmapLevel,mipmapLevel);
        ipMipmap=Downsampler.downsampleImageProcessor(ip,downSampleLevels);
      }
    }
 else {
      loadMipStop=System.currentTimeMillis();
      downSampleLevels=mipmapLevel;
      LOG.debug("String_Node_Str",mipmapLevel);
      ipMipmap=Downsampler.downsampleImageProcessor(ip,downSampleLevels);
    }
    if (doFilter) {
      final double mipmapScale=1.0 / (1 << mipmapLevel);
      vtnf1.process(ipMipmap,mipmapScale);
      vtnf2.process(ipMipmap,mipmapScale);
      nlcf.process(ipMipmap,mipmapScale);
    }
    final ImageProcessor tp=ipMipmap.createProcessor(targetImage.getWidth(),targetImage.getHeight());
    scaleMipStop=System.currentTimeMillis();
    bpMaskSource=null;
    bpMaskTarget=null;
    final String maskUrl=imageAndMask.getMaskUrl();
    if (maskUrl != null) {
      bpMaskSource=byteProcessorCache.getProcessor(maskUrl,downSampleLevels);
      if (bpMaskSource != null) {
        bpMaskTarget=new ByteProcessor(tp.getWidth(),tp.getHeight());
      }
    }
    loadMaskStop=System.currentTimeMillis();
    final CoordinateTransformList<CoordinateTransform> ctlMipmap=new CoordinateTransformList<CoordinateTransform>();
    ctlMipmap.add(Utils.createScaleLevelTransform(mipmapLevel));
    ctlMipmap.add(ctl);
    ctListCreationStop=System.currentTimeMillis();
    final CoordinateTransformMesh mesh=new CoordinateTransformMesh(ctlMipmap,(int)(width / triangleSize + 0.5),ipMipmap.getWidth(),ipMipmap.getHeight());
    meshCreationStop=System.currentTimeMillis();
    final ImageProcessorWithMasks source=new ImageProcessorWithMasks(ipMipmap,bpMaskSource,null);
    if ((bpMaskTarget != null) && (source.mask == null)) {
      LOG.warn("String_Node_Str" + ipMipmap.getWidth() + "String_Node_Str"+ ipMipmap.getHeight()+ "String_Node_Str"+ bpMaskSource.getWidth()+ "String_Node_Str"+ bpMaskSource.getHeight());
      bpMaskTarget=null;
    }
    sourceCreationStop=System.currentTimeMillis();
    final ImageProcessorWithMasks target=new ImageProcessorWithMasks(tp,bpMaskTarget,null);
    targetCreationStop=System.currentTimeMillis();
    final TransformMeshMappingWithMasks<TransformMesh> mapping=new TransformMeshMappingWithMasks<TransformMesh>(mesh);
    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();
    tp.setMinAndMax(ts.getMinIntensity(),ts.getMaxIntensity());
    final ColorProcessor cp=tp.convertToColorProcessor();
    final int[] cpPixels=(int[])cp.getPixels();
    final byte[] alphaPixels;
    if (bpMaskTarget != null) {
      alphaPixels=(byte[])bpMaskTarget.getPixels();
    }
 else {
      alphaPixels=(byte[])target.outside.getPixels();
    }
    for (int i=0; i < cpPixels.length; ++i) {
      cpPixels[i]&=0x00ffffff | (alphaPixels[i] << 24);
    }
    final BufferedImage image=new BufferedImage(cp.getWidth(),cp.getHeight(),BufferedImage.TYPE_INT_ARGB);
    final WritableRaster raster=image.getRaster();
    raster.setDataElements(0,0,cp.getWidth(),cp.getHeight(),cpPixels);
    targetGraphics.drawImage(image,0,0,null);
    drawImageStop=System.currentTimeMillis();
    LOG.debug("String_Node_Str",tileSpecIndex,drawImageStop - tileSpecStart,loadMipStop - tileSpecStart,downSampleLevels,scaleMipStop - loadMipStop,loadMaskStop - scaleMipStop,ctListCreationStop - loadMaskStop,meshCreationStop - ctListCreationStop,sourceCreationStop - meshCreationStop,targetCreationStop - sourceCreationStop,mapType,mapInterpolatedStop - targetCreationStop,drawImageStop - mapInterpolatedStop);
    tileSpecIndex++;
  }
  LOG.debug("String_Node_Str",tileSpecs.size(),System.currentTimeMillis() - tileLoopStart);
}