Program: 154010
Project: 154010
Buggy source:
/** 
 * Returns a new WritableRaster which shares all or part of the supplied WritableRaster's DataBuffer.  The new WritableRaster will possess a reference to the supplied WritableRaster, accessible through its getParent() and getWritableParent() methods. <p> This method provides a workaround for a bug in the implementation of WritableRaster.createWritableChild in the initial relase of the Java2 platform. <p> The <code>parentX</code>, <code>parentY</code>, <code>width</code> and <code>height</code> parameters form a Rectangle in this WritableRaster's coordinate space, indicating the area of pixels to be shared.  An error will be thrown if this Rectangle is not contained with the bounds of the supplied WritableRaster. <p> The new WritableRaster may additionally be translated to a different coordinate system for the plane than that used by the supplied WritableRaster.  The childMinX and childMinY parameters give the new (x, y) coordinate of the upper-left pixel of the returned WritableRaster; the coordinate (childMinX, childMinY) in the new WritableRaster will map to the same pixel as the coordinate (parentX, parentY) in the supplied WritableRaster. <p> The new WritableRaster may be defined to contain only a subset of the bands of the supplied WritableRaster, possibly reordered, by means of the bandList parameter.  If bandList is null, it is taken to include all of the bands of the supplied WritableRaster in their current order. <p> To create a new WritableRaster that contains a subregion of the supplied WritableRaster, but shares its coordinate system and bands, this method should be called with childMinX equal to parentX, childMinY equal to parentY, and bandList equal to null.
 * @param raster     The parent WritableRaster.
 * @param parentX    X coordinate of the upper left corner of the sharedrectangle in this WritableRaster's coordinates.
 * @param parentY    Y coordinate of the upper left corner of the sharedrectangle in this WritableRaster's coordinates.
 * @param width      Width of the shared rectangle starting at(<code>parentX</code>, <code>parentY</code>).
 * @param height     Height of the shared rectangle starting at(<code>parentX</code>, <code>parentY</code>).
 * @param childMinX  X coordinate of the upper left corner ofthe returned WritableRaster.
 * @param childMinY  Y coordinate of the upper left corner ofthe returned WritableRaster.
 * @param bandList   Array of band indices, or null to use all bands.
 * @throws RasterFormatException if the subregion is outside of theraster bounds. 
 */
public static WritableRaster createWritableChild(WritableRaster raster,int parentX,int parentY,int width,int height,int childMinX,int childMinY,int bandList[]){
  if (parentX < raster.getMinX()) {
    throw new RasterFormatException(JaiI18N.getString("String_Node_Str"));
  }
  if (parentY < raster.getMinY()) {
    throw new RasterFormatException(JaiI18N.getString("String_Node_Str"));
  }
  if (parentX + width > raster.getWidth() + raster.getMinX()) {
    throw new RasterFormatException(JaiI18N.getString("String_Node_Str"));
  }
  if (parentY + height > raster.getHeight() + raster.getMinY()) {
    throw new RasterFormatException(JaiI18N.getString("String_Node_Str"));
  }
  SampleModel sampleModel=raster.getSampleModel();
  DataBuffer dataBuffer=raster.getDataBuffer();
  int sampleModelTranslateX=raster.getSampleModelTranslateX();
  int sampleModelTranslateY=raster.getSampleModelTranslateY();
  SampleModel sm;
  if (bandList != null) {
    sm=sampleModel.createCompatibleSampleModel(sampleModel.getWidth(),sampleModel.getHeight());
    sm=sm.createSubsetSampleModel(bandList);
  }
 else {
    sm=sampleModel;
  }
  int deltaX=childMinX - parentX;
  int deltaY=childMinY - parentY;
  return new WritableRasterJAI(sm,dataBuffer,new Rectangle(childMinX,childMinY,width,height),new Point(sampleModelTranslateX + deltaX,sampleModelTranslateY + deltaY),raster);
}

Fixed version (ground truth):
/** 
 * Returns a new WritableRaster which shares all or part of the supplied WritableRaster's DataBuffer.  The new WritableRaster will possess a reference to the supplied WritableRaster, accessible through its getParent() and getWritableParent() methods. <p> This method provides a workaround for a bug in the implementation of WritableRaster.createWritableChild in the initial relase of the Java2 platform. <p> The <code>parentX</code>, <code>parentY</code>, <code>width</code> and <code>height</code> parameters form a Rectangle in this WritableRaster's coordinate space, indicating the area of pixels to be shared.  An error will be thrown if this Rectangle is not contained with the bounds of the supplied WritableRaster. <p> The new WritableRaster may additionally be translated to a different coordinate system for the plane than that used by the supplied WritableRaster.  The childMinX and childMinY parameters give the new (x, y) coordinate of the upper-left pixel of the returned WritableRaster; the coordinate (childMinX, childMinY) in the new WritableRaster will map to the same pixel as the coordinate (parentX, parentY) in the supplied WritableRaster. <p> The new WritableRaster may be defined to contain only a subset of the bands of the supplied WritableRaster, possibly reordered, by means of the bandList parameter.  If bandList is null, it is taken to include all of the bands of the supplied WritableRaster in their current order. <p> To create a new WritableRaster that contains a subregion of the supplied WritableRaster, but shares its coordinate system and bands, this method should be called with childMinX equal to parentX, childMinY equal to parentY, and bandList equal to null.
 * @param raster     The parent WritableRaster.
 * @param parentX    X coordinate of the upper left corner of the sharedrectangle in this WritableRaster's coordinates.
 * @param parentY    Y coordinate of the upper left corner of the sharedrectangle in this WritableRaster's coordinates.
 * @param width      Width of the shared rectangle starting at(<code>parentX</code>, <code>parentY</code>).
 * @param height     Height of the shared rectangle starting at(<code>parentX</code>, <code>parentY</code>).
 * @param childMinX  X coordinate of the upper left corner ofthe returned WritableRaster.
 * @param childMinY  Y coordinate of the upper left corner ofthe returned WritableRaster.
 * @param bandList   Array of band indices, or null to use all bands.
 * @throws RasterFormatException if the subregion is outside of theraster bounds. 
 */
public static WritableRaster createWritableChild(WritableRaster raster,int parentX,int parentY,int width,int height,int childMinX,int childMinY,int bandList[]){
  return raster.createWritableChild(parentX,parentY,width,height,childMinX,childMinY,bandList);
}