nus-yam/ex-repair huggingface dataset:
Program: 93381
Project: 93381
Buggy source:
/** 
 * Utility function to create a two-level tile cache with the right size. When the cache is created we do not actually know the size of the mapview, so the screenRatio is an approximation of the required size
 * @param c              the Android context
 * @param id             name for the storage directory
 * @param tileSize       tile size
 * @param screenRatio    part of the screen the view takes up
 * @param overdraw       overdraw allowance
 * @return a new cache created on the external storage
 */
public static TileCache createTileCache(Context c,String id,int tileSize,float screenRatio,double overdraw){
  int cacheSize=(int)Math.round(AndroidUtil.getMinimumCacheSize(c,tileSize,overdraw,screenRatio));
  return createExternalStorageTileCache(c,id,cacheSize,tileSize);
}

Fixed version (ground truth):
/** 
 * Utility function to create a two-level tile cache with the right size. When the cache is created we do not actually know the size of the mapview, so the screenRatio is an approximation of the required size
 * @param c              the Android context
 * @param id             name for the storage directory
 * @param tileSize       tile size
 * @param screenRatio    part of the screen the view takes up
 * @param overdraw       overdraw allowance
 * @return a new cache created on the external storage
 */
public static TileCache createTileCache(Context c,String id,int tileSize,float screenRatio,double overdraw){
  int cacheSize=Math.round(AndroidUtil.getMinimumCacheSize(c,tileSize,overdraw,screenRatio));
  return createExternalStorageTileCache(c,id,cacheSize,tileSize);
}
Program: 93382
Project: 93382
Buggy source:
@Override public void draw(BoundingBox boundingBox,byte zoomLevel,Canvas canvas,Point topLeftPoint){
  List<TilePosition> tilePositions=LayerUtil.getTilePositions(boundingBox,zoomLevel,topLeftPoint,this.displayModel.getTileSize());
  if (!isTransparent) {
    canvas.fillColor(this.displayModel.getBackgroundColor());
  }
  for (int i=tilePositions.size() - 1; i >= 0; --i) {
    TilePosition tilePosition=tilePositions.get(i);
    Point point=tilePosition.point;
    Tile tile=tilePosition.tile;
    Bitmap bitmap=this.tileCache.get(createJob(tile));
    if (bitmap == null) {
      this.jobQueue.add(createJob(tile));
      drawParentTileBitmap(canvas,point,tile);
    }
 else {
      canvas.drawBitmap(bitmap,(int)Math.round(point.x),(int)Math.round(point.y));
      bitmap.decrementRefCount();
    }
  }
  this.jobQueue.notifyWorkers();
}

Fixed version (ground truth):
@Override public void draw(BoundingBox boundingBox,byte zoomLevel,Canvas canvas,Point topLeftPoint){
  List<TilePosition> tilePositions=LayerUtil.getTilePositions(boundingBox,zoomLevel,topLeftPoint,this.displayModel.getTileSize());
  canvas.resetClip();
  if (!isTransparent) {
    canvas.fillColor(this.displayModel.getBackgroundColor());
  }
  for (int i=tilePositions.size() - 1; i >= 0; --i) {
    TilePosition tilePosition=tilePositions.get(i);
    Point point=tilePosition.point;
    Tile tile=tilePosition.tile;
    Bitmap bitmap=this.tileCache.get(createJob(tile));
    if (bitmap == null) {
      this.jobQueue.add(createJob(tile));
      drawParentTileBitmap(canvas,point,tile);
    }
 else {
      canvas.drawBitmap(bitmap,(int)Math.round(point.x),(int)Math.round(point.y));
      bitmap.decrementRefCount();
    }
  }
  this.jobQueue.notifyWorkers();
}
Program: 93383
Project: 93383
Buggy source:
@Override public void renderArea(Paint fill,Paint stroke,int level){
  List<ShapePaintContainer> list=this.drawingLayers.get(level);
  list.add(new ShapePaintContainer(this.shapeContainer,fill));
  list.add(new ShapePaintContainer(this.shapeContainer,stroke));
}

Fixed version (ground truth):
@Override public void renderArea(Paint fill,Paint stroke,int level){
  List<ShapePaintContainer> list=this.drawingLayers.get(level);
  list.add(new ShapePaintContainer(this.shapeContainer,stroke));
  list.add(new ShapePaintContainer(this.shapeContainer,fill));
}
Program: 93384
Project: 93384
Buggy source:
public static Point getTopLeftPoint(MapPosition mapPosition,Dimension canvasDimension){
  LatLong centerPoint=mapPosition.latLong;
  byte zoomLevel=mapPosition.zoomLevel;
  int halfCanvasWidth=canvasDimension.width / 2;
  int halfCanvasHeight=canvasDimension.height / 2;
  double pixelX=MercatorProjection.longitudeToPixelX(centerPoint.longitude,zoomLevel) - halfCanvasWidth;
  double pixelY=MercatorProjection.latitudeToPixelY(centerPoint.latitude,zoomLevel) - halfCanvasHeight;
  return new Point(pixelX,pixelY);
}

Fixed version (ground truth):
public static Point getTopLeftPoint(MapPosition mapPosition,Dimension canvasDimension){
  LatLong centerPoint=mapPosition.latLong;
  byte zoomLevel=mapPosition.zoomLevel;
  int halfCanvasWidth=canvasDimension.width / 2;
  int halfCanvasHeight=canvasDimension.height / 2;
  double pixelX=Math.round(MercatorProjection.longitudeToPixelX(centerPoint.longitude,zoomLevel));
  double pixelY=Math.round(MercatorProjection.latitudeToPixelY(centerPoint.latitude,zoomLevel));
  return new Point((int)pixelX - halfCanvasWidth,(int)pixelY - halfCanvasHeight);
}
Program: 93385
Project: 93385
Buggy source:
@Override protected void init(){
  super.init();
  this.mapView2.getModel().mapViewPosition.setZoomLevel((byte)12);
  this.observer=new MapViewPositionObserver(this.mapView.getModel().mapViewPosition,this.mapView2.getModel().mapViewPosition){
    Polyline lastLine;
    @Override protected void setCenter(){
      super.setCenter();
      BoundingBox bbox=MapPositionUtil.getBoundingBox(DualOverviewMapViewer.this.mapView.getModel().mapViewPosition.getMapPosition(),DualOverviewMapViewer.this.mapView.getDimension());
      Paint paintStroke=Utils.createPaint(AndroidGraphicFactory.INSTANCE.createColor(Color.RED),2,Style.STROKE);
      Polyline polygon=new Polyline(paintStroke);
      polygon.getLatLongs().add(new LatLong(bbox.minLatitude,bbox.minLongitude));
      polygon.getLatLongs().add(new LatLong(bbox.minLatitude,bbox.maxLongitude));
      polygon.getLatLongs().add(new LatLong(bbox.maxLatitude,bbox.maxLongitude));
      polygon.getLatLongs().add(new LatLong(bbox.maxLatitude,bbox.minLongitude));
      polygon.getLatLongs().add(new LatLong(bbox.minLatitude,bbox.minLongitude));
      if (this.lastLine != null) {
        DualOverviewMapViewer.this.mapView2.getLayerManager().getLayers().remove(this.lastLine);
      }
      DualOverviewMapViewer.this.mapView2.getLayerManager().getLayers().add(polygon);
      this.lastLine=polygon;
    }
    @Override protected void setZoom(){
    }
  }
;
}

Fixed version (ground truth):
@Override protected void init(){
  super.init();
  this.mapView2.getModel().mapViewPosition.setZoomLevel((byte)12);
  this.observer=new MapViewPositionObserver(this.mapView.getModel().mapViewPosition,this.mapView2.getModel().mapViewPosition){
    Polyline lastLine;
    @Override protected void setCenter(){
      super.setCenter();
      BoundingBox bbox=MapPositionUtil.getBoundingBox(DualOverviewMapViewer.this.mapView.getModel().mapViewPosition.getMapPosition(),DualOverviewMapViewer.this.mapView.getDimension());
      Paint paintStroke=Utils.createPaint(AndroidGraphicFactory.INSTANCE.createColor(Color.RED),2,Style.STROKE);
      Polyline polygon=new Polyline(paintStroke,AndroidGraphicFactory.INSTANCE);
      polygon.getLatLongs().add(new LatLong(bbox.minLatitude,bbox.minLongitude));
      polygon.getLatLongs().add(new LatLong(bbox.minLatitude,bbox.maxLongitude));
      polygon.getLatLongs().add(new LatLong(bbox.maxLatitude,bbox.maxLongitude));
      polygon.getLatLongs().add(new LatLong(bbox.maxLatitude,bbox.minLongitude));
      polygon.getLatLongs().add(new LatLong(bbox.minLatitude,bbox.minLongitude));
      if (this.lastLine != null) {
        DualOverviewMapViewer.this.mapView2.getLayerManager().getLayers().remove(this.lastLine);
      }
      DualOverviewMapViewer.this.mapView2.getLayerManager().getLayers().add(polygon);
      this.lastLine=polygon;
    }
    @Override protected void setZoom(){
    }
  }
;
}
Program: 93386
Project: 93386
Buggy source:
@Override protected void setCenter(){
  super.setCenter();
  BoundingBox bbox=MapPositionUtil.getBoundingBox(DualOverviewMapViewer.this.mapView.getModel().mapViewPosition.getMapPosition(),DualOverviewMapViewer.this.mapView.getDimension());
  Paint paintStroke=Utils.createPaint(AndroidGraphicFactory.INSTANCE.createColor(Color.RED),2,Style.STROKE);
  Polyline polygon=new Polyline(paintStroke);
  polygon.getLatLongs().add(new LatLong(bbox.minLatitude,bbox.minLongitude));
  polygon.getLatLongs().add(new LatLong(bbox.minLatitude,bbox.maxLongitude));
  polygon.getLatLongs().add(new LatLong(bbox.maxLatitude,bbox.maxLongitude));
  polygon.getLatLongs().add(new LatLong(bbox.maxLatitude,bbox.minLongitude));
  polygon.getLatLongs().add(new LatLong(bbox.minLatitude,bbox.minLongitude));
  if (this.lastLine != null) {
    DualOverviewMapViewer.this.mapView2.getLayerManager().getLayers().remove(this.lastLine);
  }
  DualOverviewMapViewer.this.mapView2.getLayerManager().getLayers().add(polygon);
  this.lastLine=polygon;
}

Fixed version (ground truth):
@Override protected void setCenter(){
  super.setCenter();
  BoundingBox bbox=MapPositionUtil.getBoundingBox(DualOverviewMapViewer.this.mapView.getModel().mapViewPosition.getMapPosition(),DualOverviewMapViewer.this.mapView.getDimension());
  Paint paintStroke=Utils.createPaint(AndroidGraphicFactory.INSTANCE.createColor(Color.RED),2,Style.STROKE);
  Polyline polygon=new Polyline(paintStroke,AndroidGraphicFactory.INSTANCE);
  polygon.getLatLongs().add(new LatLong(bbox.minLatitude,bbox.minLongitude));
  polygon.getLatLongs().add(new LatLong(bbox.minLatitude,bbox.maxLongitude));
  polygon.getLatLongs().add(new LatLong(bbox.maxLatitude,bbox.maxLongitude));
  polygon.getLatLongs().add(new LatLong(bbox.maxLatitude,bbox.minLongitude));
  polygon.getLatLongs().add(new LatLong(bbox.minLatitude,bbox.minLongitude));
  if (this.lastLine != null) {
    DualOverviewMapViewer.this.mapView2.getLayerManager().getLayers().remove(this.lastLine);
  }
  DualOverviewMapViewer.this.mapView2.getLayerManager().getLayers().add(polygon);
  this.lastLine=polygon;
}
Program: 93387
Project: 93387
Buggy source:
protected void addOverlayLayers(List<Layer> layers){
  LatLong latLong1=new LatLong(52.5,13.4);
  LatLong latLong2=new LatLong(52.499,13.402);
  LatLong latLong3=new LatLong(52.503,13.399);
  LatLong latLong4=new LatLong(52.51,13.401);
  LatLong latLong5=new LatLong(52.508,13.408);
  Polyline polyline=new Polyline(Utils.createPaint(AndroidGraphicFactory.INSTANCE.createColor(Color.BLUE),8,Style.STROKE));
  List<LatLong> latLongs=polyline.getLatLongs();
  latLongs.add(latLong1);
  latLongs.add(latLong2);
  latLongs.add(latLong3);
  Paint paintFill=Utils.createPaint(AndroidGraphicFactory.INSTANCE.createColor(Color.GREEN),2,Style.STROKE);
  Paint paintStroke=Utils.createPaint(AndroidGraphicFactory.INSTANCE.createColor(Color.BLACK),2,Style.STROKE);
  Polygon polygon=new Polygon(paintFill,paintStroke,AndroidGraphicFactory.INSTANCE);
  latLongs=polygon.getLatLongs();
  latLongs.add(latLong2);
  latLongs.add(latLong3);
  latLongs.add(latLong4);
  latLongs.add(latLong5);
  Marker marker1=Utils.createMarker(this,R.drawable.marker_red,latLong1);
  Circle circle=new Circle(latLong3,300,Utils.createPaint(AndroidGraphicFactory.INSTANCE.createColor(Color.WHITE),0,Style.FILL),null);
  layers.add(polyline);
  layers.add(polygon);
  layers.add(circle);
  layers.add(marker1);
}

Fixed version (ground truth):
protected void addOverlayLayers(List<Layer> layers){
  LatLong latLong1=new LatLong(52.5,13.4);
  LatLong latLong2=new LatLong(52.499,13.402);
  LatLong latLong3=new LatLong(52.503,13.399);
  LatLong latLong4=new LatLong(52.51,13.401);
  LatLong latLong5=new LatLong(52.508,13.408);
  Polyline polyline=new Polyline(Utils.createPaint(AndroidGraphicFactory.INSTANCE.createColor(Color.BLUE),8,Style.STROKE),AndroidGraphicFactory.INSTANCE);
  List<LatLong> latLongs=polyline.getLatLongs();
  latLongs.add(latLong1);
  latLongs.add(latLong2);
  latLongs.add(latLong3);
  Paint paintFill=Utils.createPaint(AndroidGraphicFactory.INSTANCE.createColor(Color.GREEN),2,Style.STROKE);
  Paint paintStroke=Utils.createPaint(AndroidGraphicFactory.INSTANCE.createColor(Color.BLACK),2,Style.STROKE);
  Polygon polygon=new Polygon(paintFill,paintStroke,AndroidGraphicFactory.INSTANCE);
  latLongs=polygon.getLatLongs();
  latLongs.add(latLong2);
  latLongs.add(latLong3);
  latLongs.add(latLong4);
  latLongs.add(latLong5);
  Marker marker1=Utils.createMarker(this,R.drawable.marker_red,latLong1);
  Circle circle=new Circle(latLong3,300,Utils.createPaint(AndroidGraphicFactory.INSTANCE.createColor(Color.WHITE),0,Style.FILL),null);
  layers.add(polyline);
  layers.add(polygon);
  layers.add(circle);
  layers.add(marker1);
}
Program: 93389
Project: 93389
Buggy source:
private TileCache createTileCache(){
  TileCache firstLevelTileCache=new InMemoryTileCache(32);
  File cacheDirectory=getDir("String_Node_Str",MODE_PRIVATE);
  TileCache secondLevelTileCache=new FileSystemTileCache(1024,cacheDirectory,AndroidGraphics.INSTANCE);
  return new TwoLevelTileCache(firstLevelTileCache,secondLevelTileCache);
}

Fixed version (ground truth):
private TileCache createTileCache(){
  TileCache firstLevelTileCache=new InMemoryTileCache(64);
  File cacheDirectory=getDir("String_Node_Str",MODE_PRIVATE);
  TileCache secondLevelTileCache=new FileSystemTileCache(1024,cacheDirectory,AndroidGraphics.INSTANCE);
  return new TwoLevelTileCache(firstLevelTileCache,secondLevelTileCache);
}
Program: 93390
Project: 93390
Buggy source:
private static Layer createTileDownloadLayer(TileCache tileCache,MapViewPosition mapViewPosition,LayerManager layerManager){
  TileSource tileSource=OpenStreetMapMapnik.INSTANCE;
  return new TileDownloadLayer(tileCache,mapViewPosition,tileSource,layerManager,GRAPHIC_FACTORY);
}

Fixed version (ground truth):
private static Layer createTileDownloadLayer(TileCache tileCache,MapViewPosition mapViewPosition,LayerManager layerManager){
  TileSource tileSource=OpenStreetMapMapnik.INSTANCE;
  TileDownloadLayer tileDownloadLayer=new TileDownloadLayer(tileCache,mapViewPosition,tileSource,layerManager,GRAPHIC_FACTORY);
  tileDownloadLayer.start();
  return tileDownloadLayer;
}
Program: 93391
Project: 93391
Buggy source:
@Override public void drawCircle(int x,int y,int radius,Paint paint){
  AwtPaint awtPaint=AwtGraphicFactory.getAwtPaint(paint);
  setColorAndStroke(awtPaint);
  int doubleRadius=radius * 2;
  Style style=awtPaint.style;
switch (style) {
case FILL:
    this.graphics2D.fillOval(x - radius,y - radius,doubleRadius,doubleRadius);
  return;
case STROKE:
this.graphics2D.drawOval(x - radius,y - radius,doubleRadius,doubleRadius);
return;
}
throw new IllegalArgumentException("String_Node_Str" + style);
}

Fixed version (ground truth):
@Override public void drawCircle(int x,int y,int radius,Paint paint){
  AwtPaint awtPaint=AwtGraphicFactory.getAwtPaint(paint);
  setColorAndStroke(awtPaint);
  int doubleRadius=radius * 2;
  Style style=awtPaint.style;
switch (style) {
case FILL:
    this.graphics2D.fillOval(x - radius,y - radius,doubleRadius,doubleRadius);
  return;
case STROKE:
this.graphics2D.drawOval(x - radius,y - radius,doubleRadius,doubleRadius);
return;
}
throw new IllegalArgumentException(UNKNOWN_STYLE + style);
}
Program: 93392
Project: 93392
Buggy source:
@Override public void drawPath(Path path,Paint paint){
  AwtPaint awtPaint=AwtGraphicFactory.getAwtPaint(paint);
  AwtPath awtPath=AwtGraphicFactory.getAwtPath(path);
  setColorAndStroke(awtPaint);
  this.graphics2D.setPaint(awtPaint.texturePaint);
  Style style=awtPaint.style;
switch (style) {
case FILL:
    this.graphics2D.fill(awtPath.path2D);
  return;
case STROKE:
this.graphics2D.draw(awtPath.path2D);
return;
}
throw new IllegalArgumentException("String_Node_Str" + style);
}

Fixed version (ground truth):
@Override public void drawPath(Path path,Paint paint){
  AwtPaint awtPaint=AwtGraphicFactory.getAwtPaint(paint);
  AwtPath awtPath=AwtGraphicFactory.getAwtPath(path);
  setColorAndStroke(awtPaint);
  this.graphics2D.setPaint(awtPaint.texturePaint);
  Style style=awtPaint.style;
switch (style) {
case FILL:
    this.graphics2D.fill(awtPath.path2D);
  return;
case STROKE:
this.graphics2D.draw(awtPath.path2D);
return;
}
throw new IllegalArgumentException(UNKNOWN_STYLE + style);
}
Program: 93393
Project: 93393
Buggy source:
static AwtPaint getAwtPaint(Paint paint){
  return ((AwtPaint)paint);
}

Fixed version (ground truth):
static AwtPaint getAwtPaint(Paint paint){
  return (AwtPaint)paint;
}
Program: 93394
Project: 93394
Buggy source:
static AwtPath getAwtPath(Path path){
  return ((AwtPath)path);
}

Fixed version (ground truth):
static AwtPath getAwtPath(Path path){
  return (AwtPath)path;
}
Program: 93395
Project: 93395
Buggy source:
public TileDownloadLayer(TileCache tileCache,MapViewPosition mapViewPosition,TileSource tileSource,LayerManager layerManager,GraphicFactory graphicFactory){
  super(tileCache,mapViewPosition,graphicFactory);
  if (tileSource == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
 else   if (layerManager == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.tileSource=tileSource;
  int numberOfDownloadThreads=Math.min(tileSource.getParallelRequestsLimit(),DOWNLOAD_THREADS_MAX);
  this.tileDownloadThreads=new TileDownloadThread[numberOfDownloadThreads];
  for (int i=0; i < numberOfDownloadThreads; ++i) {
    TileDownloadThread tileDownloadThread=new TileDownloadThread(tileCache,this.jobQueue,layerManager,graphicFactory);
    tileDownloadThread.start();
    this.tileDownloadThreads[i]=tileDownloadThread;
  }
}

Fixed version (ground truth):
public TileDownloadLayer(TileCache tileCache,MapViewPosition mapViewPosition,TileSource tileSource,LayerManager layerManager,GraphicFactory graphicFactory){
  super(tileCache,mapViewPosition,graphicFactory);
  if (tileSource == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
 else   if (layerManager == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.tileSource=tileSource;
  int numberOfDownloadThreads=Math.min(tileSource.getParallelRequestsLimit(),DOWNLOAD_THREADS_MAX);
  this.tileDownloadThreads=new TileDownloadThread[numberOfDownloadThreads];
  for (int i=0; i < numberOfDownloadThreads; ++i) {
    this.tileDownloadThreads[i]=new TileDownloadThread(tileCache,this.jobQueue,layerManager,graphicFactory);
  }
}
Program: 93396
Project: 93396
Buggy source:
@Override public synchronized void draw(BoundingBox boundingBox,byte zoomLevel,Canvas canvas,Point canvasPosition){
  if (this.latLong == null || this.bitmap == null) {
    return;
  }
  double pixelX=MercatorProjection.longitudeToPixelX(this.latLong.longitude,zoomLevel);
  double pixelY=MercatorProjection.latitudeToPixelY(this.latLong.latitude,zoomLevel);
  int left=(int)(pixelX - canvasPosition.x + this.dx - (this.bitmap.getWidth() / 2));
  int top=(int)(pixelY - canvasPosition.y + this.dy - (this.bitmap.getHeight() / 2));
  int right=left + this.bitmap.getWidth();
  int bottom=top + this.bitmap.getHeight();
  Rectangle bitmapRectangle=new Rectangle(left,top,right,bottom);
  Rectangle canvasRectangle=new Rectangle(0,0,canvas.getWidth(),canvas.getHeight());
  if (!canvasRectangle.intersects(bitmapRectangle)) {
    return;
  }
  canvas.drawBitmap(this.bitmap,left,top);
}

Fixed version (ground truth):
@Override public synchronized void draw(BoundingBox boundingBox,byte zoomLevel,Canvas canvas,Point canvasPosition){
  if (this.latLong == null || this.bitmap == null) {
    return;
  }
  double pixelX=MercatorProjection.longitudeToPixelX(this.latLong.longitude,zoomLevel);
  double pixelY=MercatorProjection.latitudeToPixelY(this.latLong.latitude,zoomLevel);
  int halfBitmapWidth=this.bitmap.getWidth() / 2;
  int halfBitmapHeight=this.bitmap.getHeight() / 2;
  int left=(int)(pixelX - canvasPosition.x - halfBitmapWidth + this.dx);
  int top=(int)(pixelY - canvasPosition.y - halfBitmapHeight + this.dy);
  int right=left + this.bitmap.getWidth();
  int bottom=top + this.bitmap.getHeight();
  Rectangle bitmapRectangle=new Rectangle(left,top,right,bottom);
  Rectangle canvasRectangle=new Rectangle(0,0,canvas.getWidth(),canvas.getHeight());
  if (!canvasRectangle.intersects(bitmapRectangle)) {
    return;
  }
  canvas.drawBitmap(this.bitmap,left,top);
}
Program: 93397
Project: 93397
Buggy source:
@Override public void destroy(){
  this.mapWorker.interrupt();
  this.mapDatabase.closeFile();
  super.destroy();
}

Fixed version (ground truth):
@Override public void destroy(){
  new DestroyThread(this.mapWorker,this.mapDatabase).start();
  super.destroy();
}
Program: 93398
Project: 93398
Buggy source:
private void restoreMapView(MapView mapView){
  SharedPreferences sharedPreferences=getSharedPreferences(PREFERENCES_FILE,MODE_PRIVATE);
  if (containsMapViewPosition(sharedPreferences)) {
    if (sharedPreferences.contains(KEY_MAP_FILE)) {
      mapView.setMapFile(new File(sharedPreferences.getString(KEY_MAP_FILE,null)));
    }
    float latitude=sharedPreferences.getFloat(KEY_LATITUDE,0);
    float longitude=sharedPreferences.getFloat(KEY_LONGITUDE,0);
    int zoomLevel=sharedPreferences.getInt(KEY_ZOOM_LEVEL,-1);
    GeoPoint geoPoint=new GeoPoint(latitude,longitude);
    MapPosition mapPosition=new MapPosition(geoPoint,(byte)zoomLevel);
    mapView.getMapViewPosition().setMapPosition(mapPosition);
  }
}

Fixed version (ground truth):
private void restoreMapView(MapView mapView){
  SharedPreferences sharedPreferences=getSharedPreferences(PREFERENCES_FILE,MODE_PRIVATE);
  if (isCompatible(sharedPreferences) && containsMapViewPosition(sharedPreferences)) {
    if (sharedPreferences.contains(KEY_MAP_FILE)) {
      mapView.setMapFile(new File(sharedPreferences.getString(KEY_MAP_FILE,null)));
    }
    float latitude=sharedPreferences.getFloat(KEY_LATITUDE,0);
    float longitude=sharedPreferences.getFloat(KEY_LONGITUDE,0);
    int zoomLevel=sharedPreferences.getInt(KEY_ZOOM_LEVEL,-1);
    GeoPoint geoPoint=new GeoPoint(latitude,longitude);
    MapPosition mapPosition=new MapPosition(geoPoint,(byte)zoomLevel);
    mapView.getMapViewPosition().setMapPosition(mapPosition);
  }
}
Program: 93399
Project: 93399
Buggy source:
@Override protected void onPause(){
  super.onPause();
  if (this.mapViews.isEmpty()) {
    return;
  }
  for (int i=0, n=this.mapViews.size(); i < n; ++i) {
    this.mapViews.get(i).onPause();
  }
  Editor editor=getSharedPreferences(PREFERENCES_FILE,MODE_PRIVATE).edit();
  editor.clear();
  MapView mapView=this.mapViews.get(0);
  MapPosition mapPosition=mapView.getMapViewPosition().getMapPosition();
  GeoPoint geoPoint=mapPosition.geoPoint;
  editor.putFloat(KEY_LATITUDE,(float)geoPoint.latitude);
  editor.putFloat(KEY_LONGITUDE,(float)geoPoint.longitude);
  editor.putInt(KEY_ZOOM_LEVEL,mapPosition.zoomLevel);
  if (mapView.getMapFile() != null) {
    editor.putString(KEY_MAP_FILE,mapView.getMapFile().getAbsolutePath());
  }
  editor.commit();
}

Fixed version (ground truth):
@Override protected void onPause(){
  super.onPause();
  if (this.mapViews.isEmpty()) {
    return;
  }
  for (int i=0, n=this.mapViews.size(); i < n; ++i) {
    this.mapViews.get(i).onPause();
  }
  Editor editor=getSharedPreferences(PREFERENCES_FILE,MODE_PRIVATE).edit();
  editor.clear();
  editor.putInt(PREFERENCES_VERSION_KEY,PREFERENCES_VERSION_NUMBER);
  MapView mapView=this.mapViews.get(0);
  MapPosition mapPosition=mapView.getMapViewPosition().getMapPosition();
  GeoPoint geoPoint=mapPosition.geoPoint;
  editor.putFloat(KEY_LATITUDE,(float)geoPoint.latitude);
  editor.putFloat(KEY_LONGITUDE,(float)geoPoint.longitude);
  editor.putInt(KEY_ZOOM_LEVEL,mapPosition.zoomLevel);
  if (mapView.getMapFile() != null) {
    editor.putString(KEY_MAP_FILE,mapView.getMapFile().getAbsolutePath());
  }
  editor.commit();
}
Program: 93400
Project: 93400
Buggy source:
synchronized void onSizeChanged(){
  this.width=this.mapView.getWidth();
  this.height=this.mapView.getHeight();
  this.mapViewBitmap1=Bitmap.createBitmap(this.width,this.height,Bitmap.Config.RGB_565);
  this.mapViewBitmap2=Bitmap.createBitmap(this.width,this.height,Bitmap.Config.RGB_565);
  clear();
  this.mapViewCanvas.setBitmap(this.mapViewBitmap1);
}

Fixed version (ground truth):
synchronized void onSizeChanged(){
  this.destroy();
  this.mapViewCanvas=new Canvas();
  this.width=this.mapView.getWidth();
  this.height=this.mapView.getHeight();
  this.mapViewBitmap1=Bitmap.createBitmap(this.width,this.height,Bitmap.Config.RGB_565);
  this.mapViewBitmap2=Bitmap.createBitmap(this.width,this.height,Bitmap.Config.RGB_565);
  clear();
  this.mapViewCanvas.setBitmap(this.mapViewBitmap1);
}
Program: 93401
Project: 93401
Buggy source:
synchronized void destroy(){
  if (this.mapViewBitmap1 != null) {
    this.mapViewBitmap1.recycle();
  }
  if (this.mapViewBitmap2 != null) {
    this.mapViewBitmap2.recycle();
  }
}

Fixed version (ground truth):
synchronized void destroy(){
  if (this.mapViewBitmap1 != null) {
    this.mapViewBitmap1.recycle();
  }
  if (this.mapViewBitmap2 != null) {
    this.mapViewBitmap2.recycle();
  }
  this.mapViewCanvas=null;
}
Program: 93402
Project: 93402
Buggy source:
void destroy(){
  this.overlayController.interrupt();
  this.mapMover.interrupt();
  this.mapWorker.interrupt();
  this.zoomAnimator.interrupt();
  try {
    this.mapWorker.join();
  }
 catch (  InterruptedException e) {
    Thread.currentThread().interrupt();
  }
  this.frameBuffer.destroy();
  this.mapScaleBar.destroy();
  this.inMemoryTileCache.destroy();
  this.fileSystemTileCache.destroy();
  this.mapDatabase.closeFile();
}

Fixed version (ground truth):
void destroy(){
  this.overlayController.interrupt();
  this.mapMover.interrupt();
  this.mapWorker.interrupt();
  this.zoomAnimator.interrupt();
  try {
    this.mapWorker.join();
  }
 catch (  InterruptedException e) {
    Thread.currentThread().interrupt();
  }
  this.frameBuffer.destroy();
  this.mapScaleBar.destroy();
  this.inMemoryTileCache.destroy();
  this.fileSystemTileCache.destroy();
  this.databaseRenderer.destroy();
  this.mapDatabase.closeFile();
}
Program: 93404
Project: 93404
Buggy source:
private boolean checkSize(){
  if (this.changeSizeNeeded) {
    return changeSize();
  }
  return true;
}

Fixed version (ground truth):
private boolean checkSize(){
  this.sizeChange.writeLock().lock();
  try {
    if (this.changeSizeNeeded) {
      return changeSize();
    }
    return true;
  }
  finally {
    this.sizeChange.writeLock().unlock();
  }
}
Program: 93405
Project: 93405
Buggy source:
private void recycleBitmaps(){
  recycleBitmap(this.bitmap1);
  recycleBitmap(this.bitmap2);
}

Fixed version (ground truth):
private void recycleBitmaps(){
  if (this.bitmap1 != null) {
    this.bitmap1.recycle();
    this.bitmap1=null;
  }
  if (this.bitmap2 != null) {
    this.bitmap2.recycle();
    this.bitmap2=null;
  }
  this.overlayCanvas=null;
}
Program: 93406
Project: 93406
Buggy source:
@Override protected void afterRun(){
  recycleBitmaps();
}

Fixed version (ground truth):
@Override protected void afterRun(){
  this.recycleBitmaps();
}
Program: 93407
Project: 93407
Buggy source:
private void redraw(){
  this.bitmap2.eraseColor(Color.TRANSPARENT);
  this.overlayCanvas.setBitmap(this.bitmap2);
  MapPosition mapPositionBefore=this.mapView.getMapViewPosition().getMapPosition();
  BoundingBox boundingBox=this.mapView.getMapViewPosition().getBoundingBox();
  List<Overlay> overlays=this.mapView.getOverlays();
synchronized (overlays) {
    for (    Overlay overlay : overlays) {
      overlay.draw(boundingBox,mapPositionBefore.zoomLevel,this.overlayCanvas);
    }
  }
  MapPosition mapPositionAfter=this.mapView.getMapViewPosition().getMapPosition();
synchronized (this.matrix) {
    adjustMatrix(mapPositionBefore,mapPositionAfter);
    swapBitmaps();
  }
  this.mapView.postInvalidate();
}

Fixed version (ground truth):
private void redraw(){
  if (this.overlayCanvas == null) {
    this.overlayCanvas=new Canvas();
  }
  this.bitmap2.eraseColor(Color.TRANSPARENT);
  this.overlayCanvas.setBitmap(this.bitmap2);
  MapPosition mapPositionBefore=this.mapView.getMapViewPosition().getMapPosition();
  BoundingBox boundingBox=this.mapView.getMapViewPosition().getBoundingBox();
  List<Overlay> overlays=this.mapView.getOverlays();
synchronized (overlays) {
    for (    Overlay overlay : overlays) {
      overlay.draw(boundingBox,mapPositionBefore.zoomLevel,this.overlayCanvas);
    }
  }
  MapPosition mapPositionAfter=this.mapView.getMapViewPosition().getMapPosition();
synchronized (this.matrix) {
    adjustMatrix(mapPositionBefore,mapPositionAfter);
    swapBitmaps();
  }
  this.mapView.postInvalidate();
}
Program: 93408
Project: 93408
Buggy source:
public OverlayController(MapView mapView){
  super();
  this.mapView=mapView;
  this.matrix=new Matrix();
  this.overlayCanvas=new Canvas();
  this.changeSizeNeeded=true;
}

Fixed version (ground truth):
public OverlayController(MapView mapView){
  super();
  this.mapView=mapView;
  this.matrix=new Matrix();
  this.changeSizeNeeded=true;
}
Program: 93409
Project: 93409
Buggy source:
private boolean changeSize(){
  recycleBitmaps();
  int width=this.mapView.getWidth();
  int height=this.mapView.getHeight();
  if (width > 0 && height > 0) {
    this.bitmap1=Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
    this.bitmap2=Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
    this.changeSizeNeeded=false;
    this.redrawNeeded=true;
    return true;
  }
  return false;
}

Fixed version (ground truth):
private boolean changeSize(){
  int newWidth=this.mapView.getWidth();
  int newHeight=this.mapView.getHeight();
  if (newWidth > 0 && newHeight > 0) {
    if (this.width == newWidth && this.height == newHeight) {
      this.changeSizeNeeded=false;
      this.redrawNeeded=false;
      return false;
    }
    recycleBitmaps();
    this.width=newWidth;
    this.height=newHeight;
    this.bitmap1=Bitmap.createBitmap(newWidth,newHeight,Bitmap.Config.ARGB_8888);
    this.bitmap2=Bitmap.createBitmap(newWidth,newHeight,Bitmap.Config.ARGB_8888);
    this.changeSizeNeeded=false;
    this.redrawNeeded=true;
    return true;
  }
  return false;
}
Program: 93410
Project: 93410
Buggy source:
private void checkRedraw(){
  if (this.redrawNeeded) {
    this.redrawNeeded=false;
    redraw();
  }
}

Fixed version (ground truth):
private void checkRedraw(){
  this.sizeChange.readLock().lock();
  try {
    if (this.redrawNeeded) {
      this.redrawNeeded=false;
      redraw();
    }
  }
  finally {
    this.sizeChange.readLock().unlock();
  }
}
Program: 93411
Project: 93411
Buggy source:
@Override public void setBitmapShader(org.mapsforge.map.graphics.Bitmap bitmap){
  if (bitmap == null) {
    return;
  }
  android.graphics.Bitmap androidBitmap=android.graphics.Bitmap.createBitmap(bitmap.getPixels(),bitmap.getWidth(),bitmap.getHeight(),Config.ARGB_8888);
  Shader shader=new BitmapShader(androidBitmap,TileMode.REPEAT,TileMode.REPEAT);
  this.paint.setShader(shader);
}

Fixed version (ground truth):
@Override public void setBitmapShader(org.mapsforge.map.graphics.Bitmap bitmap){
  if (bitmap == null) {
    return;
  }
  this.bitmap=bitmap;
  android.graphics.Bitmap androidBitmap=android.graphics.Bitmap.createBitmap(bitmap.getPixels(),bitmap.getWidth(),bitmap.getHeight(),Config.ARGB_8888);
  Shader shader=new BitmapShader(androidBitmap,TileMode.REPEAT,TileMode.REPEAT);
  this.paint.setShader(shader);
}
Program: 93412
Project: 93412
Buggy source:
@Override public void destroy(){
}

Fixed version (ground truth):
@Override public void destroy(){
  this.fill.destroy();
  this.stroke.destroy();
}
Program: 93413
Project: 93413
Buggy source:
@Override public void destroy(){
}

Fixed version (ground truth):
@Override public void destroy(){
  this.stroke.destroy();
}
Program: 93414
Project: 93414
Buggy source:
void scale(float scaleX,float scaleY,float pivotX,float pivotY);

Fixed version (ground truth):
void scale(float scaleX,float scaleY);
Program: 93415
Project: 93415
Buggy source:
@Override public void scale(float scaleX,float scaleY,float pivotX,float pivotY){
  this.matrix.preScale(scaleX,scaleY,pivotX,pivotY);
}

Fixed version (ground truth):
@Override public void scale(float scaleX,float scaleY){
  this.matrix.preScale(scaleX,scaleY);
}
Program: 93416
Project: 93416
Buggy source:
@Override public void scale(float scaleX,float scaleY,float pivotX,float pivotY){
  this.affineTransform.scale(scaleX,scaleY);
}

Fixed version (ground truth):
@Override public void scale(float scaleX,float scaleY){
  this.affineTransform.scale(scaleX,scaleY);
}
Program: 93417
Project: 93417
Buggy source:
private void drawParentTileBitmap(Canvas canvas,Point point,Tile tile){
  Tile cachedParentTile=getCachedParentTile(tile,4);
  if (cachedParentTile != null) {
    Bitmap bitmap=this.tileCache.get(createJob(cachedParentTile));
    if (bitmap != null) {
      long translateX=tile.getShiftX(cachedParentTile) * Tile.TILE_SIZE;
      long translateY=tile.getShiftY(cachedParentTile) * Tile.TILE_SIZE;
      byte zoomLevelDiff=(byte)(tile.zoomLevel - cachedParentTile.zoomLevel);
      float scaleFactor=(float)Math.pow(2,zoomLevelDiff);
      this.matrix.reset();
      this.matrix.scale(scaleFactor,scaleFactor);
      this.matrix.translate((float)(point.x - translateX),(float)(point.y - translateY));
      canvas.drawBitmap(bitmap,this.matrix);
    }
  }
}

Fixed version (ground truth):
private void drawParentTileBitmap(Canvas canvas,Point point,Tile tile){
  Tile cachedParentTile=getCachedParentTile(tile,4);
  if (cachedParentTile != null) {
    Bitmap bitmap=this.tileCache.get(createJob(cachedParentTile));
    if (bitmap != null) {
      long translateX=tile.getShiftX(cachedParentTile) * Tile.TILE_SIZE;
      long translateY=tile.getShiftY(cachedParentTile) * Tile.TILE_SIZE;
      byte zoomLevelDiff=(byte)(tile.zoomLevel - cachedParentTile.zoomLevel);
      float scaleFactor=(float)Math.pow(2,zoomLevelDiff);
      this.matrix.reset();
      this.matrix.translate((float)(point.x - translateX),(float)(point.y - translateY));
      this.matrix.scale(scaleFactor,scaleFactor);
      canvas.drawBitmap(bitmap,this.matrix);
    }
  }
}
Program: 93418
Project: 93418
Buggy source:
public void setOverdrawFactor(double overdrawFactor){
  if (overdrawFactor <= 0) {
    throw new IllegalArgumentException("String_Node_Str" + overdrawFactor);
  }
synchronized (this) {
    this.overdrawFactor=overdrawFactor;
  }
  notifyObservers();
}

Fixed version (ground truth):
/** 
 * @throws IllegalArgumentException if the  {@code overdrawFactor} is less or equal zero.
 */
public void setOverdrawFactor(double overdrawFactor){
  if (overdrawFactor <= 0) {
    throw new IllegalArgumentException("String_Node_Str" + overdrawFactor);
  }
synchronized (this) {
    this.overdrawFactor=overdrawFactor;
  }
  notifyObservers();
}
Program: 93419
Project: 93419
Buggy source:
public synchronized void adjustMatrix(float diffX,float diffY,float scaleFactor,Dimension mapViewDimension){
  if (this.dimension == null) {
    return;
  }
  int pivotX=this.dimension.width / 2;
  int pivotY=this.dimension.height / 2;
  this.matrix.reset();
  this.matrix.scale(scaleFactor,scaleFactor,pivotX,pivotY);
  this.matrix.translate(diffX,diffY);
  float dx=(this.dimension.width - mapViewDimension.width) / -2f;
  float dy=(this.dimension.height - mapViewDimension.height) / -2f;
  this.matrix.translate(dx,dy);
}

Fixed version (ground truth):
public synchronized void adjustMatrix(float diffX,float diffY,float scaleFactor,Dimension mapViewDimension){
  if (this.dimension == null) {
    return;
  }
  this.matrix.reset();
  centerFrameBufferToMapView(mapViewDimension);
  scale(scaleFactor);
  this.matrix.translate(diffX,diffY);
}
Program: 93420
Project: 93420
Buggy source:
@Override public synchronized void destroy(){
  if (!this.persistent || !serializeMap(this.cacheDirectory,this.map)) {
    for (    File file : this.map.values()) {
      if (!file.delete()) {
        file.deleteOnExit();
      }
    }
    this.map.clear();
    File[] filesToDelete=this.cacheDirectory.listFiles(ImageFileNameFilter.INSTANCE);
    if (filesToDelete != null) {
      for (      File file : filesToDelete) {
        if (!file.delete()) {
          file.deleteOnExit();
        }
      }
    }
    if (!this.cacheDirectory.delete()) {
      this.cacheDirectory.deleteOnExit();
    }
  }
}

Fixed version (ground truth):
@Override public synchronized void destroy(){
  if (this.bitmapGet != null) {
    this.bitmapGet.recycle();
  }
  if (this.capacity == 0) {
    return;
  }
  if (!this.persistent || !serializeMap(this.cacheDirectory,this.map)) {
    for (    File file : this.map.values()) {
      if (!file.delete()) {
        file.deleteOnExit();
      }
    }
    this.map.clear();
    if (this.cacheDirectory != null) {
      File[] filesToDelete=this.cacheDirectory.listFiles(ImageFileNameFilter.INSTANCE);
      if (filesToDelete != null) {
        for (        File file : filesToDelete) {
          if (!file.delete()) {
            file.deleteOnExit();
          }
        }
      }
      if (!this.cacheDirectory.delete()) {
        this.cacheDirectory.deleteOnExit();
      }
    }
  }
}
Program: 93421
Project: 93421
Buggy source:
@Override public synchronized void put(MapGeneratorJob mapGeneratorJob,Bitmap bitmap){
  if (this.capacity == 0) {
    return;
  }
  FileOutputStream fileOutputStream=null;
  try {
    File outputFile;
    do {
      ++this.cacheId;
      outputFile=new File(this.cacheDirectory,this.cacheId + IMAGE_FILE_NAME_EXTENSION);
    }
 while (outputFile.exists());
    this.byteBuffer.rewind();
    bitmap.copyPixelsToBuffer(this.byteBuffer);
    byte[] array=this.byteBuffer.array();
    fileOutputStream=new FileOutputStream(outputFile);
    fileOutputStream.write(array,0,array.length);
    this.map.put(mapGeneratorJob,outputFile);
  }
 catch (  IOException e) {
    LOGGER.log(Level.SEVERE,null,e);
  }
 finally {
    try {
      if (fileOutputStream != null) {
        fileOutputStream.close();
      }
    }
 catch (    IOException e) {
      LOGGER.log(Level.SEVERE,null,e);
    }
  }
}

Fixed version (ground truth):
@Override public synchronized void put(MapGeneratorJob mapGeneratorJob,Bitmap bitmap){
  if (this.capacity == 0) {
    return;
  }
  FileOutputStream fileOutputStream=null;
  try {
    File outputFile;
    do {
      ++this.cacheId;
      outputFile=new File(this.cacheDirectory,this.cacheId + IMAGE_FILE_NAME_EXTENSION);
    }
 while (outputFile.exists());
    this.byteBuffer.rewind();
    bitmap.copyPixelsToBuffer(this.byteBuffer);
    byte[] array=this.byteBuffer.array();
    fileOutputStream=new FileOutputStream(outputFile);
    fileOutputStream.write(array,0,array.length);
    this.map.put(mapGeneratorJob,outputFile);
  }
 catch (  IOException e) {
    LOGGER.log(Level.SEVERE,"String_Node_Str",e);
    this.capacity=0;
  }
 finally {
    try {
      if (fileOutputStream != null) {
        fileOutputStream.close();
      }
    }
 catch (    IOException e) {
      LOGGER.log(Level.SEVERE,null,e);
    }
  }
}
Program: 93422
Project: 93422
Buggy source:
/** 
 * @param capacity the maximum number of entries in this cache.
 * @param mapViewId the ID of the MapView to separate caches for different MapViews.
 * @throws IllegalArgumentException if the capacity is negative.
 */
public FileSystemTileCache(int capacity,int mapViewId){
  this.capacity=getCapacity(capacity);
  String externalStorageDirectory=Environment.getExternalStorageDirectory().getAbsolutePath();
  String cacheDirectoryPath=externalStorageDirectory + CACHE_DIRECTORY + mapViewId;
  this.cacheDirectory=createDirectory(cacheDirectoryPath);
  Map<MapGeneratorJob,File> deserializedMap=deserializeMap(this.cacheDirectory);
  if (deserializedMap == null) {
    this.map=createMap(this.capacity);
  }
 else {
    this.map=deserializedMap;
  }
  this.byteBuffer=ByteBuffer.allocate(TILE_SIZE_IN_BYTES);
  this.bitmapGet=Bitmap.createBitmap(Tile.TILE_SIZE,Tile.TILE_SIZE,Config.RGB_565);
}

Fixed version (ground truth):
/** 
 * @param capacity the maximum number of entries in this cache.
 * @param mapViewId the ID of the MapView to separate caches for different MapViews.
 * @throws IllegalArgumentException if the capacity is negative.
 */
public FileSystemTileCache(int capacity,int mapViewId){
  this.mapViewId=mapViewId;
  this.capacity=checkCapacity(capacity);
  if (this.capacity > 0 && this.cacheDirectory != null) {
    Map<MapGeneratorJob,File> deserializedMap=deserializeMap(this.cacheDirectory);
    if (deserializedMap == null) {
      this.map=createMap(this.capacity);
    }
 else {
      this.map=deserializedMap;
    }
    this.byteBuffer=ByteBuffer.allocate(TILE_SIZE_IN_BYTES);
    this.bitmapGet=Bitmap.createBitmap(Tile.TILE_SIZE,Tile.TILE_SIZE,Config.RGB_565);
  }
 else {
    this.byteBuffer=null;
    this.bitmapGet=null;
    this.map=createMap(0);
  }
}
Program: 93423
Project: 93423
Buggy source:
@Override public synchronized void setCapacity(int capacity){
  if (this.capacity == capacity) {
    return;
  }
  this.capacity=getCapacity(capacity);
  Map<MapGeneratorJob,File> newMap=createMap(this.capacity);
  newMap.putAll(this.map);
  this.map=newMap;
}

Fixed version (ground truth):
@Override public synchronized void setCapacity(int capacity){
  if (this.capacity == capacity) {
    return;
  }
  this.capacity=checkCapacity(capacity);
  if (this.capacity != 0) {
    Map<MapGeneratorJob,File> newMap=createMap(this.capacity);
    if (this.map != null) {
      newMap.putAll(this.map);
    }
    this.map=newMap;
  }
}
Program: 93425
Project: 93425
Buggy source:
private void parseAttributes(AttributeSet attrs){
  TypedArray a=getContext().obtainStyledAttributes(attrs,R.styleable.CropImageView);
  final int crop=a.getInt(R.styleable.CropImageView_crop,CropType.NONE.getCrop());
  if (crop >= 0) {
    setScaleType(ScaleType.MATRIX);
    this.cropType=CropType.get(crop);
  }
  a.recycle();
}

Fixed version (ground truth):
private void parseAttributes(AttributeSet attrs){
  final TypedArray a=getContext().obtainStyledAttributes(attrs,R.styleable.CropImageView);
  final int crop=a.getInt(R.styleable.CropImageView_crop,CropType.NONE.getCrop());
  if (crop >= 0) {
    setScaleType(ScaleType.MATRIX);
    this.cropType=CropType.get(crop);
  }
  a.recycle();
}
Program: 93426
Project: 93426
Buggy source:
@Override protected boolean setFrame(int l,int t,int r,int b){
  final boolean changed=super.setFrame(l,t,r,b);
  if (!isInEditMode()) {
    this.computeImageMatrix();
  }
  return changed;
}

Fixed version (ground truth):
@Override protected boolean setFrame(int l,int t,int r,int b){
  final boolean changed=super.setFrame(l,t,r,b);
  final Drawable drawable=getDrawable();
  if (!isInEditMode() && drawable != null) {
    this.computeImageMatrix(drawable);
  }
  return changed;
}
Program: 93427
Project: 93427
Buggy source:
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public CropImageView(Context context,AttributeSet attrs,int defStyleAttr,int defStyleRes){
  super(context,attrs,defStyleAttr,defStyleRes);
  this.parseAttributes(attrs);
}

Fixed version (ground truth):
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public CropImageView(Context context,AttributeSet attrs,int defStyleAttr,int defStyleRes){
  super(context,attrs,defStyleAttr,defStyleRes);
  parseAttributes(attrs);
}
Program: 93428
Project: 93428
Buggy source:
private void computeImageMatrix(){
  final int viewWidth=getWidth() - getPaddingLeft() - getPaddingRight();
  final int viewHeight=getHeight() - getPaddingTop() - getPaddingBottom();
  if (cropType != CropType.NONE && viewHeight > 0 && viewWidth > 0) {
    final Matrix matrix=getImageMatrix();
    int drawableWidth=getDrawable().getIntrinsicWidth();
    int drawableHeight=getDrawable().getIntrinsicHeight();
    final float scaleY=(float)viewHeight / (float)drawableHeight;
    final float scaleX=(float)viewWidth / (float)drawableWidth;
    final float scale=scaleX > scaleY ? scaleX : scaleY;
    matrix.setScale(scale,scale);
    final boolean verticalImageMode=scaleX > scaleY;
    final float postDrawableWidth=drawableWidth * scale;
    final float xTranslation=getXTranslation(cropType,viewWidth,postDrawableWidth,verticalImageMode);
    final float postDrawabeHeigth=drawableHeight * scale;
    final float yTranslation=getYTranslation(cropType,viewHeight,postDrawabeHeigth,verticalImageMode);
    matrix.postTranslate(xTranslation,yTranslation);
    setImageMatrix(matrix);
  }
}

Fixed version (ground truth):
private void computeImageMatrix(Drawable drawable){
  final int viewWidth=getWidth() - getPaddingLeft() - getPaddingRight();
  final int viewHeight=getHeight() - getPaddingTop() - getPaddingBottom();
  if (cropType != CropType.NONE && viewHeight > 0 && viewWidth > 0) {
    final Matrix matrix=getImageMatrix();
    int drawableWidth=drawable.getIntrinsicWidth();
    int drawableHeight=drawable.getIntrinsicHeight();
    final float scaleY=(float)viewHeight / (float)drawableHeight;
    final float scaleX=(float)viewWidth / (float)drawableWidth;
    final float scale=scaleX > scaleY ? scaleX : scaleY;
    matrix.setScale(scale,scale);
    final boolean verticalImageMode=scaleX > scaleY;
    final float postDrawableWidth=drawableWidth * scale;
    final float xTranslation=getXTranslation(cropType,viewWidth,postDrawableWidth,verticalImageMode);
    final float postDrawabeHeigth=drawableHeight * scale;
    final float yTranslation=getYTranslation(cropType,viewHeight,postDrawabeHeigth,verticalImageMode);
    matrix.postTranslate(xTranslation,yTranslation);
    setImageMatrix(matrix);
  }
}
Program: 93429
Project: 93429
Buggy source:
private float getYTranslation(CropType cropType,float scale,int viewHeight,int drawableHeight,boolean verticalImageMode){
  if (verticalImageMode) {
switch (cropType) {
case CENTER_BOTTOM:
case LEFT_BOTTOM:
case RIGHT_BOTTOM:
      return viewHeight - (scale * drawableHeight);
case LEFT_CENTER:
case RIGHT_CENTER:
    return (float)(((float)viewHeight / 2.0) - ((float)drawableHeight / 2.0));
}
}
return 0;
}

Fixed version (ground truth):
private float getYTranslation(CropType cropType,int viewHeight,float postDrawabeHeigth,boolean verticalImageMode){
  if (verticalImageMode) {
switch (cropType) {
case CENTER_BOTTOM:
case LEFT_BOTTOM:
case RIGHT_BOTTOM:
      return viewHeight - postDrawabeHeigth;
case LEFT_CENTER:
case RIGHT_CENTER:
    return (viewHeight - postDrawabeHeigth) / 2f;
}
}
return 0;
}
Program: 93430
Project: 93430
Buggy source:
private float getXTranslation(CropType cropType,float scale,int viewWidth,int drawableWidth,boolean verticalImageMode){
  if (!verticalImageMode) {
switch (cropType) {
case RIGHT_TOP:
case RIGHT_CENTER:
case RIGHT_BOTTOM:
      return viewWidth - (drawableWidth * scale);
case CENTER_TOP:
case CENTER_BOTTOM:
    return (float)(((float)viewWidth / 2.0) + ((float)drawableWidth / 2.0));
}
}
return 0;
}

Fixed version (ground truth):
private float getXTranslation(CropType cropType,int viewWidth,float postDrawableWidth,boolean verticalImageMode){
  if (!verticalImageMode) {
switch (cropType) {
case RIGHT_TOP:
case RIGHT_CENTER:
case RIGHT_BOTTOM:
      return viewWidth - postDrawableWidth;
case CENTER_TOP:
case CENTER_BOTTOM:
    return (viewWidth - postDrawableWidth) / 2f;
}
}
return 0;
}