Program: 1038
Project: 1038
Buggy source:
public static void generateInternalLighting(Chunk chunk){
  int top=Chunk.SIZE_Y - 1;
  short[] tops=new short[Chunk.SIZE_X * Chunk.SIZE_Z];
  byte sunlightMax=SUNLIGHT_RULES.getMaxValue();
  for (int x=0; x < Chunk.SIZE_X; x++) {
    for (int z=0; z < Chunk.SIZE_Z; z++) {
      Block lastBlock=BlockManager.getAir();
      int y=top;
      for (; y >= 0; y--) {
        Block block=chunk.getBlock(x,y,z);
        if (SUNLIGHT_RULES.propagateValue(sunlightMax,Side.BOTTOM,lastBlock) == sunlightMax && SUNLIGHT_RULES.canSpreadOutOf(lastBlock,Side.BOTTOM) && SUNLIGHT_RULES.canSpreadInto(block,Side.TOP)) {
          chunk.setSunlight(x,y,z,sunlightMax);
          lastBlock=block;
        }
      }
      tops[x + Chunk.SIZE_X * z]=(short)y;
    }
  }
  BatchPropagator lightPropagator=new BatchPropagator(LIGHT_RULES,new SingleChunkView(LIGHT_RULES,chunk));
  for (int x=0; x < Chunk.SIZE_X; x++) {
    for (int z=0; z < Chunk.SIZE_Z; z++) {
      if (tops[x + Chunk.SIZE_X * z] < top) {
        Block block=chunk.getBlock(x,tops[x + Chunk.SIZE_X * z] + 1,z);
        spreadSunlightInternal(chunk,x,tops[x + Chunk.SIZE_X * z] + 1,z,block);
      }
      for (int y=top; y >= 0; y--) {
        Block block=chunk.getBlock(x,y,z);
        if (y > tops[x + Chunk.SIZE_X * z] && ((x > 0 && tops[(x - 1) + Chunk.SIZE_X * z] >= y) || (x < Chunk.SIZE_X - 1 && tops[(x + 1) + Chunk.SIZE_X * z] >= y) || (z > 0 && tops[x + Chunk.SIZE_X * (z - 1)] >= y)|| (z < Chunk.SIZE_Z - 1 && tops[x + Chunk.SIZE_X * (z + 1)] >= y))) {
          spreadSunlightInternal(chunk,x,y,z,block);
        }
        if (block.getLuminance() > 0) {
          chunk.setLight(x,y,z,block.getLuminance());
          lightPropagator.propagateFrom(new Vector3i(x,y,z),block);
        }
      }
    }
  }
  lightPropagator.process();
}

Fixed version (ground truth):
public static void generateInternalLighting(Chunk chunk){
  int top=Chunk.SIZE_Y - 1;
  short[] tops=new short[Chunk.SIZE_X * Chunk.SIZE_Z];
  byte sunlightMax=SUNLIGHT_RULES.getMaxValue();
  for (int x=0; x < Chunk.SIZE_X; x++) {
    for (int z=0; z < Chunk.SIZE_Z; z++) {
      Block lastBlock=BlockManager.getAir();
      int y=top;
      for (; y >= 0; y--) {
        Block block=chunk.getBlock(x,y,z);
        if (SUNLIGHT_RULES.propagateValue(sunlightMax,Side.BOTTOM,lastBlock) == sunlightMax && SUNLIGHT_RULES.canSpreadOutOf(lastBlock,Side.BOTTOM) && SUNLIGHT_RULES.canSpreadInto(block,Side.TOP)) {
          chunk.setSunlight(x,y,z,sunlightMax);
          lastBlock=block;
        }
 else {
          break;
        }
      }
      tops[x + Chunk.SIZE_X * z]=(short)y;
    }
  }
  BatchPropagator lightPropagator=new BatchPropagator(LIGHT_RULES,new SingleChunkView(LIGHT_RULES,chunk));
  for (int x=0; x < Chunk.SIZE_X; x++) {
    for (int z=0; z < Chunk.SIZE_Z; z++) {
      if (tops[x + Chunk.SIZE_X * z] < top) {
        Block block=chunk.getBlock(x,tops[x + Chunk.SIZE_X * z] + 1,z);
        spreadSunlightInternal(chunk,x,tops[x + Chunk.SIZE_X * z] + 1,z,block);
      }
      for (int y=top; y >= 0; y--) {
        Block block=chunk.getBlock(x,y,z);
        if (y > tops[x + Chunk.SIZE_X * z] && ((x > 0 && tops[(x - 1) + Chunk.SIZE_X * z] >= y) || (x < Chunk.SIZE_X - 1 && tops[(x + 1) + Chunk.SIZE_X * z] >= y) || (z > 0 && tops[x + Chunk.SIZE_X * (z - 1)] >= y)|| (z < Chunk.SIZE_Z - 1 && tops[x + Chunk.SIZE_X * (z + 1)] >= y))) {
          spreadSunlightInternal(chunk,x,y,z,block);
        }
        if (block.getLuminance() > 1) {
          lightPropagator.propagateFrom(new Vector3i(x,y,z),block);
        }
      }
    }
  }
  lightPropagator.process();
}