Program: 11488
Project: 11488
Buggy source:
/** 
 * Generate simulated image for normalization.
 * @param x0             X coordinate of the upper left corner pixel of given tile.
 * @param y0             Y coordinate of the upper left corner pixel of given tile.
 * @param w              Width of given tile.
 * @param h              Height of given tile.
 * @param simulatedImage The simulated image.
 * @return Boolean flag indicating if the simulation is successful.
 */
private boolean generateSimulatedImage(final int x0,final int y0,final int w,final int h,double[][] simulatedImage){
  try {
    int ymin=0;
    int ymax=0;
    if (tileOverlapPercentage >= 0.0f) {
      ymin=Math.max(y0 - (int)(tileSize * tileOverlapPercentage),0);
      ymax=y0 + h;
    }
 else {
      ymin=y0;
      ymax=y0 + h + (int)(tileSize * Math.abs(tileOverlapPercentage));
    }
    final TerrainData terrainData=new TerrainData(w,ymax - ymin);
    final boolean valid=getLocalDEM(x0,ymin,w,ymax - ymin,terrainData);
    if (!valid) {
      return false;
    }
    final double[] earthPoint=new double[3];
    final double[] sensorPos=new double[3];
    for (int y=ymin; y < ymax; y++) {
      final double[] azimuthIndex=new double[w];
      final double[] rangeIndex=new double[w];
      final double[] illuminatedArea=new double[w];
      final double[] elevationAngle=new double[w];
      final boolean[] savePixel=new boolean[w];
      for (int x=x0; x < x0 + w; x++) {
        final int i=x - x0;
        final int xx=x - x0 + 1;
        final int yy=y - ymin + 1;
        final double alt=terrainData.localDEM[yy][xx];
        if (alt == demNoDataValue) {
          savePixel[i]=false;
          continue;
        }
        GeoUtils.geo2xyzWGS84(terrainData.latPixels[yy][xx],terrainData.lonPixels[yy][xx],alt,earthPoint);
        final double zeroDopplerTime=SARGeocoding.getEarthPointZeroDopplerTime(firstLineUTC,lineTimeInterval,wavelength,earthPoint,orbit.sensorPosition,orbit.sensorVelocity);
        double slantRange=SARGeocoding.computeSlantRange(zeroDopplerTime,orbit,earthPoint,sensorPos);
        final double zeroDopplerTimeWithoutBias=zeroDopplerTime + slantRange / Constants.lightSpeedInMetersPerDay;
        azimuthIndex[i]=(zeroDopplerTimeWithoutBias - firstLineUTC) / lineTimeInterval;
        slantRange=SARGeocoding.computeSlantRange(zeroDopplerTimeWithoutBias,orbit,earthPoint,sensorPos);
        rangeIndex[i]=SARGeocoding.computeRangeIndex(srgrFlag,sourceImageWidth,firstLineUTC,lastLineUTC,rangeSpacing,zeroDopplerTimeWithoutBias,slantRange,nearEdgeSlantRange,srgrConvParams);
        if (rangeIndex[i] <= 0.0) {
          continue;
        }
        if (!nearRangeOnLeft) {
          rangeIndex[i]=sourceImageWidth - 1 - rangeIndex[i];
        }
        final LocalGeometry localGeometry=new LocalGeometry(x,y,earthPoint,sensorPos,terrainData,xx,yy);
        illuminatedArea[i]=computeLocalIlluminatedArea(x0,ymin,x,y,localGeometry,terrainData.localDEM,demNoDataValue);
        if (illuminatedArea[i] == noDataValue) {
          savePixel[i]=false;
          continue;
        }
        elevationAngle[i]=computeElevationAngle(slantRange,earthPoint,sensorPos);
        savePixel[i]=rangeIndex[i] >= x0 && rangeIndex[i] < x0 + w && azimuthIndex[i] > y0 - 1 && azimuthIndex[i] < y0 + h;
      }
      if (nearRangeOnLeft) {
        double maxElevAngle=0.0;
        for (int x=x0; x < x0 + w; x++) {
          int i=x - x0;
          if (savePixel[i] && elevationAngle[i] > maxElevAngle) {
            maxElevAngle=elevationAngle[i];
            saveLocalIlluminatedArea(x0,y0,w,h,illuminatedArea[i],azimuthIndex[i],rangeIndex[i],simulatedImage);
          }
        }
      }
 else {
        double maxElevAngle=0.0;
        for (int x=x0 + w - 1; x >= x0; x--) {
          int i=x - x0;
          if (savePixel[i] && elevationAngle[i] > maxElevAngle) {
            maxElevAngle=elevationAngle[i];
            saveLocalIlluminatedArea(x0,y0,w,h,illuminatedArea[i],azimuthIndex[i],rangeIndex[i],simulatedImage);
          }
        }
      }
    }
  }
 catch (  Throwable e) {
    OperatorUtils.catchOperatorException(getId(),e);
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Generate simulated image for normalization.
 * @param x0             X coordinate of the upper left corner pixel of given tile.
 * @param y0             Y coordinate of the upper left corner pixel of given tile.
 * @param w              Width of given tile.
 * @param h              Height of given tile.
 * @param simulatedImage The simulated image.
 * @return Boolean flag indicating if the simulation is successful.
 */
private boolean generateSimulatedImage(final int x0,final int y0,final int w,final int h,double[][] simulatedImage){
  try {
    int ymin=0;
    int ymax=0;
    if (tileOverlapPercentage >= 0.0f) {
      ymin=Math.max(y0 - (int)(tileSize * tileOverlapPercentage),0);
      ymax=y0 + h;
    }
 else {
      ymin=y0;
      ymax=y0 + h + (int)(tileSize * Math.abs(tileOverlapPercentage));
    }
    final TerrainData terrainData=new TerrainData(w,ymax - ymin);
    final boolean valid=getLocalDEM(x0,ymin,w,ymax - ymin,terrainData);
    if (!valid) {
      return false;
    }
    final double[] earthPoint=new double[3];
    final double[] sensorPos=new double[3];
    for (int y=ymin; y < ymax; y++) {
      final double[] azimuthIndex=new double[w];
      final double[] rangeIndex=new double[w];
      final double[] illuminatedArea=new double[w];
      final double[] elevationAngle=new double[w];
      final boolean[] savePixel=new boolean[w];
      for (int x=x0; x < x0 + w; x++) {
        final int i=x - x0;
        final int xx=x - x0 + 1;
        final int yy=y - ymin + 1;
        final double alt=terrainData.localDEM[yy][xx];
        if (alt == demNoDataValue) {
          savePixel[i]=false;
          continue;
        }
        GeoUtils.geo2xyzWGS84(terrainData.latPixels[yy][xx],terrainData.lonPixels[yy][xx],alt,earthPoint);
        final double zeroDopplerTime=SARGeocoding.getEarthPointZeroDopplerTime(firstLineUTC,lineTimeInterval,wavelength,earthPoint,orbit.sensorPosition,orbit.sensorVelocity);
        double slantRange=SARGeocoding.computeSlantRange(zeroDopplerTime,orbit,earthPoint,sensorPos);
        final double zeroDopplerTimeWithoutBias=zeroDopplerTime + slantRange / Constants.lightSpeedInMetersPerDay;
        azimuthIndex[i]=(zeroDopplerTimeWithoutBias - firstLineUTC) / lineTimeInterval;
        slantRange=SARGeocoding.computeSlantRange(zeroDopplerTimeWithoutBias,orbit,earthPoint,sensorPos);
        rangeIndex[i]=SARGeocoding.computeRangeIndex(srgrFlag,sourceImageWidth,firstLineUTC,lastLineUTC,rangeSpacing,zeroDopplerTimeWithoutBias,slantRange,nearEdgeSlantRange,srgrConvParams);
        if (rangeIndex[i] <= 0.0) {
          continue;
        }
        if (!nearRangeOnLeft) {
          rangeIndex[i]=sourceImageWidth - 1 - rangeIndex[i];
        }
        final LocalGeometry localGeometry=new LocalGeometry(earthPoint,sensorPos,terrainData,xx,yy);
        illuminatedArea[i]=computeLocalIlluminatedArea(x0,ymin,x,y,localGeometry,terrainData.localDEM,demNoDataValue);
        if (illuminatedArea[i] == noDataValue) {
          savePixel[i]=false;
          continue;
        }
        elevationAngle[i]=computeElevationAngle(slantRange,earthPoint,sensorPos);
        savePixel[i]=rangeIndex[i] >= x0 && rangeIndex[i] < x0 + w && azimuthIndex[i] > y0 - 1 && azimuthIndex[i] < y0 + h;
      }
      if (nearRangeOnLeft) {
        double maxElevAngle=0.0;
        for (int x=x0; x < x0 + w; x++) {
          int i=x - x0;
          if (savePixel[i] && elevationAngle[i] > maxElevAngle) {
            maxElevAngle=elevationAngle[i];
            saveLocalIlluminatedArea(x0,y0,w,h,illuminatedArea[i],azimuthIndex[i],rangeIndex[i],simulatedImage);
          }
        }
      }
 else {
        double maxElevAngle=0.0;
        for (int x=x0 + w - 1; x >= x0; x--) {
          int i=x - x0;
          if (savePixel[i] && elevationAngle[i] > maxElevAngle) {
            maxElevAngle=elevationAngle[i];
            saveLocalIlluminatedArea(x0,y0,w,h,illuminatedArea[i],azimuthIndex[i],rangeIndex[i],simulatedImage);
          }
        }
      }
    }
  }
 catch (  Throwable e) {
    OperatorUtils.catchOperatorException(getId(),e);
  }
  return true;
}