nus-yam/ex-repair huggingface dataset:
Program: 3681
Project: 3681
Buggy source:
private void findLowEnergyDevices(CallbackContext callbackContext,UUID[] serviceUUIDs,int scanSeconds){
  if (!PermissionHelper.hasPermission(this,ACCESS_COARSE_LOCATION)) {
    permissionCallback=callbackContext;
    this.serviceUUIDs=serviceUUIDs;
    this.scanSeconds=scanSeconds;
    PermissionHelper.requestPermission(this,REQUEST_ACCESS_COARSE_LOCATION,ACCESS_COARSE_LOCATION);
    return;
  }
  if (bluetoothAdapter.isDiscovering()) {
    return;
  }
  for (Iterator<Map.Entry<String,Peripheral>> iterator=peripherals.entrySet().iterator(); iterator.hasNext(); ) {
    Map.Entry<String,Peripheral> entry=iterator.next();
    Peripheral device=entry.getValue();
    boolean connecting=device.isConnecting();
    if (connecting) {
      LOG.d(TAG,"String_Node_Str" + device.getDevice().getAddress());
    }
    if (!entry.getValue().isConnected() && !connecting) {
      iterator.remove();
    }
  }
  discoverCallback=callbackContext;
  if (serviceUUIDs.length > 0) {
    bluetoothAdapter.startLeScan(serviceUUIDs,this);
  }
 else {
    bluetoothAdapter.startLeScan(this);
  }
  if (scanSeconds > 0) {
    Handler handler=new Handler();
    handler.postDelayed(new Runnable(){
      @Override public void run(){
        LOG.d(TAG,"String_Node_Str");
        BLECentralPlugin.this.bluetoothAdapter.stopLeScan(BLECentralPlugin.this);
      }
    }
,scanSeconds * 1000);
  }
  PluginResult result=new PluginResult(PluginResult.Status.NO_RESULT);
  result.setKeepCallback(true);
  callbackContext.sendPluginResult(result);
}

Fixed version (ground truth):
private void findLowEnergyDevices(CallbackContext callbackContext,UUID[] serviceUUIDs,int scanSeconds){
  if (!PermissionHelper.hasPermission(this,ACCESS_COARSE_LOCATION)) {
    permissionCallback=callbackContext;
    this.serviceUUIDs=serviceUUIDs;
    this.scanSeconds=scanSeconds;
    PermissionHelper.requestPermission(this,REQUEST_ACCESS_COARSE_LOCATION,ACCESS_COARSE_LOCATION);
    return;
  }
  if (bluetoothAdapter.isDiscovering()) {
    return;
  }
  for (Iterator<Map.Entry<String,Peripheral>> iterator=peripherals.entrySet().iterator(); iterator.hasNext(); ) {
    Map.Entry<String,Peripheral> entry=iterator.next();
    Peripheral device=entry.getValue();
    boolean connecting=device.isConnecting();
    if (connecting) {
      LOG.d(TAG,"String_Node_Str" + device.getDevice().getAddress());
    }
    if (!entry.getValue().isConnected() && !connecting) {
      iterator.remove();
    }
  }
  discoverCallback=callbackContext;
  if (serviceUUIDs != null && serviceUUIDs.length > 0) {
    bluetoothAdapter.startLeScan(serviceUUIDs,this);
  }
 else {
    bluetoothAdapter.startLeScan(this);
  }
  if (scanSeconds > 0) {
    Handler handler=new Handler();
    handler.postDelayed(new Runnable(){
      @Override public void run(){
        LOG.d(TAG,"String_Node_Str");
        BLECentralPlugin.this.bluetoothAdapter.stopLeScan(BLECentralPlugin.this);
      }
    }
,scanSeconds * 1000);
  }
  PluginResult result=new PluginResult(PluginResult.Status.NO_RESULT);
  result.setKeepCallback(true);
  callbackContext.sendPluginResult(result);
}
Program: 3682
Project: 3682
Buggy source:
@Override public void onCharacteristicRead(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic,int status){
  super.onCharacteristicRead(gatt,characteristic,status);
  if (readCallback != null) {
    if (status == BluetoothGatt.GATT_SUCCESS) {
      readCallback.success(characteristic.getValue());
    }
 else {
      readCallback.error("String_Node_Str" + characteristic.getUuid() + "String_Node_Str"+ status);
    }
    readCallback=null;
  }
  commandCompleted();
}

Fixed version (ground truth):
@Override public void onCharacteristicRead(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic,int status){
  super.onCharacteristicRead(gatt,characteristic,status);
  LOG.d(TAG,"String_Node_Str" + characteristic);
  if (readCallback != null) {
    if (status == BluetoothGatt.GATT_SUCCESS) {
      readCallback.success(characteristic.getValue());
    }
 else {
      readCallback.error("String_Node_Str" + characteristic.getUuid() + "String_Node_Str"+ status);
    }
    readCallback=null;
  }
  commandCompleted();
}
Program: 3683
Project: 3683
Buggy source:
private void commandCompleted(){
  bleProcessing=false;
  processCommands();
}

Fixed version (ground truth):
private void commandCompleted(){
  LOG.d(TAG,"String_Node_Str");
  bleProcessing=false;
  processCommands();
}
Program: 3684
Project: 3684
Buggy source:
private void queueCommand(BLECommand command){
  commandQueue.add(command);
  PluginResult result=new PluginResult(PluginResult.Status.NO_RESULT);
  result.setKeepCallback(true);
  command.getCallbackContext().sendPluginResult(result);
  if (!bleProcessing) {
    processCommands();
  }
}

Fixed version (ground truth):
private void queueCommand(BLECommand command){
  LOG.d(TAG,"String_Node_Str" + command);
  commandQueue.add(command);
  PluginResult result=new PluginResult(PluginResult.Status.NO_RESULT);
  result.setKeepCallback(true);
  command.getCallbackContext().sendPluginResult(result);
  if (!bleProcessing) {
    LOG.d(TAG,"String_Node_Str");
    processCommands();
  }
 else {
    LOG.d(TAG,"String_Node_Str");
  }
}
Program: 3685
Project: 3685
Buggy source:
@Override public void onCharacteristicChanged(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic){
  super.onCharacteristicChanged(gatt,characteristic);
  CallbackContext callback=notificationCallbacks.get(generateHashKey(characteristic));
  if (callback != null) {
    PluginResult result=new PluginResult(PluginResult.Status.OK,characteristic.getValue());
    result.setKeepCallback(true);
    callback.sendPluginResult(result);
  }
}

Fixed version (ground truth):
@Override public void onCharacteristicChanged(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic){
  super.onCharacteristicChanged(gatt,characteristic);
  LOG.d(TAG,"String_Node_Str" + characteristic);
  CallbackContext callback=notificationCallbacks.get(generateHashKey(characteristic));
  if (callback != null) {
    PluginResult result=new PluginResult(PluginResult.Status.OK,characteristic.getValue());
    result.setKeepCallback(true);
    callback.sendPluginResult(result);
  }
}
Program: 3686
Project: 3686
Buggy source:
@Override public void onDescriptorWrite(BluetoothGatt gatt,BluetoothGattDescriptor descriptor,int status){
  super.onDescriptorWrite(gatt,descriptor,status);
  commandCompleted();
}

Fixed version (ground truth):
@Override public void onDescriptorWrite(BluetoothGatt gatt,BluetoothGattDescriptor descriptor,int status){
  super.onDescriptorWrite(gatt,descriptor,status);
  LOG.d(TAG,"String_Node_Str" + descriptor);
  commandCompleted();
}
Program: 3687
Project: 3687
Buggy source:
@Override public void onCharacteristicWrite(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic,int status){
  super.onCharacteristicWrite(gatt,characteristic,status);
}

Fixed version (ground truth):
@Override public void onCharacteristicWrite(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic,int status){
  super.onCharacteristicWrite(gatt,characteristic,status);
  LOG.d(TAG,"String_Node_Str" + characteristic);
  if (writeCallback != null) {
    if (status == BluetoothGatt.GATT_SUCCESS) {
      writeCallback.success();
    }
 else {
      writeCallback.error(status);
    }
    writeCallback=null;
  }
  commandCompleted();
}
Program: 3688
Project: 3688
Buggy source:
private void writeNoResponse(CallbackContext callbackContext,UUID serviceUUID,UUID characteristicUUID,byte[] data){
  try {
    if (gatt == null) {
      callbackContext.error("String_Node_Str");
      return;
    }
    BluetoothGattService service=gatt.getService(serviceUUID);
    BluetoothGattCharacteristic characteristic=service.getCharacteristic(characteristicUUID);
    if (characteristic == null) {
      callbackContext.error("String_Node_Str" + characteristicUUID + "String_Node_Str");
    }
 else {
      characteristic.setValue(data);
      characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
      if (gatt.writeCharacteristic(characteristic)) {
        callbackContext.success();
      }
 else {
        callbackContext.error("String_Node_Str");
      }
    }
  }
  finally {
    commandCompleted();
  }
}

Fixed version (ground truth):
private void writeNoResponse(CallbackContext callbackContext,UUID serviceUUID,UUID characteristicUUID,byte[] data){
  boolean success=false;
  try {
    if (gatt == null) {
      callbackContext.error("String_Node_Str");
      return;
    }
    BluetoothGattService service=gatt.getService(serviceUUID);
    BluetoothGattCharacteristic characteristic=service.getCharacteristic(characteristicUUID);
    if (characteristic == null) {
      callbackContext.error("String_Node_Str" + characteristicUUID + "String_Node_Str");
    }
 else {
      characteristic.setValue(data);
      characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
      if (gatt.writeCharacteristic(characteristic)) {
        writeCallback=callbackContext;
        success=true;
      }
 else {
        callbackContext.error("String_Node_Str");
      }
    }
  }
  finally {
    if (!success) {
      commandCompleted();
    }
  }
}
Program: 3689
Project: 3689
Buggy source:
private void processCommands(){
  if (bleProcessing) {
    return;
  }
  BLECommand command=commandQueue.poll();
  if (command != null) {
    if (command.getType() == BLECommand.READ) {
      bleProcessing=true;
      readCharacteristic(command.getCallbackContext(),command.getServiceUUID(),command.getCharacteristicUUID());
    }
 else     if (command.getType() == BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT) {
      bleProcessing=true;
      writeCharacteristic(command.getCallbackContext(),command.getServiceUUID(),command.getCharacteristicUUID(),command.getData());
    }
 else     if (command.getType() == BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE) {
      bleProcessing=true;
      writeNoResponse(command.getCallbackContext(),command.getServiceUUID(),command.getCharacteristicUUID(),command.getData());
    }
 else     if (command.getType() == BLECommand.REGISTER_NOTIFY) {
      bleProcessing=true;
      registerNotifyCallback(command.getCallbackContext(),command.getServiceUUID(),command.getCharacteristicUUID());
    }
 else {
      throw new RuntimeException("String_Node_Str" + command.getType());
    }
  }
}

Fixed version (ground truth):
private void processCommands(){
  LOG.d(TAG,"String_Node_Str");
  if (bleProcessing) {
    return;
  }
  BLECommand command=commandQueue.poll();
  if (command != null) {
    if (command.getType() == BLECommand.READ) {
      LOG.d(TAG,"String_Node_Str" + command.getCharacteristicUUID());
      bleProcessing=true;
      readCharacteristic(command.getCallbackContext(),command.getServiceUUID(),command.getCharacteristicUUID());
    }
 else     if (command.getType() == BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT) {
      LOG.d(TAG,"String_Node_Str" + command.getCharacteristicUUID());
      bleProcessing=true;
      writeCharacteristic(command.getCallbackContext(),command.getServiceUUID(),command.getCharacteristicUUID(),command.getData());
    }
 else     if (command.getType() == BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE) {
      LOG.d(TAG,"String_Node_Str" + command.getCharacteristicUUID());
      bleProcessing=true;
      writeNoResponse(command.getCallbackContext(),command.getServiceUUID(),command.getCharacteristicUUID(),command.getData());
    }
 else     if (command.getType() == BLECommand.REGISTER_NOTIFY) {
      LOG.d(TAG,"String_Node_Str" + command.getCharacteristicUUID());
      bleProcessing=true;
      registerNotifyCallback(command.getCallbackContext(),command.getServiceUUID(),command.getCharacteristicUUID());
    }
 else {
      throw new RuntimeException("String_Node_Str" + command.getType());
    }
  }
 else {
    LOG.d(TAG,"String_Node_Str");
  }
}
Program: 3690
Project: 3690
Buggy source:
public static void act(Long id,Point2D pos){
  if (pos == null) {
    return;
  }
  Unit target=getUnit(id);
  for (  Unit u : selection) {
    u.group.clear();
    u.group.addAll(selection);
  }
  if (target != null && target.faction != selection.get(0).faction) {
    orderAttack(target);
  }
 else {
    orderMove(pos);
  }
  moveAttack=false;
}

Fixed version (ground truth):
public static void act(Long id,Point2D pos){
  if (pos == null) {
    return;
  }
  Unit target=getUnit(id);
  Group group=new Group(selection);
  for (  Unit u : group) {
    u.group.remove(u);
    u.group=group;
  }
  if (target != null && target.faction != selection.get(0).faction) {
    orderAttack(target);
  }
 else {
    orderMove(pos);
  }
  moveAttack=false;
}
Program: 3691
Project: 3691
Buggy source:
public void updatePosition(double elapsedTime){
  double lastOrientation=hiker.getOrientation();
  Point3D lastPos=new Point3D(hiker.pos);
  if (!holdPosition) {
    Motion steering=sm.collectSteering();
    if (steering.isEmpty() && !Double.isNaN(desiredOrientation)) {
      steering.setAngle(desiredOrientation);
      desiredOrientation=Double.NaN;
    }
    Motion possibleMotion=hiker.getNearestPossibleMotion(steering,getDestination(),elapsedTime);
    Motion correctMotion=cm.correctMotion(possibleMotion,elapsedTime,toAvoid);
    hiker.move(correctMotion);
  }
  hasMoved=hiker.hasMoved(lastPos,lastOrientation);
  if (hasMoved) {
    updateElevation();
  }
  if (hasDestination) {
    hasFoundPost=false;
  }
 else {
    hasFoundPost=true;
    for (    Mover m : toFlockWith) {
      if (m.hasDestination) {
        hasFoundPost=false;
      }
    }
  }
  if (!tryHold) {
    holdPosition=false;
  }
}

Fixed version (ground truth):
public void updatePosition(double elapsedTime){
  double lastOrientation=hiker.getOrientation();
  Point3D lastPos=new Point3D(hiker.pos);
  if (!holdPosition) {
    Motion steering=sm.collectSteering();
    if (steering.isEmpty() && !Double.isNaN(desiredOrientation)) {
      steering.setAngle(desiredOrientation);
      desiredOrientation=Double.NaN;
    }
    Motion possibleMotion=hiker.getNearestPossibleMotion(steering,getDestination(),elapsedTime);
    Motion correctMotion=cm.correctMotion(possibleMotion,elapsedTime,toAvoid);
    hiker.move(correctMotion);
  }
  hasMoved=hiker.hasMoved(lastPos,lastOrientation);
  if (hasMoved) {
    updateElevation();
  }
  if (hasDestination) {
    hasFoundPost=false;
  }
 else {
    hasFoundPost=true;
    for (    Mover m : toFlockWith) {
      if (m.hasDestination) {
        hasFoundPost=false;
        break;
      }
    }
  }
  if (!tryHold) {
    holdPosition=false;
  }
}
Program: 3692
Project: 3692
Buggy source:
public boolean heading(Point2D target,double toleranceInDegrees){
  boolean res=AngleUtil.getSmallestDifference(getAngleTo(target),getOrientation()) <= AngleUtil.toRadians(toleranceInDegrees);
  return res;
}

Fixed version (ground truth):
public boolean heading(Point2D target,double toleranceInDegrees){
  return AngleUtil.getSmallestDifference(getAngleTo(target),getOrientation()) <= AngleUtil.toRadians(toleranceInDegrees);
}
Program: 3693
Project: 3693
Buggy source:
private Point3D getSeparationForce(List<Mover> neighbors){
  Point3D res=Point3D.ORIGIN;
  if (neighbors.isEmpty()) {
    return res;
  }
  for (  Mover n : neighbors) {
    if (n.hiker.priority < mover.hiker.priority)     continue;
    double neededDistance=n.hiker.getSpacing(mover.hiker) - n.hiker.getDistance(mover.hiker);
    if (neededDistance <= 0) {
      continue;
    }
    logger.info("String_Node_Str" + df.format(neededDistance));
    Point3D sepVector=n.hiker.getVectorTo(mover.hiker).getScaled(neededDistance);
    res=res.getAddition(sepVector);
  }
  if (res.isOrigin()) {
    return res;
  }
  if (mover.fly()) {
    return res.getMult(SEPARATION_FORCE_FOR_FLYING);
  }
  return res.getMult(SEPARATION_FORCE);
}

Fixed version (ground truth):
private Point3D getSeparationForce(List<Mover> neighbors){
  Point3D res=Point3D.ORIGIN;
  if (neighbors.isEmpty()) {
    return res;
  }
  for (  Mover n : neighbors) {
    double neededDistance=n.hiker.getSpacing(mover.hiker) - n.hiker.getDistance(mover.hiker);
    if (neededDistance <= 0) {
      continue;
    }
    if (n.hiker.priority < mover.hiker.priority)     neededDistance/=10;
    Point3D sepVector=n.hiker.getVectorTo(mover.hiker).getScaled(neededDistance);
    res=res.getAddition(sepVector);
  }
  if (res.isOrigin()) {
    return res;
  }
  if (mover.fly()) {
    return res.getMult(SEPARATION_FORCE_FOR_FLYING);
  }
  return res.getMult(SEPARATION_FORCE);
}
Program: 3694
Project: 3694
Buggy source:
void doWaitOrders(){
  if (!unit.getMover().hasFoundPost) {
    post=unit.getPos();
  }
  unit.idle();
  unit.getMover().separate();
  if (post != null && getPostDistance() > FREE_MOVE_RADIUS) {
    stateMachine.pushState(RETURN_POST);
    stateMachine.pushState(WAIT,DISTURB_DURATION);
  }
  if (unit.arming.scanning()) {
    stateMachine.pushState(RETURN_POST);
    stateMachine.pushState(AUTO_ATTACK,new ArrayList<>());
  }
  if (isAttacked()) {
    stateMachine.pushState(RETURN_POST);
    stateMachine.pushState(ATTACK_BACK);
  }
}

Fixed version (ground truth):
void doWaitOrders(){
  if (!unit.getMover().hasFoundPost) {
    post=unit.getPos();
  }
  unit.idle();
  unit.getMover().letPass();
  if (post != null && getPostDistance() > FREE_MOVE_RADIUS) {
    stateMachine.pushState(RETURN_POST);
    stateMachine.pushState(WAIT,DISTURB_DURATION);
  }
  if (unit.arming.scanning()) {
    stateMachine.pushState(RETURN_POST);
    stateMachine.pushState(AUTO_ATTACK,new ArrayList<>());
  }
  if (isAttacked()) {
    stateMachine.pushState(RETURN_POST);
    stateMachine.pushState(ATTACK_BACK);
  }
}
Program: 3695
Project: 3695
Buggy source:
void doWait(double duration){
  unit.getMover().separate();
  if (disturbTime == 0) {
    disturbTime=System.currentTimeMillis();
  }
 else   if (disturbTime + duration < System.currentTimeMillis()) {
    disturbTime=0;
    stateMachine.popState();
  }
}

Fixed version (ground truth):
void doWait(double duration){
  unit.getMover().letPass();
  if (disturbTime == 0) {
    disturbTime=System.currentTimeMillis();
  }
 else   if (disturbTime + duration < System.currentTimeMillis()) {
    disturbTime=0;
    stateMachine.popState();
  }
}
Program: 3696
Project: 3696
Buggy source:
void doReturnPost(){
  if (getPostDistance() < POST_TOLERANCE) {
    stateMachine.popState();
  }
 else   if (isAttacked()) {
    stateMachine.pushState(ATTACK_BACK);
  }
 else {
    unit.getMover().separate();
    unit.getMover().seek(post);
  }
}

Fixed version (ground truth):
void doReturnPost(){
  if (getPostDistance() < POST_TOLERANCE) {
    stateMachine.popState();
  }
 else   if (isAttacked()) {
    stateMachine.pushState(ATTACK_BACK);
  }
 else {
    unit.getMover().letPass();
    unit.getMover().seek(post);
  }
}
Program: 3697
Project: 3697
Buggy source:
void doHold(){
  post=unit.getPos();
  unit.idle();
  unit.getMover().tryToHoldPositionSoftly();
  unit.getMover().separate();
  if (unit.arming.acquiring()) {
    unit.arming.attack();
  }
}

Fixed version (ground truth):
void doHold(){
  post=unit.getPos();
  unit.idle();
  unit.getMover().tryToHoldPositionSoftly();
  unit.getMover().letPass();
  if (unit.arming.acquiring()) {
    unit.arming.attack();
  }
}
Program: 3698
Project: 3698
Buggy source:
public LightDrawer(MapView view,AssetManager am,Node rootNode,ViewPort vp){
  this.view=view;
  this.rootNode=rootNode;
  FilterPostProcessor fpp=new FilterPostProcessor(am);
  int SHADOWMAP_SIZE=4096;
  sf=new DirectionalLightShadowFilter(am,SHADOWMAP_SIZE,1);
  sf.setEnabled(true);
  sf.setShadowZExtend(SHADOWMAP_SIZE);
  fpp.addFilter(sf);
  SSAOFilter ssaoFilter=new SSAOFilter(0.5f,4f,0.2f,0.3f);
  BloomFilter bloom=new BloomFilter(BloomFilter.GlowMode.Objects);
  fpp.addFilter(bloom);
  vp.addProcessor(fpp);
}

Fixed version (ground truth):
public LightDrawer(MapView view,AssetManager am,Node rootNode,ViewPort vp){
  this.view=view;
  this.rootNode=rootNode;
  FilterPostProcessor fpp=new FilterPostProcessor(am);
  int SHADOWMAP_SIZE=4096;
  sf=new DirectionalLightShadowFilter(am,SHADOWMAP_SIZE,1);
  sf.setEnabled(true);
  sf.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
  sf.setShadowZExtend(SHADOWMAP_SIZE);
  fpp.addFilter(sf);
  SSAOFilter ssaoFilter=new SSAOFilter(0.5f,4f,0.2f,0.3f);
  BloomFilter bloom=new BloomFilter(BloomFilter.GlowMode.Objects);
  fpp.addFilter(bloom);
  vp.addProcessor(fpp);
}
Program: 3699
Project: 3699
Buggy source:
@JsonIgnore @Override public double getElevation(){
  return getModifiedElevation();
}

Fixed version (ground truth):
@Override public double getElevation(){
  if (modifiedLevel != 0) {
    return modifiedLevel * STAGE_HEIGHT + elevation;
  }
 else {
    return level * STAGE_HEIGHT + elevation;
  }
}
Program: 3700
Project: 3700
Buggy source:
private double getElevation(Tile t,Cliff c){
  if (t.getModifiedLevel() > c.level + 1) {
    return (c.level + 1) * Tile.STAGE_HEIGHT;
  }
  return t.getModifiedElevation();
}

Fixed version (ground truth):
private double getElevation(Tile t,Cliff c){
  if (t.getModifiedLevel() > c.level + 1) {
    return (c.level + 1) * Tile.STAGE_HEIGHT;
  }
  return t.getElevation();
}
Program: 3701
Project: 3701
Buggy source:
public double getElevation(){
  return ModelManager.getBattlefield().getMap().get(getContainerTilePos()).getModifiedElevation();
}

Fixed version (ground truth):
public double getElevation(){
  return ModelManager.getBattlefield().getMap().get(getContainerTilePos()).getElevation();
}
Program: 3702
Project: 3702
Buggy source:
public List<T> get8Around(T n){
  List<T> res=getAround(n,1);
  return res;
}

Fixed version (ground truth):
public List<T> get8Around(T n){
  List<T> res=getInSquareWithourCenter(n,1);
  return res;
}
Program: 3703
Project: 3703
Buggy source:
public List<T> get25Around(T n){
  List<T> res=getAround(n,2);
  return res;
}

Fixed version (ground truth):
public List<T> get25Around(T n){
  List<T> res=getInSquare(n,2);
  return res;
}
Program: 3704
Project: 3704
Buggy source:
public List<T> get9Around(T n){
  List<T> res=getAround(n,1);
  res.add(n);
  return res;
}

Fixed version (ground truth):
public List<T> get9Around(T n){
  List<T> res=getInSquare(n,1);
  return res;
}
Program: 3705
Project: 3705
Buggy source:
private Trinket grow(Sowing s){
  Trinket source=s.toGrow.get(RandomUtil.nextInt(s.toGrow.size()));
  List<Trinket> neibors=ModelManager.getBattlefield().getCloseComps(source,20);
  for (int i=0; i < MAX_TRINKETS_COUNT; i++) {
    int trinketIndex=RandomUtil.between(0,s.trinketBuilders.size());
    Trinket candidate=s.trinketBuilders.get(trinketIndex).build(Point3D.ORIGIN);
    candidate.separationRadius*=s.spacings.get(trinketIndex);
    for (int j=0; j < MAX_PLACES_COUNT; j++) {
      double separationDistance=source.getSpacing(candidate);
      Point2D place=source.getCoord().getTranslation(RandomUtil.between(0,AngleUtil.FULL),RandomUtil.between(separationDistance,separationDistance * 2));
      if (!ModelManager.getBattlefield().getMap().isInBounds(place) || !s.isAllowed(place)) {
        continue;
      }
      boolean isValidePlace=true;
      for (      Trinket n : neibors) {
        if (n.getCoord().getDistance(place) < n.getSpacing(candidate)) {
          isValidePlace=false;
          break;
        }
      }
      if (isValidePlace) {
        candidate.setPos(place.get3D(ModelManager.getBattlefield().getMap().getAltitudeAt(place)));
        sowTrinket(s,candidate);
        return candidate;
      }
    }
  }
  s.toGrow.remove(source);
  return null;
}

Fixed version (ground truth):
private Trinket grow(Sowing s){
  Map m=ModelManager.getBattlefield().getMap();
  Trinket source=s.toGrow.get(RandomUtil.nextInt(s.toGrow.size()));
  List<Trinket> neibors=m.getInCircle(Trinket.class,source.getCoord(),20);
  for (int i=0; i < MAX_TRINKETS_COUNT; i++) {
    int trinketIndex=RandomUtil.between(0,s.trinketBuilders.size());
    Trinket candidate=s.trinketBuilders.get(trinketIndex).build(Point3D.ORIGIN);
    candidate.separationRadius*=s.spacings.get(trinketIndex);
    for (int j=0; j < MAX_PLACES_COUNT; j++) {
      double separationDistance=source.getSpacing(candidate);
      Point2D place=source.getCoord().getTranslation(RandomUtil.between(0,AngleUtil.FULL),RandomUtil.between(separationDistance,separationDistance * 2));
      if (!m.isInBounds(place) || !s.isAllowed(place)) {
        continue;
      }
      boolean isValidePlace=true;
      for (      Trinket n : neibors) {
        if (n.getCoord().getDistance(place) < n.getSpacing(candidate)) {
          isValidePlace=false;
          break;
        }
      }
      if (isValidePlace) {
        candidate.setPos(place.get3D(m.getAltitudeAt(place)));
        sowTrinket(s,candidate);
        return candidate;
      }
    }
  }
  s.toGrow.remove(source);
  return null;
}
Program: 3706
Project: 3706
Buggy source:
private Trinket findNewPlace(Sowing s){
  double r1=RandomUtil.next();
  double r2=RandomUtil.next();
  Point2D randomPos=new Point2D(r1 * (ModelManager.getBattlefield().getMap().xSize() - 1),r2 * (ModelManager.getBattlefield().getMap().ySize() - 1));
  if (!ModelManager.getBattlefield().getMap().isInBounds(randomPos))   return null;
  if (s.isAllowed(randomPos)) {
    int trinketIndex=RandomUtil.between(0,s.trinketBuilders.size());
    TrinketBuilder tb=s.trinketBuilders.get(trinketIndex);
    Trinket candidate=tb.build(randomPos.get3D(ModelManager.getBattlefield().getMap().getAltitudeAt(randomPos)));
    candidate.separationRadius*=s.spacings.get(trinketIndex);
    boolean isValid=true;
    for (    Trinket n : ModelManager.getBattlefield().getCloseComps(candidate,randomPos,10)) {
      double separationDistance=n.getSpacing(candidate);
      if (n.getDistance(candidate) < separationDistance) {
        isValid=false;
        break;
      }
    }
    if (isValid) {
      sowTrinket(s,candidate);
      return candidate;
    }
  }
  return null;
}

Fixed version (ground truth):
private Trinket findNewPlace(Sowing s){
  Map m=ModelManager.getBattlefield().getMap();
  Point2D randomPos=new Point2D(RandomUtil.next() * (m.xSize() - 1),RandomUtil.next() * (m.ySize() - 1));
  if (s.isAllowed(randomPos)) {
    int trinketIndex=RandomUtil.between(0,s.trinketBuilders.size());
    TrinketBuilder tb=s.trinketBuilders.get(trinketIndex);
    Trinket candidate=tb.build(randomPos.get3D(m.getAltitudeAt(randomPos)));
    candidate.separationRadius*=s.spacings.get(trinketIndex);
    boolean isValid=true;
    for (    Trinket n : m.getInCircle(Trinket.class,randomPos,10)) {
      double separationDistance=n.getSpacing(candidate);
      if (n.getDistance(candidate) < separationDistance) {
        isValid=false;
        break;
      }
    }
    if (isValid) {
      sowTrinket(s,candidate);
      return candidate;
    }
  }
  return null;
}
Program: 3707
Project: 3707
Buggy source:
public boolean isAllowed(Point2D p){
  Map map=ModelManager.getBattlefield().getMap();
  if (distFromCliff > 0) {
    boolean hasCliff=false;
    for (    Tile t : map.getAround(p,distFromCliff)) {
      if (t.hasCliff()) {
        hasCliff=true;
        break;
      }
    }
    if (!hasCliff) {
      return false;
    }
  }
  if (slopeMin > 0 || slopeMax > 0) {
    double dist=map.getNormalVectorAt(p).get2D().getLength();
    double angle=AngleUtil.RIGHT - new Point2D(dist,1).getAngle();
    if (slopeMin > 0 && angle < AngleUtil.toRadians(slopeMin)) {
      return false;
    }
    if (slopeMax > 0 && angle > AngleUtil.toRadians(slopeMax)) {
      return false;
    }
  }
  if (!textures.isEmpty()) {
    int i=0;
    for (    String s : textures) {
      AtlasLayer l;
      int texIndex=Integer.parseInt(s);
      if (texIndex >= 8)       l=map.getCover().getLayers().get(texIndex - 8);
 else       l=map.getAtlas().getLayers().get(texIndex);
      if (l.getInAtlasSpace(p) < textureMin.get(i) * 255 || l.getInAtlasSpace(p) > textureMax.get(i) * 255) {
        return false;
      }
      i++;
    }
  }
  return true;
}

Fixed version (ground truth):
public boolean isAllowed(Point2D p){
  Map map=ModelManager.getBattlefield().getMap();
  if (distFromCliff > 0) {
    boolean hasCliff=false;
    for (    Tile t : map.getInCircle(p,distFromCliff)) {
      if (t.hasCliff()) {
        hasCliff=true;
        break;
      }
    }
    if (!hasCliff) {
      return false;
    }
  }
  if (slopeMin > 0 || slopeMax > 0) {
    double dist=map.getNormalVectorAt(p).get2D().getLength();
    double angle=AngleUtil.RIGHT - new Point2D(dist,1).getAngle();
    if (slopeMin > 0 && angle < AngleUtil.toRadians(slopeMin)) {
      return false;
    }
    if (slopeMax > 0 && angle > AngleUtil.toRadians(slopeMax)) {
      return false;
    }
  }
  if (!textures.isEmpty()) {
    int i=0;
    for (    String s : textures) {
      AtlasLayer l;
      int texIndex=Integer.parseInt(s);
      if (texIndex >= 8)       l=map.getCover().getLayers().get(texIndex - 8);
 else       l=map.getAtlas().getLayers().get(texIndex);
      if (l.getInAtlasSpace(p) < textureMin.get(i) * 255 || l.getInAtlasSpace(p) > textureMax.get(i) * 255) {
        return false;
      }
      i++;
    }
  }
  return true;
}
Program: 3708
Project: 3708
Buggy source:
private Trinket grow(Sowing s){
  Trinket source=s.toGrow.get(MyRandom.nextInt(s.toGrow.size()));
  List<Trinket> neibors=ModelManager.getBattlefield().getCloseComps(source,10);
  for (int i=0; i < MAX_TRINKETS_COUNT; i++) {
    Trinket candidate=s.trinketBuilders.get(MyRandom.between(0,s.trinketBuilders.size() - 1)).build(Point3D.ORIGIN);
    for (int j=0; j < MAX_PLACES_COUNT; j++) {
      double separationDistance=source.getRadius() + candidate.getRadius();
      Point2D place=source.getCoord().getTranslation(MyRandom.between(0,Angle.FULL),MyRandom.between(separationDistance,separationDistance * 2));
      if (!ModelManager.getBattlefield().getMap().isInBounds(place) || !s.isAllowed(place))       continue;
      boolean isValidePlace=true;
      for (      Trinket n : neibors)       if (n.getCoord().getDistance(place) < n.getRadius() + candidate.getRadius()) {
        isValidePlace=false;
        break;
      }
      if (isValidePlace) {
        candidate.setPos(place.get3D(ModelManager.getBattlefield().getMap().getAltitudeAt(place)));
        sowTrinket(s,candidate);
        return candidate;
      }
    }
  }
  s.toGrow.remove(source);
  return null;
}

Fixed version (ground truth):
private Trinket grow(Sowing s){
  Trinket source=s.toGrow.get(MyRandom.nextInt(s.toGrow.size()));
  List<Trinket> neibors=ModelManager.getBattlefield().getCloseComps(source,10);
  for (int i=0; i < MAX_TRINKETS_COUNT; i++) {
    Trinket candidate=s.trinketBuilders.get(MyRandom.between(0,s.trinketBuilders.size())).build(Point3D.ORIGIN);
    for (int j=0; j < MAX_PLACES_COUNT; j++) {
      double separationDistance=source.getRadius() + candidate.getRadius();
      Point2D place=source.getCoord().getTranslation(MyRandom.between(0,Angle.FULL),MyRandom.between(separationDistance,separationDistance * 2));
      if (!ModelManager.getBattlefield().getMap().isInBounds(place) || !s.isAllowed(place))       continue;
      boolean isValidePlace=true;
      for (      Trinket n : neibors)       if (n.getCoord().getDistance(place) < n.getRadius() + candidate.getRadius()) {
        isValidePlace=false;
        break;
      }
      if (isValidePlace) {
        candidate.setPos(place.get3D(ModelManager.getBattlefield().getMap().getAltitudeAt(place)));
        sowTrinket(s,candidate);
        return candidate;
      }
    }
  }
  s.toGrow.remove(source);
  return null;
}
Program: 3709
Project: 3709
Buggy source:
private void sowTrinket(Sowing s,Trinket t){
  t.drawOnBattlefield();
  s.toGrow.add(t);
  ModelManager.getBattlefield().store(t);
}

Fixed version (ground truth):
private void sowTrinket(Sowing s,Trinket t){
  t.drawOnBattlefield();
  s.toGrow.add(t);
}
Program: 3710
Project: 3710
Buggy source:
@Override public void run(){
  thread=Thread.currentThread();
  try {
    while (!Thread.currentThread().isInterrupted()) {
      if (pauseAsked) {
synchronized (this) {
          paused=true;
          this.wait();
          paused=false;
          pauseAsked=false;
        }
      }
      for (      Sowing s : sowings) {
        Trinket newTrinket;
        if (s.toGrow.isEmpty()) {
          newTrinket=findNewPlace(s);
        }
 else {
          newTrinket=grow(s);
        }
        if (newTrinket != null) synchronized (ModelManager.getBattlefield().getMap()) {
          ModelManager.getBattlefield().getMap().getTrinkets().add(newTrinket);
        }
      }
    }
  }
 catch (  InterruptedException e) {
  }
}

Fixed version (ground truth):
@Override public void run(){
  thread=Thread.currentThread();
  try {
    while (!Thread.currentThread().isInterrupted()) {
      if (pauseAsked) {
synchronized (this) {
          paused=true;
          this.wait();
          paused=false;
          pauseAsked=false;
        }
      }
      for (      Sowing s : sowings) {
        Trinket newTrinket;
        if (s.toGrow.isEmpty()) {
          newTrinket=findNewPlace(s);
        }
 else {
          newTrinket=grow(s);
        }
        if (newTrinket != null) synchronized (ModelManager.getBattlefield().getMap()) {
          MapArtisan.attachTrinket(newTrinket,ModelManager.getBattlefield().getMap());
        }
      }
    }
  }
 catch (  InterruptedException e) {
  }
}
Program: 3711
Project: 3711
Buggy source:
private Trinket findNewPlace(Sowing s){
  Point2D randomPos=new Point2D(MyRandom.next() * (double)ModelManager.getBattlefield().getMap().xSize(),MyRandom.next() * (double)ModelManager.getBattlefield().getMap().ySize());
  if (s.isAllowed(randomPos)) {
    for (    TrinketBuilder tb : s.trinketBuilders) {
      Trinket candidate=tb.build(randomPos.get3D(ModelManager.getBattlefield().getMap().getAltitudeAt(randomPos)));
      boolean isValid=true;
      for (      Trinket n : ModelManager.getBattlefield().getCloseComps(candidate,randomPos,10)) {
        double separationDistance=n.getRadius() + candidate.getRadius();
        if (n.getDistance(candidate) < separationDistance) {
          isValid=false;
          break;
        }
      }
      if (isValid) {
        sowTrinket(s,candidate);
        return candidate;
      }
    }
  }
  return null;
}

Fixed version (ground truth):
private Trinket findNewPlace(Sowing s){
  Point2D randomPos=new Point2D(MyRandom.next() * (double)ModelManager.getBattlefield().getMap().xSize(),MyRandom.next() * (double)ModelManager.getBattlefield().getMap().ySize());
  if (s.isAllowed(randomPos)) {
    TrinketBuilder tb=s.trinketBuilders.get(MyRandom.between(0,s.trinketBuilders.size()));
    Trinket candidate=tb.build(randomPos.get3D(ModelManager.getBattlefield().getMap().getAltitudeAt(randomPos)));
    boolean isValid=true;
    for (    Trinket n : ModelManager.getBattlefield().getCloseComps(candidate,randomPos,10)) {
      double separationDistance=n.getRadius() + candidate.getRadius();
      if (n.getDistance(candidate) < separationDistance) {
        isValid=false;
        break;
      }
    }
    if (isValid) {
      sowTrinket(s,candidate);
      return candidate;
    }
  }
  return null;
}
Program: 3712
Project: 3712
Buggy source:
public Sower(){
  Sowing tree=new Sowing();
  tree.addTrinket("String_Node_Str");
  tree.setCliffDist(2);
  tree.setMaxSlope(30);
  sowings.add(tree);
  Sowing rocks=new Sowing();
  rocks.addTrinket("String_Node_Str");
  rocks.setMinSlope(20);
  rocks.allowedGrounds.add("String_Node_Str");
  rocks.allowedGrounds.add("String_Node_Str");
  sowings.add(rocks);
}

Fixed version (ground truth):
public Sower(){
  Sowing tree=new Sowing();
  tree.addTrinket("String_Node_Str");
  tree.addTrinket("String_Node_Str");
  tree.setCliffDist(2);
  tree.setMaxSlope(30);
  sowings.add(tree);
  Sowing rocks=new Sowing();
  rocks.addTrinket("String_Node_Str");
  rocks.setMinSlope(20);
  rocks.allowedGrounds.add("String_Node_Str");
  rocks.allowedGrounds.add("String_Node_Str");
  sowings.add(rocks);
}
Program: 3713
Project: 3713
Buggy source:
@Override public void update(float elapsedTime){
  ToolManager.setPointedSpatialLabel(spatialSelector.getSpatialLabel());
  ToolManager.setPointedSpatialEntityId(spatialSelector.getEntityId());
  Point2D coord=spatialSelector.getCoord(view.editorRend.gridNode);
  if (coord != null && ModelManager.getBattlefield().getMap().isInBounds(coord)) {
    ToolManager.updatePencilsPos(coord);
    view.editorRend.drawPencil();
  }
  guiController.update();
}

Fixed version (ground truth):
@Override public void update(float elapsedTime){
  ToolManager.setPointedSpatialLabel(spatialSelector.getSpatialLabel());
  ToolManager.setPointedSpatialEntityId(spatialSelector.getEntityId());
  Point2D coord=spatialSelector.getCoord(view.editorRend.gridNode);
  if (coord != null && ModelManager.battlefieldReady && ModelManager.getBattlefield().getMap().isInBounds(coord)) {
    ToolManager.updatePencilsPos(coord);
    view.editorRend.drawPencil();
  }
  guiController.update();
}
Program: 3714
Project: 3714
Buggy source:
private static void setBattlefield(Battlefield battlefield){
  if (battlefield != null) {
    ModelManager.battlefield=battlefield;
    ParcelManager.createParcelMeshes(ModelManager.getBattlefield().getMap());
    battlefieldReady=true;
    getBattlefield().getMap().resetTrinkets();
    getBattlefield().getEngagement().reset();
    EventManager.post(new BattleFieldUpdateEvent());
    LogUtil.logger.info("String_Node_Str");
  }
}

Fixed version (ground truth):
private static void setBattlefield(Battlefield battlefield){
  if (battlefield != null) {
    ModelManager.battlefield=battlefield;
    battlefieldReady=true;
    ParcelManager.createParcelMeshes(ModelManager.getBattlefield().getMap());
    getBattlefield().getMap().resetTrinkets();
    getBattlefield().getEngagement().reset();
    EventManager.post(new BattleFieldUpdateEvent());
    LogUtil.logger.info("String_Node_Str");
  }
}
Program: 3717
Project: 3717
Buggy source:
public void loadFromFile(String fileName){
  byte[] bytes=new byte[width * height * LAYER_COUNT];
  try {
    FileInputStream fis=new FileInputStream(fileName + "String_Node_Str");
    fis.read(bytes,0,width * height * LAYER_COUNT);
    fis.close();
  }
 catch (  IOException e) {
    throw new TechnicalException("String_Node_Str" + e);
  }
  int index=0;
  layers.clear();
  for (int i=0; i < LAYER_COUNT; i++) {
    AtlasLayer l=new AtlasLayer(width,height);
    for (int xy=0; xy < width * height; xy++) {
      l.setByte(xy,bytes[index++]);
    }
    layers.add(l);
  }
  buffers.clear();
  buffers.add(buildBuffer(0));
  buffers.add(buildBuffer(1));
  toUpdate=true;
}

Fixed version (ground truth):
public void loadFromFile(String fileName,String suffix){
  byte[] bytes=new byte[width * height * LAYER_COUNT];
  try {
    FileInputStream fis=new FileInputStream(fileName + suffix);
    fis.read(bytes,0,width * height * LAYER_COUNT);
    fis.close();
  }
 catch (  IOException e) {
    throw new TechnicalException("String_Node_Str" + e);
  }
  int index=0;
  layers.clear();
  for (int i=0; i < LAYER_COUNT; i++) {
    AtlasLayer l=new AtlasLayer(width,height);
    for (int xy=0; xy < width * height; xy++) {
      l.setByte(xy,bytes[index++]);
    }
    layers.add(l);
  }
  buffers.clear();
  buffers.add(buildBuffer(0));
  buffers.add(buildBuffer(1));
  toUpdate=true;
}
Program: 3718
Project: 3718
Buggy source:
public ByteBuffer getBuffer(int index){
  return buffers.get(index);
}

Fixed version (ground truth):
public ByteBuffer getBuffer(int index){
  if (!finalized)   LogUtil.logger.warning("String_Node_Str");
  return buffers.get(index);
}
Program: 3719
Project: 3719
Buggy source:
public List<AtlasLayer> getLayers(){
  return layers;
}

Fixed version (ground truth):
public List<AtlasLayer> getLayers(){
  if (!finalized)   LogUtil.logger.warning("String_Node_Str");
  return layers;
}
Program: 3720
Project: 3720
Buggy source:
public void saveToFile(String fileName){
  byte[] bytes=new byte[width * height * LAYER_COUNT];
  int index=0;
  for (  AtlasLayer l : layers) {
    for (    Byte b : l.getBytes()) {
      bytes[index++]=b;
    }
  }
  try {
    FileOutputStream fos=new FileOutputStream(fileName + "String_Node_Str");
    fos.write(bytes);
    fos.close();
  }
 catch (  IOException e) {
    System.out.println("String_Node_Str" + e);
  }
}

Fixed version (ground truth):
public void saveToFile(String fileName,String suffix){
  byte[] bytes=new byte[width * height * LAYER_COUNT];
  int index=0;
  for (  AtlasLayer l : layers) {
    for (    Byte b : l.getBytes()) {
      bytes[index++]=b;
    }
  }
  try {
    FileOutputStream fos=new FileOutputStream(fileName + suffix);
    fos.write(bytes);
    fos.close();
  }
 catch (  IOException e) {
    System.out.println("String_Node_Str" + e);
  }
}
Program: 3721
Project: 3721
Buggy source:
@Override public void finalize(){
  width=mapWidth * RESOLUTION_RATIO;
  height=mapHeight * RESOLUTION_RATIO;
  layers.add(new AtlasLayer(width,height,AtlasLayer.MAX_VALUE));
  for (int i=1; i < LAYER_COUNT; i++) {
    layers.add(new AtlasLayer(width,height,0));
  }
  buffers.add(buildBuffer(0));
  buffers.add(buildBuffer(1));
}

Fixed version (ground truth):
@Override public void finalize(){
  width=mapWidth * RESOLUTION_RATIO;
  height=mapHeight * RESOLUTION_RATIO;
  layers.add(new AtlasLayer(width,height,AtlasLayer.MAX_VALUE));
  for (int i=1; i < LAYER_COUNT; i++) {
    layers.add(new AtlasLayer(width,height,0));
  }
  buffers.add(buildBuffer(0));
  buffers.add(buildBuffer(1));
  finalized=true;
}
Program: 3723
Project: 3723
Buggy source:
@Override public void finalize(){
  width=mapWidth * RESOLUTION_RATIO;
  height=mapHeight * RESOLUTION_RATIO;
  layers.add(new AtlasLayer(width,height,1));
  for (int i=1; i < LAYER_COUNT; i++) {
    layers.add(new AtlasLayer(width,height,0));
  }
  buffers.add(buildBuffer(0));
  buffers.add(buildBuffer(1));
}

Fixed version (ground truth):
@Override public void finalize(){
  width=mapWidth * RESOLUTION_RATIO;
  height=mapHeight * RESOLUTION_RATIO;
  layers.add(new AtlasLayer(width,height,AtlasLayer.MAX_VALUE));
  for (int i=1; i < LAYER_COUNT; i++) {
    layers.add(new AtlasLayer(width,height,0));
  }
  buffers.add(buildBuffer(0));
  buffers.add(buildBuffer(1));
}
Program: 3724
Project: 3724
Buggy source:
private int getBufferVal(int x,int y,int firstLayerIndex){
  int r=(int)Math.round(layers.get(firstLayerIndex).get(x,y) * 255) << 24;
  int g=(int)Math.round(layers.get(firstLayerIndex + 1).get(x,y) * 255) << 16;
  int b=(int)Math.round(layers.get(firstLayerIndex + 2).get(x,y) * 255) << 8;
  int a=(int)Math.round(layers.get(firstLayerIndex + 3).get(x,y) * 255);
  return (r + g + b+ a);
}

Fixed version (ground truth):
private int getBufferVal(int x,int y,int firstLayerIndex){
  int r=(int)Math.round(layers.get(firstLayerIndex).get(x,y)) << 24;
  int g=(int)Math.round(layers.get(firstLayerIndex + 1).get(x,y)) << 16;
  int b=(int)Math.round(layers.get(firstLayerIndex + 2).get(x,y)) << 8;
  int a=(int)Math.round(layers.get(firstLayerIndex + 3).get(x,y));
  return (r + g + b+ a);
}
Program: 3725
Project: 3725
Buggy source:
public double addAndReturnExcess(int x,int y,double toAdd){
  double excess=0;
  double newVal=get(x,y) + toAdd;
  if (newVal > 1) {
    excess=newVal - 1;
    newVal=1;
  }
  set(x,y,newVal);
  return excess;
}

Fixed version (ground truth):
public double addAndReturnExcess(int x,int y,double toAdd){
  double excess=0;
  double newVal=get(x,y) + toAdd;
  if (newVal > MAX_VALUE) {
    excess=newVal - MAX_VALUE;
    newVal=MAX_VALUE;
  }
  set(x,y,newVal);
  return excess;
}
Program: 3726
Project: 3726
Buggy source:
public void set(int x,int y,double val){
  values.set(x,y,(byte)(val * 255 - 128));
}

Fixed version (ground truth):
public void set(int x,int y,double val){
  values.set(x,y,(byte)(val - 128));
}
Program: 3727
Project: 3727
Buggy source:
public double get(int x,int y){
  return ((double)values.get(x,y) + 128) / 255;
}

Fixed version (ground truth):
public double get(int x,int y){
  return ((double)values.get(x,y) + 128);
}
Program: 3728
Project: 3728
Buggy source:
public AtlasLayer(int xSize,int ySize,double val){
  values=new Map2D<Byte>(xSize,ySize,(byte)(val * 255 - 128));
}

Fixed version (ground truth):
public AtlasLayer(int xSize,int ySize,double val){
  values=new Map2D<Byte>(xSize,ySize,(byte)(val - 128));
}
Program: 3729
Project: 3729
Buggy source:
private void decrement(Point2D p,int layer){
  int x=(int)Math.round(p.x);
  int y=(int)Math.round(p.y);
  double attenuatedInc=increment * pencil.strength * pencil.getApplicationRatio(explorer.getInMapSpace(p));
  double valueToDitribute=attenuatedInc;
  ArrayList<AtlasLayer> availableLayers=new ArrayList<>();
  for (  AtlasLayer l : ModelManager.getBattlefield().getMap().atlas.getLayers()) {
    if (ModelManager.getBattlefield().getMap().atlas.getLayers().indexOf(l) == layer) {
      valueToDitribute-=l.withdrawAndReturnExcess(x,y,attenuatedInc);
    }
 else     if (l.get(x,y) > 0) {
      availableLayers.add(l);
    }
  }
  if (availableLayers.isEmpty()) {
    availableLayers.add(ModelManager.getBattlefield().getMap().atlas.getLayers().get(0));
  }
  int secur=-1;
  while (valueToDitribute > 0 && !availableLayers.isEmpty() && secur++ < 50) {
    ArrayList<AtlasLayer> unavailableLayers=new ArrayList<>();
    double shared=valueToDitribute / availableLayers.size();
    valueToDitribute=0;
    for (    AtlasLayer l : availableLayers) {
      valueToDitribute+=l.addAndReturnExcess(x,y,shared);
      if (l.get(x,y) == 255) {
        unavailableLayers.add(l);
      }
    }
    availableLayers.removeAll(unavailableLayers);
  }
  if (secur > 40) {
    LogUtil.logger.warning("String_Node_Str");
  }
  ModelManager.getBattlefield().getMap().atlas.updatePixel(x,y);
}

Fixed version (ground truth):
private void decrement(Point2D p,int layer){
  int x=(int)Math.round(p.x);
  int y=(int)Math.round(p.y);
  double attenuatedInc=Math.round(increment * pencil.strength * pencil.getApplicationRatio(explorer.getInMapSpace(p)));
  double valueToDitribute=attenuatedInc;
  ArrayList<AtlasLayer> availableLayers=new ArrayList<>();
  for (  AtlasLayer l : ModelManager.getBattlefield().getMap().atlas.getLayers()) {
    if (ModelManager.getBattlefield().getMap().atlas.getLayers().indexOf(l) == layer) {
      valueToDitribute-=l.withdrawAndReturnExcess(x,y,attenuatedInc);
    }
 else     if (l.get(x,y) > 0) {
      availableLayers.add(l);
    }
  }
  if (availableLayers.isEmpty()) {
    availableLayers.add(ModelManager.getBattlefield().getMap().atlas.getLayers().get(0));
  }
  int secur=-1;
  while (valueToDitribute > 0 && !availableLayers.isEmpty() && secur++ < 50) {
    ArrayList<AtlasLayer> unavailableLayers=new ArrayList<>();
    double shared=valueToDitribute / availableLayers.size();
    valueToDitribute=0;
    for (    AtlasLayer l : availableLayers) {
      valueToDitribute+=l.addAndReturnExcess(x,y,shared);
      if (l.get(x,y) == 255) {
        unavailableLayers.add(l);
      }
    }
    availableLayers.removeAll(unavailableLayers);
  }
  if (secur > 40) {
    LogUtil.logger.warning("String_Node_Str");
  }
  ModelManager.getBattlefield().getMap().atlas.updatePixel(x,y);
}