nus-yam/ex-repair huggingface dataset:
Program: 3730
Project: 3730
Buggy source:
private void increment(Point2D p,int layer){
  Atlas toPaint=ModelManager.getBattlefield().getMap().atlas;
  if (layer > 3) {
    toPaint=ModelManager.getBattlefield().getMap().cover;
    layer-=4;
  }
  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 : toPaint.getLayers()) {
    if (toPaint.getLayers().indexOf(l) == layer) {
      valueToDitribute-=l.addAndReturnExcess(x,y,attenuatedInc);
    }
 else {
      if (l.get(x,y) > 0)       availableLayers.add(l);
    }
  }
  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.withdrawAndReturnExcess(x,y,shared);
      if (l.get(x,y) == 0) {
        unavailableLayers.add(l);
      }
    }
    availableLayers.removeAll(unavailableLayers);
  }
  if (secur > 40) {
    LogUtil.logger.warning("String_Node_Str");
  }
  toPaint.updatePixel(x,y);
  DecimalFormat df=new DecimalFormat("String_Node_Str");
  String val="String_Node_Str";
  double total=0;
  for (  AtlasLayer l : toPaint.getLayers()) {
    val+=df.format(l.get(x,y)) + "String_Node_Str";
    total+=l.get(x,y);
  }
  LogUtil.logger.info(val);
  LogUtil.logger.info("String_Node_Str" + df.format(total));
}

Fixed version (ground truth):
private void increment(Point2D p,int layer){
  Atlas toPaint=ModelManager.getBattlefield().getMap().atlas;
  if (layer > 3) {
    toPaint=ModelManager.getBattlefield().getMap().cover;
    layer-=4;
  }
  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 : toPaint.getLayers()) {
    if (toPaint.getLayers().indexOf(l) == layer) {
      valueToDitribute-=l.addAndReturnExcess(x,y,attenuatedInc);
    }
 else {
      if (l.get(x,y) > 0)       availableLayers.add(l);
    }
  }
  int secur=-1;
  while (valueToDitribute > 0 && !availableLayers.isEmpty() && secur++ < 50) {
    ArrayList<AtlasLayer> unavailableLayers=new ArrayList<>();
    double shared=Math.round(valueToDitribute / availableLayers.size());
    valueToDitribute=0;
    for (    AtlasLayer l : availableLayers) {
      valueToDitribute+=l.withdrawAndReturnExcess(x,y,shared);
      if (l.get(x,y) == 0) {
        unavailableLayers.add(l);
      }
    }
    availableLayers.removeAll(unavailableLayers);
  }
  if (secur > 40) {
    LogUtil.logger.warning("String_Node_Str");
  }
  toPaint.updatePixel(x,y);
}
Program: 3731
Project: 3731
Buggy source:
private void smooth(ArrayList<Point2D> pixels){
  for (  Point2D p : pixels) {
    int x=(int)Math.round(p.x);
    int y=(int)Math.round(p.y);
    double attenuatedInc=increment * pencil.strength * pencil.getApplicationRatio(new Point2D(x,y).getMult(ModelManager.getBattlefield().getMap().width,ModelManager.getBattlefield().getMap().height).getDivision(ModelManager.getBattlefield().getMap().atlas.getWidth(),ModelManager.getBattlefield().getMap().atlas.getHeight()));
    int activeLayerCount=0;
    for (    AtlasLayer l : ModelManager.getBattlefield().getMap().atlas.getLayers()) {
      if (l.get(x,y) != 0) {
        activeLayerCount++;
      }
    }
    double targetVal=255 / activeLayerCount;
    for (    AtlasLayer l : ModelManager.getBattlefield().getMap().atlas.getLayers()) {
      if (l.get(x,y) != 0) {
        double diff=targetVal - l.get(x,y);
        if (diff < 0) {
          l.set(x,y,l.get(x,y) + Math.max(diff,-attenuatedInc));
        }
 else         if (diff > 0) {
          l.set(x,y,l.get(x,y) + Math.min(diff,attenuatedInc));
        }
      }
    }
    ModelManager.getBattlefield().getMap().atlas.updatePixel(x,y);
  }
}

Fixed version (ground truth):
private void smooth(ArrayList<Point2D> pixels){
  for (  Point2D p : pixels) {
    int x=(int)Math.round(p.x);
    int y=(int)Math.round(p.y);
    double attenuatedInc=Math.round(increment * pencil.strength * pencil.getApplicationRatio(new Point2D(x,y).getMult(ModelManager.getBattlefield().getMap().width,ModelManager.getBattlefield().getMap().height).getDivision(ModelManager.getBattlefield().getMap().atlas.getWidth(),ModelManager.getBattlefield().getMap().atlas.getHeight())));
    int activeLayerCount=0;
    for (    AtlasLayer l : ModelManager.getBattlefield().getMap().atlas.getLayers()) {
      if (l.get(x,y) != 0) {
        activeLayerCount++;
      }
    }
    double targetVal=255 / activeLayerCount;
    for (    AtlasLayer l : ModelManager.getBattlefield().getMap().atlas.getLayers()) {
      if (l.get(x,y) != 0) {
        double diff=targetVal - l.get(x,y);
        if (diff < 0) {
          l.set(x,y,l.get(x,y) + Math.max(diff,-attenuatedInc));
        }
 else         if (diff > 0) {
          l.set(x,y,l.get(x,y) + Math.min(diff,attenuatedInc));
        }
      }
    }
    ModelManager.getBattlefield().getMap().atlas.updatePixel(x,y);
  }
}
Program: 3732
Project: 3732
Buggy source:
public void buildMaterial(){
  mat=new Material(am,"String_Node_Str");
  Texture2D alpha0=new Texture2D(new Image(Image.Format.RGBA8,atlas.getWidth(),atlas.getHeight(),atlas.getBuffer(0)));
  mat.setTexture("String_Node_Str",alpha0);
  Texture2D alpha1=new Texture2D(new Image(Image.Format.RGBA8,atlas.getWidth(),atlas.getHeight(),atlas.getBuffer(1)));
  mat.setTexture("String_Node_Str",alpha1);
  mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
  for (int i=0; i < 12; i++) {
    if (diffuseMaps.size() > i) {
      if (i == 0) {
        mat.setTexture("String_Node_Str",diffuseMaps.get(i));
      }
 else {
        mat.setTexture("String_Node_Str" + i,diffuseMaps.get(i));
      }
      mat.setFloat("String_Node_Str" + i + "String_Node_Str",scales.get(i).floatValue());
      if (normaMaps.get(i) != null) {
        if (i == 0) {
          mat.setTexture("String_Node_Str",normaMaps.get(i));
        }
 else {
          mat.setTexture("String_Node_Str" + i,normaMaps.get(i));
        }
      }
    }
  }
}

Fixed version (ground truth):
public void buildMaterial(){
  mat=new Material(am,"String_Node_Str");
  Texture2D alpha0=new Texture2D(new Image(Image.Format.RGBA8,atlas.getWidth(),atlas.getHeight(),atlas.getBuffer(0)));
  mat.setTexture("String_Node_Str",alpha0);
  Texture2D alpha1=new Texture2D(new Image(Image.Format.RGBA8,atlas.getWidth(),atlas.getHeight(),atlas.getBuffer(1)));
  mat.setTexture("String_Node_Str",alpha1);
  if (transp)   mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
  for (int i=0; i < 12; i++) {
    if (diffuseMaps.size() > i) {
      if (i == 0) {
        mat.setTexture("String_Node_Str",diffuseMaps.get(i));
      }
 else {
        mat.setTexture("String_Node_Str" + i,diffuseMaps.get(i));
      }
      mat.setFloat("String_Node_Str" + i + "String_Node_Str",scales.get(i).floatValue());
      if (normaMaps.get(i) != null) {
        if (i == 0) {
          mat.setTexture("String_Node_Str",normaMaps.get(i));
        }
 else {
          mat.setTexture("String_Node_Str" + i,normaMaps.get(i));
        }
      }
    }
  }
}
Program: 3733
Project: 3733
Buggy source:
public AtlasTool(){
  super(ADD_DELETE_OP,PROPAGATE_SMOOTH_OP);
  explorer=new AtlasExplorer(ModelManager.getBattlefield().getMap());
  List<String> allTextures=ModelManager.getBattlefield().getMap().style.diffuses;
  while (allTextures.size() < 8)   allTextures.add(null);
  allTextures.addAll(ModelManager.getBattlefield().getMap().style.coverDiffuses);
  set=new AssetSet(allTextures,true);
}

Fixed version (ground truth):
public AtlasTool(){
  super(ADD_DELETE_OP,PROPAGATE_SMOOTH_OP);
  explorer=new AtlasExplorer(ModelManager.getBattlefield().getMap());
  List<String> allTextures=new ArrayList<>();
  allTextures.addAll(ModelManager.getBattlefield().getMap().style.diffuses);
  while (allTextures.size() < 8)   allTextures.add(null);
  allTextures.addAll(ModelManager.getBattlefield().getMap().style.coverDiffuses);
  set=new AssetSet(allTextures,true);
}
Program: 3734
Project: 3734
Buggy source:
public void resetTrinkets(){
  trinkets.clear();
  for (  SerializableTrinket st : serializableTrinkets) {
    trinkets.add(st.getTrinket());
  }
}

Fixed version (ground truth):
public void resetTrinkets(){
  trinkets.clear();
  for (  SerializableTrinket st : serializableTrinkets) {
    Trinket t=st.getTrinket();
    trinkets.add(t);
    t.drawOnBattlefield();
  }
}
Program: 3735
Project: 3735
Buggy source:
private void add(){
  Point2D pos=pencil.getCoord();
  for (  Trinket t : ModelManager.getBattlefield().getMap().trinkets) {
    if (t.pos.equals(pos)) {
      pos=pos.getTranslation(MyRandom.between(Angle.FLAT,-Angle.FLAT),0.1);
    }
  }
  Trinket t=BuilderManager.getAllEditableTrinketBuilders().get(set.actual).build(pos.get3D(ModelManager.getBattlefield().getMap().getAltitudeAt(pos)));
  ModelManager.getBattlefield().getMap().trinkets.add(t);
}

Fixed version (ground truth):
private void add(){
  Point2D pos=pencil.getCoord();
  for (  Trinket t : ModelManager.getBattlefield().getMap().trinkets) {
    if (t.pos.equals(pos)) {
      pos=pos.getTranslation(MyRandom.between(Angle.FLAT,-Angle.FLAT),0.1);
    }
  }
  Trinket t=BuilderManager.getAllEditableTrinketBuilders().get(set.actual).build(pos.get3D(ModelManager.getBattlefield().getMap().getAltitudeAt(pos)));
  t.drawOnBattlefield();
  ModelManager.getBattlefield().getMap().trinkets.add(t);
}
Program: 3738
Project: 3738
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 : atlas.getLayers()) {
    if (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(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");
  }
  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=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);
}
Program: 3739
Project: 3739
Buggy source:
private void increment(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 : atlas.getLayers()) {
    if (atlas.getLayers().indexOf(l) == layer) {
      valueToDitribute-=l.addAndReturnExcess(x,y,attenuatedInc);
    }
 else {
      availableLayers.add(l);
    }
  }
  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.withdrawAndReturnExcess(x,y,shared);
      if (l.get(x,y) == 0) {
        unavailableLayers.add(l);
      }
    }
    availableLayers.removeAll(unavailableLayers);
  }
  if (secur > 40) {
    LogUtil.logger.warning("String_Node_Str");
  }
  atlas.updatePixel(x,y);
}

Fixed version (ground truth):
private void increment(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.addAndReturnExcess(x,y,attenuatedInc);
    }
 else {
      availableLayers.add(l);
    }
  }
  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.withdrawAndReturnExcess(x,y,shared);
      if (l.get(x,y) == 0) {
        unavailableLayers.add(l);
      }
    }
    availableLayers.removeAll(unavailableLayers);
  }
  if (secur > 40) {
    LogUtil.logger.warning("String_Node_Str");
  }
  ModelManager.getBattlefield().getMap().atlas.updatePixel(x,y);
}
Program: 3740
Project: 3740
Buggy source:
private void propagate(ArrayList<Point2D> pixels){
  if (!pencil.maintained) {
    pencil.maintain();
    autoLayer=0;
    Point2D center=pencil.getCoord().getMult(atlas.getWidth(),atlas.getHeight()).getDivision(ModelManager.getBattlefield().getMap().width,ModelManager.getBattlefield().getMap().height);
    int centerX=(int)Math.round(center.x);
    int centerY=(int)Math.round(center.y);
    for (    AtlasLayer l : atlas.getLayers()) {
      if (l.get(centerX,centerY) > atlas.getLayers().get(autoLayer).get(centerX,centerY)) {
        autoLayer=atlas.getLayers().indexOf(l);
      }
    }
  }
  for (  Point2D p : pixels) {
    increment(p,autoLayer);
  }
}

Fixed version (ground truth):
private void propagate(ArrayList<Point2D> pixels){
  if (!pencil.maintained) {
    pencil.maintain();
    autoLayer=0;
    Point2D center=pencil.getCoord().getMult(ModelManager.getBattlefield().getMap().atlas.getWidth(),ModelManager.getBattlefield().getMap().atlas.getHeight()).getDivision(ModelManager.getBattlefield().getMap().width,ModelManager.getBattlefield().getMap().height);
    int centerX=(int)Math.round(center.x);
    int centerY=(int)Math.round(center.y);
    for (    AtlasLayer l : ModelManager.getBattlefield().getMap().atlas.getLayers()) {
      if (l.get(centerX,centerY) > ModelManager.getBattlefield().getMap().atlas.getLayers().get(autoLayer).get(centerX,centerY)) {
        autoLayer=ModelManager.getBattlefield().getMap().atlas.getLayers().indexOf(l);
      }
    }
  }
  for (  Point2D p : pixels) {
    increment(p,autoLayer);
  }
}
Program: 3741
Project: 3741
Buggy source:
public AtlasTool(){
  super(ADD_DELETE_OP,PROPAGATE_SMOOTH_OP);
  this.atlas=ModelManager.getBattlefield().getMap().atlas;
  explorer=new AtlasExplorer(ModelManager.getBattlefield().getMap());
  set=new AssetSet(ModelManager.getBattlefield().getMap().style.textures,true);
}

Fixed version (ground truth):
public AtlasTool(){
  super(ADD_DELETE_OP,PROPAGATE_SMOOTH_OP);
  explorer=new AtlasExplorer(ModelManager.getBattlefield().getMap());
  set=new AssetSet(ModelManager.getBattlefield().getMap().style.textures,true);
}
Program: 3742
Project: 3742
Buggy source:
private void smooth(ArrayList<Point2D> pixels){
  for (  Point2D p : pixels) {
    int x=(int)Math.round(p.x);
    int y=(int)Math.round(p.y);
    double attenuatedInc=increment * pencil.strength * pencil.getApplicationRatio(new Point2D(x,y).getMult(ModelManager.getBattlefield().getMap().width,ModelManager.getBattlefield().getMap().height).getDivision(atlas.getWidth(),atlas.getHeight()));
    int activeLayerCount=0;
    for (    AtlasLayer l : atlas.getLayers()) {
      if (l.get(x,y) != 0) {
        activeLayerCount++;
      }
    }
    double targetVal=255 / activeLayerCount;
    for (    AtlasLayer l : atlas.getLayers()) {
      if (l.get(x,y) != 0) {
        double diff=targetVal - l.get(x,y);
        if (diff < 0) {
          l.set(x,y,l.get(x,y) + Math.max(diff,-attenuatedInc));
        }
 else         if (diff > 0) {
          l.set(x,y,l.get(x,y) + Math.min(diff,attenuatedInc));
        }
      }
    }
    atlas.updatePixel(x,y);
  }
}

Fixed version (ground truth):
private void smooth(ArrayList<Point2D> pixels){
  for (  Point2D p : pixels) {
    int x=(int)Math.round(p.x);
    int y=(int)Math.round(p.y);
    double attenuatedInc=increment * pencil.strength * pencil.getApplicationRatio(new Point2D(x,y).getMult(ModelManager.getBattlefield().getMap().width,ModelManager.getBattlefield().getMap().height).getDivision(ModelManager.getBattlefield().getMap().atlas.getWidth(),ModelManager.getBattlefield().getMap().atlas.getHeight()));
    int activeLayerCount=0;
    for (    AtlasLayer l : ModelManager.getBattlefield().getMap().atlas.getLayers()) {
      if (l.get(x,y) != 0) {
        activeLayerCount++;
      }
    }
    double targetVal=255 / activeLayerCount;
    for (    AtlasLayer l : ModelManager.getBattlefield().getMap().atlas.getLayers()) {
      if (l.get(x,y) != 0) {
        double diff=targetVal - l.get(x,y);
        if (diff < 0) {
          l.set(x,y,l.get(x,y) + Math.max(diff,-attenuatedInc));
        }
 else         if (diff > 0) {
          l.set(x,y,l.get(x,y) + Math.min(diff,attenuatedInc));
        }
      }
    }
    ModelManager.getBattlefield().getMap().atlas.updatePixel(x,y);
  }
}
Program: 3743
Project: 3743
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: 3744
Project: 3744
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: 3745
Project: 3745
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: 3746
Project: 3746
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: 3747
Project: 3747
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: 3748
Project: 3748
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: 3749
Project: 3749
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);
}
Program: 3750
Project: 3750
Buggy source:
private void increment(Point2D p,int layer){
  Atlas toPaint=ModelManager.getBattlefield().getMap().atlas;
  if (layer > 3) {
    toPaint=ModelManager.getBattlefield().getMap().cover;
    layer-=4;
  }
  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 : toPaint.getLayers()) {
    if (toPaint.getLayers().indexOf(l) == layer) {
      valueToDitribute-=l.addAndReturnExcess(x,y,attenuatedInc);
    }
 else {
      if (l.get(x,y) > 0)       availableLayers.add(l);
    }
  }
  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.withdrawAndReturnExcess(x,y,shared);
      if (l.get(x,y) == 0) {
        unavailableLayers.add(l);
      }
    }
    availableLayers.removeAll(unavailableLayers);
  }
  if (secur > 40) {
    LogUtil.logger.warning("String_Node_Str");
  }
  toPaint.updatePixel(x,y);
  DecimalFormat df=new DecimalFormat("String_Node_Str");
  String val="String_Node_Str";
  double total=0;
  for (  AtlasLayer l : toPaint.getLayers()) {
    val+=df.format(l.get(x,y)) + "String_Node_Str";
    total+=l.get(x,y);
  }
  LogUtil.logger.info(val);
  LogUtil.logger.info("String_Node_Str" + df.format(total));
}

Fixed version (ground truth):
private void increment(Point2D p,int layer){
  Atlas toPaint=ModelManager.getBattlefield().getMap().atlas;
  if (layer > 3) {
    toPaint=ModelManager.getBattlefield().getMap().cover;
    layer-=4;
  }
  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 : toPaint.getLayers()) {
    if (toPaint.getLayers().indexOf(l) == layer) {
      valueToDitribute-=l.addAndReturnExcess(x,y,attenuatedInc);
    }
 else {
      if (l.get(x,y) > 0)       availableLayers.add(l);
    }
  }
  int secur=-1;
  while (valueToDitribute > 0 && !availableLayers.isEmpty() && secur++ < 50) {
    ArrayList<AtlasLayer> unavailableLayers=new ArrayList<>();
    double shared=Math.round(valueToDitribute / availableLayers.size());
    valueToDitribute=0;
    for (    AtlasLayer l : availableLayers) {
      valueToDitribute+=l.withdrawAndReturnExcess(x,y,shared);
      if (l.get(x,y) == 0) {
        unavailableLayers.add(l);
      }
    }
    availableLayers.removeAll(unavailableLayers);
  }
  if (secur > 40) {
    LogUtil.logger.warning("String_Node_Str");
  }
  toPaint.updatePixel(x,y);
}
Program: 3751
Project: 3751
Buggy source:
private void smooth(ArrayList<Point2D> pixels){
  for (  Point2D p : pixels) {
    int x=(int)Math.round(p.x);
    int y=(int)Math.round(p.y);
    double attenuatedInc=increment * pencil.strength * pencil.getApplicationRatio(new Point2D(x,y).getMult(ModelManager.getBattlefield().getMap().width,ModelManager.getBattlefield().getMap().height).getDivision(ModelManager.getBattlefield().getMap().atlas.getWidth(),ModelManager.getBattlefield().getMap().atlas.getHeight()));
    int activeLayerCount=0;
    for (    AtlasLayer l : ModelManager.getBattlefield().getMap().atlas.getLayers()) {
      if (l.get(x,y) != 0) {
        activeLayerCount++;
      }
    }
    double targetVal=255 / activeLayerCount;
    for (    AtlasLayer l : ModelManager.getBattlefield().getMap().atlas.getLayers()) {
      if (l.get(x,y) != 0) {
        double diff=targetVal - l.get(x,y);
        if (diff < 0) {
          l.set(x,y,l.get(x,y) + Math.max(diff,-attenuatedInc));
        }
 else         if (diff > 0) {
          l.set(x,y,l.get(x,y) + Math.min(diff,attenuatedInc));
        }
      }
    }
    ModelManager.getBattlefield().getMap().atlas.updatePixel(x,y);
  }
}

Fixed version (ground truth):
private void smooth(ArrayList<Point2D> pixels){
  for (  Point2D p : pixels) {
    int x=(int)Math.round(p.x);
    int y=(int)Math.round(p.y);
    double attenuatedInc=Math.round(increment * pencil.strength * pencil.getApplicationRatio(new Point2D(x,y).getMult(ModelManager.getBattlefield().getMap().width,ModelManager.getBattlefield().getMap().height).getDivision(ModelManager.getBattlefield().getMap().atlas.getWidth(),ModelManager.getBattlefield().getMap().atlas.getHeight())));
    int activeLayerCount=0;
    for (    AtlasLayer l : ModelManager.getBattlefield().getMap().atlas.getLayers()) {
      if (l.get(x,y) != 0) {
        activeLayerCount++;
      }
    }
    double targetVal=255 / activeLayerCount;
    for (    AtlasLayer l : ModelManager.getBattlefield().getMap().atlas.getLayers()) {
      if (l.get(x,y) != 0) {
        double diff=targetVal - l.get(x,y);
        if (diff < 0) {
          l.set(x,y,l.get(x,y) + Math.max(diff,-attenuatedInc));
        }
 else         if (diff > 0) {
          l.set(x,y,l.get(x,y) + Math.min(diff,attenuatedInc));
        }
      }
    }
    ModelManager.getBattlefield().getMap().atlas.updatePixel(x,y);
  }
}
Program: 3752
Project: 3752
Buggy source:
public void buildMaterial(){
  mat=new Material(am,"String_Node_Str");
  Texture2D alpha0=new Texture2D(new Image(Image.Format.RGBA8,atlas.getWidth(),atlas.getHeight(),atlas.getBuffer(0)));
  mat.setTexture("String_Node_Str",alpha0);
  Texture2D alpha1=new Texture2D(new Image(Image.Format.RGBA8,atlas.getWidth(),atlas.getHeight(),atlas.getBuffer(1)));
  mat.setTexture("String_Node_Str",alpha1);
  mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
  for (int i=0; i < 12; i++) {
    if (diffuseMaps.size() > i) {
      if (i == 0) {
        mat.setTexture("String_Node_Str",diffuseMaps.get(i));
      }
 else {
        mat.setTexture("String_Node_Str" + i,diffuseMaps.get(i));
      }
      mat.setFloat("String_Node_Str" + i + "String_Node_Str",scales.get(i).floatValue());
      if (normaMaps.get(i) != null) {
        if (i == 0) {
          mat.setTexture("String_Node_Str",normaMaps.get(i));
        }
 else {
          mat.setTexture("String_Node_Str" + i,normaMaps.get(i));
        }
      }
    }
  }
}

Fixed version (ground truth):
public void buildMaterial(){
  mat=new Material(am,"String_Node_Str");
  Texture2D alpha0=new Texture2D(new Image(Image.Format.RGBA8,atlas.getWidth(),atlas.getHeight(),atlas.getBuffer(0)));
  mat.setTexture("String_Node_Str",alpha0);
  Texture2D alpha1=new Texture2D(new Image(Image.Format.RGBA8,atlas.getWidth(),atlas.getHeight(),atlas.getBuffer(1)));
  mat.setTexture("String_Node_Str",alpha1);
  if (transp)   mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
  for (int i=0; i < 12; i++) {
    if (diffuseMaps.size() > i) {
      if (i == 0) {
        mat.setTexture("String_Node_Str",diffuseMaps.get(i));
      }
 else {
        mat.setTexture("String_Node_Str" + i,diffuseMaps.get(i));
      }
      mat.setFloat("String_Node_Str" + i + "String_Node_Str",scales.get(i).floatValue());
      if (normaMaps.get(i) != null) {
        if (i == 0) {
          mat.setTexture("String_Node_Str",normaMaps.get(i));
        }
 else {
          mat.setTexture("String_Node_Str" + i,normaMaps.get(i));
        }
      }
    }
  }
}
Program: 3753
Project: 3753
Buggy source:
public Atlas(int mapWidth,int mapHeight){
  this.mapWidth=mapWidth;
  this.mapHeight=mapHeight;
  width=mapWidth * RESOLUTION_RATIO;
  height=mapHeight * RESOLUTION_RATIO;
}

Fixed version (ground truth):
public Atlas(int mapWidth,int mapHeight){
  this.mapWidth=mapWidth;
  this.mapHeight=mapHeight;
}
Program: 3754
Project: 3754
Buggy source:
@Override public void finalize(){
  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,1));
  for (int i=1; i < LAYER_COUNT; i++) {
    layers.add(new AtlasLayer(width,height,0));
  }
  buffers.add(buildBuffer(0));
  buffers.add(buildBuffer(1));
}
Program: 3755
Project: 3755
Buggy source:
public void buildMaterial(){
  mat=new Material(am,"String_Node_Str");
  mat.setTexture("String_Node_Str",new Texture2D(new Image(Image.Format.RGBA8,atlas.getWidth(),atlas.getHeight(),atlas.getBuffer(0))));
  mat.setTexture("String_Node_Str",new Texture2D(new Image(Image.Format.RGBA8,atlas.getWidth(),atlas.getHeight(),atlas.getBuffer(1))));
  for (int i=0; i < 12; i++) {
    if (diffuseMaps.size() > i) {
      if (i == 0) {
        mat.setTexture("String_Node_Str",diffuseMaps.get(i));
      }
 else {
        mat.setTexture("String_Node_Str" + i,diffuseMaps.get(i));
      }
      mat.setFloat("String_Node_Str" + i + "String_Node_Str",scales.get(i).floatValue());
      if (normaMaps.get(i) != null) {
        if (i == 0) {
          mat.setTexture("String_Node_Str",normaMaps.get(i));
        }
 else {
          mat.setTexture("String_Node_Str" + i,normaMaps.get(i));
        }
      }
    }
  }
}

Fixed version (ground truth):
public void buildMaterial(){
  mat=new Material(am,"String_Node_Str");
  Texture2D alpha0=new Texture2D(new Image(Image.Format.RGBA8,atlas.getWidth(),atlas.getHeight(),atlas.getBuffer(0)));
  Texture2D alpha1=new Texture2D(new Image(Image.Format.RGBA8,atlas.getWidth(),atlas.getHeight(),atlas.getBuffer(1)));
  mat.setTexture("String_Node_Str",alpha0);
  mat.setTexture("String_Node_Str",alpha1);
  for (int i=0; i < 12; i++) {
    if (diffuseMaps.size() > i) {
      if (i == 0) {
        mat.setTexture("String_Node_Str",diffuseMaps.get(i));
      }
 else {
        mat.setTexture("String_Node_Str" + i,diffuseMaps.get(i));
      }
      mat.setFloat("String_Node_Str" + i + "String_Node_Str",scales.get(i).floatValue());
      if (normaMaps.get(i) != null) {
        if (i == 0) {
          mat.setTexture("String_Node_Str",normaMaps.get(i));
        }
 else {
          mat.setTexture("String_Node_Str" + i,normaMaps.get(i));
        }
      }
    }
  }
}
Program: 3756
Project: 3756
Buggy source:
public void renderTiles(){
  int index=0;
  for (  String s : ModelManager.getBattlefield().getMap().style.textures) {
    Texture diffuse=am.loadTexture(s);
    Texture normal;
    if (ModelManager.getBattlefield().getMap().style.normals.get(index) != null) {
      normal=am.loadTexture(ModelManager.getBattlefield().getMap().style.normals.get(index));
    }
 else {
      normal=null;
    }
    double scale=ModelManager.getBattlefield().getMap().style.scales.get(index);
    groundTexture.addTexture(diffuse,normal,scale);
    index++;
  }
  groundTexture.buildMaterial();
  for (  ParcelMesh mesh : ParcelManager.getMeshes()) {
    Geometry g=new Geometry();
    Mesh jmeMesh=Translator.toJMEMesh(mesh);
    SilentTangentBinormalGenerator.generate(jmeMesh);
    g.setMesh(jmeMesh);
    g.setMaterial(mm.getLightingTexture("String_Node_Str"));
    g.addControl(new RigidBodyControl(0));
    parcelsSpatial.put(mesh,g);
    castAndReceiveNode.attachChild(g);
    mainPhysicsSpace.add(g);
  }
  updateTiles(ModelManager.getBattlefield().getMap().getTiles());
}

Fixed version (ground truth):
public void renderTiles(){
  int index=0;
  for (  String s : ModelManager.getBattlefield().getMap().style.textures) {
    Texture diffuse=am.loadTexture(s);
    Texture normal;
    if (ModelManager.getBattlefield().getMap().style.normals.get(index) != null) {
      normal=am.loadTexture(ModelManager.getBattlefield().getMap().style.normals.get(index));
    }
 else {
      normal=null;
    }
    double scale=ModelManager.getBattlefield().getMap().style.scales.get(index);
    groundTexture.addTexture(diffuse,normal,scale);
    index++;
  }
  groundTexture.buildMaterial();
  for (  ParcelMesh mesh : ParcelManager.getMeshes()) {
    Geometry g=new Geometry();
    Mesh jmeMesh=Translator.toJMEMesh(mesh);
    SilentTangentBinormalGenerator.generate(jmeMesh);
    g.setMesh(jmeMesh);
    g.setMaterial(groundTexture.getMaterial());
    g.addControl(new RigidBodyControl(0));
    parcelsSpatial.put(mesh,g);
    castAndReceiveNode.attachChild(g);
    mainPhysicsSpace.add(g);
  }
  updateTiles(ModelManager.getBattlefield().getMap().getTiles());
}
Program: 3757
Project: 3757
Buggy source:
private static void setBattlefield(Battlefield battlefield){
  if (battlefield != null) {
    ModelManager.battlefield=battlefield;
    ParcelManager.createParcelMeshes(ModelManager.getBattlefield().getMap());
    battlefield.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;
    ParcelManager.createParcelMeshes(ModelManager.getBattlefield().getMap());
    ModelManager.getBattlefield().getMap().resetTrinkets();
    ModelManager.getBattlefield().getEngagement().reset();
    EventManager.post(new BattleFieldUpdateEvent());
    LogUtil.logger.info("String_Node_Str");
  }
}
Program: 3759
Project: 3759
Buggy source:
public Trinket getTrinket(){
  Trinket res=BuilderManager.getTrinketBuilder(builderID).build(pos,yaw,modelPath,scaleX,scaleY,scaleZ);
  return res;
}

Fixed version (ground truth):
@JsonIgnore public Trinket getTrinket(){
  Trinket res=BuilderManager.getTrinketBuilder(builderID).build(pos,yaw,modelPath,scaleX,scaleY,scaleZ);
  return res;
}
Program: 3760
Project: 3760
Buggy source:
@Subscribe protected void handleTileEvent(TilesEvent e){
  updateTiles(e.getExtended());
}

Fixed version (ground truth):
@Subscribe public void handleTileEvent(TilesEvent e){
  updateTiles(e.getExtended());
}
Program: 3761
Project: 3761
Buggy source:
public double addAndReturnExcess(int x,int y,double toAdd){
  double excess=0;
  double newVal=get(x,y) + toAdd;
  double maskVal=mask.getPixel((x) % (mask.getWidth() * (int)maskScale),(y) % (mask.getHeight() * (int)maskScale)).a;
  if (maskVal < 1)   newVal=Math.min(newVal,255 * maskVal);
  if (newVal > 255) {
    excess=newVal - 255;
    newVal=255;
  }
  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;
  double maskVal=mask.getPixel((x * mask.getWidth() * (int)maskScale / xSize) % (mask.getWidth()),(y * mask.getHeight() * (int)maskScale / ySize) % (mask.getHeight())).a;
  if (newVal > 255 * maskVal) {
    excess=newVal - 255 * maskVal;
    newVal=255 * maskVal;
  }
  set(x,y,newVal);
  return excess;
}
Program: 3762
Project: 3762
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) {
    System.out.println("String_Node_Str" + e);
  }
  int index=0;
  layers.clear();
  for (int i=0; i < LAYER_COUNT; i++) {
    AtlasLayer l=new AtlasLayer(width,height);
    layers.add(l);
  }
  buffers.clear();
  buffers.add(buildBuffer(0));
  buffers.add(buildBuffer(1));
  toUpdate=true;
}

Fixed version (ground truth):
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) {
    System.out.println("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: 3763
Project: 3763
Buggy source:
@Override public void update(float elapsedTime){
  Point2D selStart=((BattlefieldInputInterpreter)inputInterpreter).selectionStart;
  if (selStart != null) {
    Point2D p=Translator.toPoint2D(inputManager.getCursorPosition());
    view.drawSelectionArea(selStart,p);
    ((BattlefieldInputInterpreter)inputInterpreter).updateSelection();
  }
 else {
    view.guiNode.detachAllChildren();
  }
  CommandManager.updateSelectables(spatialSelector.getCenterViewCoord(view.rootNode));
  guiController.update();
  if (!paused) {
    ModelManager.battlefield.armyManager.update(elapsedTime);
  }
}

Fixed version (ground truth):
@Override public void update(float elapsedTime){
  Point2D selStart=((BattlefieldInputInterpreter)inputInterpreter).clicInitialCoord;
  if (selStart != null) {
    Point2D p=Translator.toPoint2D(inputManager.getCursorPosition());
    view.drawSelectionArea(selStart,p);
    ((BattlefieldInputInterpreter)inputInterpreter).updateSelection();
  }
 else {
    view.guiNode.detachAllChildren();
  }
  CommandManager.updateSelectables(spatialSelector.getCenterViewCoord(view.rootNode));
  guiController.update();
  if (!paused) {
    ModelManager.battlefield.armyManager.update(elapsedTime);
  }
}
Program: 3764
Project: 3764
Buggy source:
public void updateSelection(){
  Point2D selectionEnd=Translator.toPoint2D(ctrl.inputManager.getCursorPosition());
  if (selectionEnd.equals(selectionStart) || selectionEnd.getDistance(selectionStart) < 10) {
    return;
  }
  AlignedBoundingBox rect=new AlignedBoundingBox(selectionStart,selectionEnd);
  List<Unit> inSelection=new ArrayList<>();
  for (  Unit u : ModelManager.battlefield.armyManager.getUnits()) {
    if (rect.contains(ctrl.spatialSelector.getScreenCoord(u.getPos()))) {
      inSelection.add(u);
    }
  }
  CommandManager.select(inSelection);
}

Fixed version (ground truth):
public void updateSelection(){
  Point2D coord=getMouseCoord();
  if (coord.equals(clicInitialCoord)) {
    return;
  }
  AlignedBoundingBox rect=new AlignedBoundingBox(clicInitialCoord,coord);
  List<Unit> inSelection=new ArrayList<>();
  for (  Unit u : ModelManager.battlefield.armyManager.getUnits()) {
    if (rect.contains(ctrl.spatialSelector.getScreenCoord(u.getPos()))) {
      inSelection.add(u);
    }
  }
  CommandManager.select(inSelection);
}
Program: 3765
Project: 3765
Buggy source:
@Override public void onAction(String name,boolean isPressed,float tpf){
  EventManager.post(new InputEvent(name));
  if (!isPressed) {
switch (name) {
case SWITCH_CTRL_1:
      ctrl.notifyListeners("String_Node_Str");
    break;
case SWITCH_CTRL_2:
  ctrl.notifyListeners("String_Node_Str");
break;
case SWITCH_CTRL_3:
ctrl.notifyListeners("String_Node_Str");
break;
case MULTIPLE_SELECTION:
CommandManager.setMultipleSelection(false);
break;
case SELECT:
if (System.currentTimeMillis() - dblclicTimer < DOUBLE_CLIC_DELAY && dblclicCoord.getDistance(getSpatialCoord()) < DOUBLE_CLIC_MAX_OFFSET) {
CommandManager.selectUnityInContext(ctrl.spatialSelector.getEntityId());
}
 else {
}
selectionStart=null;
dblclicTimer=System.currentTimeMillis();
dblclicCoord=getSpatialCoord();
break;
case ACTION:
CommandManager.act(ctrl.spatialSelector.getEntityId(),getSpatialCoord());
break;
case MOVE_ATTACK:
CommandManager.setMoveAttack();
break;
case HOLD:
CommandManager.orderHold();
break;
case PAUSE:
((BattlefieldController)ctrl).togglePause();
break;
}
}
 else {
switch (name) {
case MULTIPLE_SELECTION:
CommandManager.setMultipleSelection(true);
break;
case SELECT:
beginSelection();
break;
}
}
}

Fixed version (ground truth):
@Override public void onAction(String name,boolean isPressed,float tpf){
  EventManager.post(new InputEvent(name));
  if (!isPressed) {
switch (name) {
case SWITCH_CTRL_1:
      ctrl.notifyListeners("String_Node_Str");
    break;
case SWITCH_CTRL_2:
  ctrl.notifyListeners("String_Node_Str");
break;
case SWITCH_CTRL_3:
ctrl.notifyListeners("String_Node_Str");
break;
case MULTIPLE_SELECTION:
CommandManager.setMultipleSelection(false);
break;
case SELECT:
if (System.currentTimeMillis() - dblclicTimer < DOUBLE_CLIC_DELAY && dblclicCoord.getDistance(getSpatialCoord()) < DOUBLE_CLIC_MAX_OFFSET) {
CommandManager.selectUnityInContext(ctrl.spatialSelector.getEntityId());
}
 else {
if (!isDragging()) CommandManager.select(ctrl.spatialSelector.getEntityId(),getSpatialCoord());
}
clicInitialCoord=null;
dblclicTimer=System.currentTimeMillis();
dblclicCoord=getSpatialCoord();
break;
case ACTION:
CommandManager.act(ctrl.spatialSelector.getEntityId(),getSpatialCoord());
break;
case MOVE_ATTACK:
CommandManager.setMoveAttack();
break;
case HOLD:
CommandManager.orderHold();
break;
case PAUSE:
((BattlefieldController)ctrl).togglePause();
break;
}
}
 else {
switch (name) {
case MULTIPLE_SELECTION:
CommandManager.setMultipleSelection(true);
break;
case SELECT:
beginSelection();
break;
}
}
}
Program: 3766
Project: 3766
Buggy source:
private void beginSelection(){
  selectionStart=Translator.toPoint2D(ctrl.inputManager.getCursorPosition());
}

Fixed version (ground truth):
private void beginSelection(){
  clicInitialCoord=Translator.toPoint2D(ctrl.inputManager.getCursorPosition());
}
Program: 3767
Project: 3767
Buggy source:
@Override public void onAction(String name,boolean isPressed,float tpf){
  if (!isPressed) switch (name) {
case TOGGLE_PENCIL_SHAPE:
    toolManager.pencil.toggleShape();
  break;
case TOGGLE_PENCIL_MODE:
toolManager.pencil.toggleMode();
break;
case INC_SELECTOR_RADIUS:
toolManager.pencil.incRadius();
break;
case DEC_SELECTOR_RADIUS:
toolManager.pencil.decRadius();
break;
case SET_CLIFF_TOOL:
toolManager.setCliffTool();
break;
case SET_HEIGHT_TOOL:
toolManager.setHeightTool();
break;
case SET_ATLAS_TOOL:
toolManager.setAtlasTool();
break;
case TOGGLE_SET:
toolManager.toggleSet();
break;
case TOGGLE_GRID:
controller.view.editorRend.toggleGrid();
break;
case TOGGLE_LIGHT_COMP:
sunLight.toggleLight();
break;
case TOGGLE_SPEED:
sunLight.toggleSpeed();
break;
case RESET_COLOR:
sunLight.resetColor();
break;
case SAVE:
MapFactory.save(toolManager.map);
break;
case LOAD:
controller.model.map=MapFactory.load();
break;
}
}

Fixed version (ground truth):
@Override public void onAction(String name,boolean isPressed,float tpf){
  if (!isPressed) switch (name) {
case TOGGLE_PENCIL_SHAPE:
    toolManager.pencil.toggleShape();
  break;
case TOGGLE_PENCIL_MODE:
toolManager.pencil.toggleMode();
break;
case INC_SELECTOR_RADIUS:
toolManager.pencil.incRadius();
break;
case DEC_SELECTOR_RADIUS:
toolManager.pencil.decRadius();
break;
case SET_CLIFF_TOOL:
toolManager.setCliffTool();
break;
case SET_HEIGHT_TOOL:
toolManager.setHeightTool();
break;
case SET_ATLAS_TOOL:
toolManager.setAtlasTool();
break;
case TOGGLE_SET:
toolManager.toggleSet();
break;
case TOGGLE_GRID:
controller.view.editorRend.toggleGrid();
break;
case TOGGLE_LIGHT_COMP:
sunLight.toggleLight();
break;
case TOGGLE_SPEED:
sunLight.toggleSpeed();
break;
case RESET_COLOR:
sunLight.resetColor();
break;
case SAVE:
MapFactory.save(toolManager.map);
break;
}
}