Program: 96831
Project: 96831
Buggy source:
/** 
 * Checks for collisions between every component in the scene that belongs to the registered types registered using the register() method.
 */
public void checkCollisions(){
  if (scene.entities.size() == 0) {
    childrenInScene=0;
    return;
  }
  if (scene.entities.size() != childrenInScene) {
    entities.clear();
    broadphase.clear();
    childrenInScene=0;
    for (    Entity2D entity : scene.entities) {
      CollisionComponent2D component=entity.getComponent(CollisionComponent2D.class);
      if (component != null) {
        broadphase.insert(component);
        entities.add(entity);
      }
      childrenInScene++;
    }
  }
  for (  Entity2D entity : entities) {
    TransformComponent2D transform=entity.getComponent(TransformComponent2D.class);
    CollisionComponent2D collision=entity.getComponent(CollisionComponent2D.class);
    if (transform.transformed) {
      broadphase.remove(collision);
      broadphase.insert(collision);
    }
  }
  for (  CollisionTag type1 : collisionMap.keySet()) {
    for (    Entity2D entity : entities) {
      CollisionComponent2D collision=entity.getComponent(CollisionComponent2D.class);
      if (type1 == collision.tag) {
        List<CollisionComponent2D> collidables=broadphase.retrieve(collision);
        for (        CollisionTag type2 : collisionMap.get(type1)) {
          for (          CollisionComponent2D collidable : collidables)           if (collidable.tag == type2)           if (collision.polygon.intersects(collidable.polygon))           collision.callback.handleCollision(collision.entity);
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Checks for collisions between every component in the scene that belongs to the registered types registered using the register() method.
 */
public void checkCollisions(){
  if (scene.entities.size() == 0) {
    childrenInScene=0;
    return;
  }
  if (scene.numEntities() != childrenInScene) {
    entities.clear();
    broadphase.clear();
    childrenInScene=0;
    updateEntities(scene.entities);
  }
  for (  Entity2D entity : entities) {
    TransformComponent2D transform=entity.getComponent(TransformComponent2D.class);
    for (    IComponent2D component : entity.getComponents()) {
      if (component instanceof CollisionComponent2D) {
        CollisionComponent2D collision=(CollisionComponent2D)component;
        if (transform.transformed) {
          broadphase.remove(collision);
          broadphase.insert(collision);
        }
      }
    }
  }
  for (  CollisionTag type1 : collisionMap.keySet()) {
    for (    Entity2D entity : entities) {
      CollisionComponent2D collision=entity.getComponent(CollisionComponent2D.class);
      if (type1 == collision.tag) {
        List<CollisionComponent2D> collidables=broadphase.retrieve(collision);
        for (        CollisionTag type2 : collisionMap.get(type1)) {
          for (          CollisionComponent2D collidable : collidables)           if (collidable.tag == type2)           if (collision.polygon.intersects(collidable.polygon))           collision.callback.handleCollision(collision.entity,collidable);
        }
      }
    }
  }
}