Program: 170354
Project: 170354
Buggy source:
private boolean updateAngleBands(Product multiSizeProduct,Product targetProduct,S2BandConstants bandConstants){
  Vector<RenderedOp> inputsZenith=new Vector(17);
  Vector<RenderedOp> inputsAzimuth=new Vector(17);
  String azimuthAnglesBandName=String.format("String_Node_Str",bandConstants.getPhysicalName());
  String zenithAnglesBandName=String.format("String_Node_Str",bandConstants.getPhysicalName());
  Band bandZenith=targetProduct.getBand(zenithAnglesBandName);
  Band bandAzimuth=targetProduct.getBand(azimuthAnglesBandName);
  if (bandAzimuth == null || bandZenith == null) {
    return false;
  }
  for (int detectorId=1; detectorId <= 12; detectorId++) {
    String maskName=String.format("String_Node_Str",bandConstants.getFilenameBandId(),detectorId);
    String nextMaskName=String.format("String_Node_Str",bandConstants.getFilenameBandId(),detectorId + 1);
    if (multiSizeProduct.getMaskGroup().get(maskName) == null) {
      continue;
    }
    String maskExpression;
    if (multiSizeProduct.getMaskGroup().get(nextMaskName) == null) {
      maskExpression=String.format("String_Node_Str",maskName);
    }
 else {
      maskExpression=String.format("String_Node_Str",maskName,nextMaskName);
    }
    MultiLevelImage footprint=multiSizeProduct.getMaskImage(maskExpression,multiSizeProduct.getBand(bandConstants.getPhysicalName()));
    MultiLevelImage footprintFinal=S2ResamplerUtils.createInterpolatedImage(footprint,0.0f,multiSizeProduct.getBand(bandConstants.getPhysicalName()).getImageToModelTransform(),referenceWidth,referenceHeight,referenceTileSize,referenceMultiLevelModel,S2ResamplerUtils.getInterpolation("String_Node_Str"));
    S2BandAnglesGridByDetector[] anglesGridByDetector=((Sentinel2OrthoProductReader)multiSizeProduct.getProductReader()).getMetadataHeader().getAnglesGridByDetector(bandConstants.getBandIndex(),detectorId);
    float[] extendedZenithData=S2ResamplerUtils.extendDataV2(anglesGridByDetector[0].getData(),anglesGridByDetector[0].getWidth(),anglesGridByDetector[0].getHeight());
    float[] extendedAzimuthData=S2ResamplerUtils.extendDataV2(anglesGridByDetector[1].getData(),anglesGridByDetector[1].getWidth(),anglesGridByDetector[1].getHeight());
    int extendedWidth=anglesGridByDetector[0].getWidth() + 2;
    int extendedHeight=anglesGridByDetector[0].getHeight() + 2;
    AffineTransform originalAffineTransform5000=new AffineTransform(anglesGridByDetector[0].getResX(),0.0f,0.0f,-anglesGridByDetector[0].getResX(),anglesGridByDetector[0].originX,anglesGridByDetector[0].originY);
    AffineTransform extendedAffineTransform5000=(AffineTransform)originalAffineTransform5000.clone();
    extendedAffineTransform5000.translate(-1d,-1d);
    MultiLevelImage zenithMultiLevelImage=S2ResamplerUtils.createMultiLevelImage(extendedZenithData,extendedWidth,extendedHeight,extendedAffineTransform5000);
    MultiLevelImage targetImageZenith=S2ResamplerUtils.createInterpolatedImage(zenithMultiLevelImage,0.0f,extendedAffineTransform5000,referenceWidth,referenceHeight,referenceTileSize,referenceMultiLevelModel,S2ResamplerUtils.getInterpolation("String_Node_Str"));
    MultiLevelImage azimuthMultiLevelImage=S2ResamplerUtils.createMultiLevelImage(extendedAzimuthData,extendedWidth,extendedHeight,extendedAffineTransform5000);
    MultiLevelImage targetImageAzimuth=S2ResamplerUtils.createInterpolatedImage(azimuthMultiLevelImage,0.0f,extendedAffineTransform5000,referenceWidth,referenceHeight,referenceTileSize,referenceMultiLevelModel,S2ResamplerUtils.getInterpolation("String_Node_Str"));
    ImageLayout imageLayout=new ImageLayout();
    imageLayout.setMinX(0);
    imageLayout.setMinY(0);
    imageLayout.setTileWidth(DEFAULT_JAI_TILE_SIZE);
    imageLayout.setTileHeight(DEFAULT_JAI_TILE_SIZE);
    imageLayout.setTileGridXOffset(0);
    imageLayout.setTileGridYOffset(0);
    RenderingHints hints=new RenderingHints(JAI.KEY_TILE_CACHE,JAI.getDefaultInstance().getTileCache());
    hints.put(JAI.KEY_IMAGE_LAYOUT,imageLayout);
    RenderedOp multiZenith=MultiplyDescriptor.create(targetImageZenith.getImage(0),footprintFinal.getImage(0),hints);
    multiZenith=MultiplyConstDescriptor.create(multiZenith,new double[]{1 / 255.0},hints);
    RenderedOp multiAzimuth=MultiplyDescriptor.create(targetImageAzimuth.getImage(0),footprintFinal.getImage(0),hints);
    multiAzimuth=MultiplyConstDescriptor.create(multiAzimuth,new double[]{1 / 255.0},hints);
    inputsZenith.add(multiZenith);
    inputsAzimuth.add(multiAzimuth);
  }
  if (inputsAzimuth.size() == 0 || inputsZenith.size() == 0) {
    return false;
  }
  ImageLayout imageLayout=new ImageLayout();
  imageLayout.setMinX(0);
  imageLayout.setMinY(0);
  imageLayout.setTileWidth(DEFAULT_JAI_TILE_SIZE);
  imageLayout.setTileHeight(DEFAULT_JAI_TILE_SIZE);
  imageLayout.setTileGridXOffset(0);
  imageLayout.setTileGridYOffset(0);
  RenderingHints hints=new RenderingHints(JAI.KEY_TILE_CACHE,JAI.getDefaultInstance().getTileCache());
  hints.put(JAI.KEY_IMAGE_LAYOUT,imageLayout);
  RenderedOp finalAnglesZenith=AddCollectionDescriptor.create(inputsZenith,hints);
  RenderedOp finalAnglesAzimuth=AddCollectionDescriptor.create(inputsAzimuth,hints);
  MultiLevelImage finalImageZenith=new DefaultMultiLevelImage(new DefaultMultiLevelSource(finalAnglesZenith,referenceMultiLevelModel,Interpolation.getInstance(Interpolation.INTERP_NEAREST)));
  MultiLevelImage finalImageAzimuth=new DefaultMultiLevelImage(new DefaultMultiLevelSource(finalAnglesAzimuth,referenceMultiLevelModel,Interpolation.getInstance(Interpolation.INTERP_NEAREST)));
  bandZenith.setSourceImage(S2ResamplerUtils.adjustImageToModelTransform(finalImageZenith,referenceMultiLevelModel));
  bandAzimuth.setSourceImage(S2ResamplerUtils.adjustImageToModelTransform(finalImageAzimuth,referenceMultiLevelModel));
  return true;
}

Fixed version (ground truth):
private boolean updateAngleBands(Product multiSizeProduct,Product targetProduct,S2BandConstants bandConstants){
  Vector<RenderedOp> inputsZenith=new Vector(17);
  Vector<RenderedOp> inputsAzimuth=new Vector(17);
  String azimuthAnglesBandName=String.format("String_Node_Str",bandConstants.getPhysicalName());
  String zenithAnglesBandName=String.format("String_Node_Str",bandConstants.getPhysicalName());
  Band bandZenith=targetProduct.getBand(zenithAnglesBandName);
  Band bandAzimuth=targetProduct.getBand(azimuthAnglesBandName);
  if (bandAzimuth == null || bandZenith == null) {
    return false;
  }
  for (int detectorId=1; detectorId <= 12; detectorId++) {
    String maskName=String.format("String_Node_Str",bandConstants.getFilenameBandId(),detectorId);
    String nextMaskName=String.format("String_Node_Str",bandConstants.getFilenameBandId(),detectorId + 1);
    if (multiSizeProduct.getMaskGroup().get(maskName) == null) {
      continue;
    }
    String maskExpression;
    if (multiSizeProduct.getMaskGroup().get(nextMaskName) == null) {
      maskExpression=String.format("String_Node_Str",maskName);
    }
 else {
      maskExpression=String.format("String_Node_Str",maskName,nextMaskName);
    }
    MultiLevelImage footprint=multiSizeProduct.getMaskImage(maskExpression,multiSizeProduct.getBand(bandConstants.getPhysicalName()));
    MultiLevelImage footprintFinal=S2ResamplerUtils.createInterpolatedImage(footprint,0.0f,multiSizeProduct.getBand(bandConstants.getPhysicalName()).getImageToModelTransform(),referenceWidth,referenceHeight,referenceTileSize,referenceMultiLevelModel,S2ResamplerUtils.getInterpolation("String_Node_Str"));
    S2BandAnglesGridByDetector[] anglesGridByDetector=((Sentinel2OrthoProductReader)multiSizeProduct.getProductReader()).getMetadataHeader().getAnglesGridByDetector(bandConstants.getBandIndex(),detectorId);
    float[] extendedZenithData=S2ResamplerUtils.extendDataV2(anglesGridByDetector[0].getData(),anglesGridByDetector[0].getWidth(),anglesGridByDetector[0].getHeight());
    float[] extendedAzimuthData=S2ResamplerUtils.extendDataV2(anglesGridByDetector[1].getData(),anglesGridByDetector[1].getWidth(),anglesGridByDetector[1].getHeight());
    int extendedWidth=anglesGridByDetector[0].getWidth() + 2;
    int extendedHeight=anglesGridByDetector[0].getHeight() + 2;
    AffineTransform originalAffineTransform5000=new AffineTransform(anglesGridByDetector[0].getResX(),0.0f,0.0f,-anglesGridByDetector[0].getResX(),anglesGridByDetector[0].originX,anglesGridByDetector[0].originY);
    AffineTransform extendedAffineTransform5000=(AffineTransform)originalAffineTransform5000.clone();
    extendedAffineTransform5000.translate(-1d,-1d);
    MultiLevelImage zenithMultiLevelImage=S2ResamplerUtils.createMultiLevelImage(extendedZenithData,extendedWidth,extendedHeight,extendedAffineTransform5000);
    MultiLevelImage targetImageZenith=S2ResamplerUtils.createInterpolatedImage(zenithMultiLevelImage,0.0f,extendedAffineTransform5000,referenceWidth,referenceHeight,referenceTileSize,referenceMultiLevelModel,S2ResamplerUtils.getInterpolation("String_Node_Str"));
    MultiLevelImage azimuthMultiLevelImage=S2ResamplerUtils.createMultiLevelImage(extendedAzimuthData,extendedWidth,extendedHeight,extendedAffineTransform5000);
    MultiLevelImage targetImageAzimuth=S2ResamplerUtils.createInterpolatedImage(azimuthMultiLevelImage,0.0f,extendedAffineTransform5000,referenceWidth,referenceHeight,referenceTileSize,referenceMultiLevelModel,S2ResamplerUtils.getInterpolation("String_Node_Str"));
    ImageLayout imageLayout=new ImageLayout();
    imageLayout.setMinX(0);
    imageLayout.setMinY(0);
    imageLayout.setTileWidth(DEFAULT_JAI_TILE_SIZE);
    imageLayout.setTileHeight(DEFAULT_JAI_TILE_SIZE);
    imageLayout.setTileGridXOffset(0);
    imageLayout.setTileGridYOffset(0);
    RenderingHints hints=new RenderingHints(JAI.KEY_TILE_CACHE,JAI.getDefaultInstance().getTileCache());
    hints.put(JAI.KEY_IMAGE_LAYOUT,imageLayout);
    RenderedOp multiZenith=MultiplyDescriptor.create(targetImageZenith.getImage(0),footprintFinal.getImage(0),hints);
    multiZenith=MultiplyConstDescriptor.create(multiZenith,new double[]{1 / 255.0},hints);
    RenderedOp multiAzimuth=MultiplyDescriptor.create(targetImageAzimuth.getImage(0),footprintFinal.getImage(0),hints);
    multiAzimuth=MultiplyConstDescriptor.create(multiAzimuth,new double[]{1 / 255.0},hints);
    inputsZenith.add(multiZenith);
    inputsAzimuth.add(multiAzimuth);
  }
  if (inputsAzimuth.size() == 0 || inputsZenith.size() == 0) {
    return false;
  }
  ImageLayout imageLayout=new ImageLayout();
  imageLayout.setMinX(0);
  imageLayout.setMinY(0);
  imageLayout.setTileWidth(DEFAULT_JAI_TILE_SIZE);
  imageLayout.setTileHeight(DEFAULT_JAI_TILE_SIZE);
  imageLayout.setTileGridXOffset(0);
  imageLayout.setTileGridYOffset(0);
  RenderingHints hints=new RenderingHints(JAI.KEY_TILE_CACHE,JAI.getDefaultInstance().getTileCache());
  hints.put(JAI.KEY_IMAGE_LAYOUT,imageLayout);
  RenderedOp finalAnglesZenith;
  RenderedOp finalAnglesAzimuth;
  if (inputsZenith.size() > 1) {
    finalAnglesZenith=AddCollectionDescriptor.create(inputsZenith,hints);
  }
 else {
    finalAnglesZenith=inputsZenith.firstElement();
  }
  if (inputsAzimuth.size() > 1) {
    finalAnglesAzimuth=AddCollectionDescriptor.create(inputsAzimuth,hints);
  }
 else {
    finalAnglesAzimuth=inputsAzimuth.firstElement();
  }
  MultiLevelImage finalImageZenith=new DefaultMultiLevelImage(new DefaultMultiLevelSource(finalAnglesZenith,referenceMultiLevelModel,Interpolation.getInstance(Interpolation.INTERP_NEAREST)));
  MultiLevelImage finalImageAzimuth=new DefaultMultiLevelImage(new DefaultMultiLevelSource(finalAnglesAzimuth,referenceMultiLevelModel,Interpolation.getInstance(Interpolation.INTERP_NEAREST)));
  bandZenith.setSourceImage(S2ResamplerUtils.adjustImageToModelTransform(finalImageZenith,referenceMultiLevelModel));
  bandAzimuth.setSourceImage(S2ResamplerUtils.adjustImageToModelTransform(finalImageAzimuth,referenceMultiLevelModel));
  return true;
}