Program: 31407
Project: 31407
Buggy source:
@Override public void resume(IOContext context) throws IOException {
  JsonHandlerContext ctx=localContext.get(context);
  Iterator<Record> records=ctx.records;
  if (records == null) {
    return;
  }
  RecordMetadata metadata=ctx.metadata;
  final int columnCount=metadata.getColumnCount();
  if (ctx.current == null && records.hasNext()) {
    ctx.current=records.next();
    ctx.count++;
  }
  final ChunkedResponse r=context.chunkedResponse();
  try {
    while (ctx.current != null) {
      if (ctx.count > ctx.skip) {
        r.bookmark();
        if (ctx.count > ctx.stop && !ctx.includeCount) {
          break;
        }
        if (ctx.count <= ctx.stop) {
          if (ctx.count > ctx.skip + 1) {
            r.put(',');
          }
          r.put('{');
          for (int col=0; col < columnCount; col++) {
            RecordColumnMetadata m=metadata.getColumnQuick(col);
            if (col > 0) {
              r.put(',');
            }
            r.putQuoted(m.getName()).put(':');
            putValue(r,m.getType(),ctx.current,col);
          }
          r.put('}');
          r.sendChunk();
        }
      }
      if (records.hasNext()) {
        ctx.current=records.next();
        ctx.count++;
      }
 else {
        ctx.current=null;
      }
    }
    sendDone(r,ctx);
  }
 catch (  ResponseContentBufferTooSmallException ex) {
    if (!r.resetToBookmark()) {
      ctx.error().$("String_Node_Str").$(ctx.count - 1).$("String_Node_Str").$();
      throw ex;
    }
    ctx.debug().$("String_Node_Str").$(ctx.count - 1).$();
    r.sendChunk();
  }
}

Fixed version (ground truth):
@Override public void resume(IOContext context) throws IOException {
  JsonHandlerContext ctx=localContext.get(context);
  Iterator<Record> records;
  if (ctx == null || (records=ctx.cursor) == null) {
    return;
  }
  final RecordMetadata metadata=ctx.metadata;
  final int columnCount=metadata.getColumnCount();
  if (ctx.record == null && records.hasNext()) {
    ctx.record=records.next();
    ctx.count++;
  }
  final ChunkedResponse r=context.chunkedResponse();
  try {
    while (ctx.record != null) {
      if (ctx.count > ctx.skip) {
        r.bookmark();
        if (ctx.count > ctx.stop && !ctx.includeCount) {
          break;
        }
        if (ctx.count <= ctx.stop) {
          if (ctx.count > ctx.skip + 1) {
            r.put(',');
          }
          r.put('{');
          for (int col=0; col < columnCount; col++) {
            RecordColumnMetadata m=metadata.getColumnQuick(col);
            if (col > 0) {
              r.put(',');
            }
            r.putQuoted(m.getName()).put(':');
            putValue(r,m.getType(),ctx.record,col);
          }
          r.put('}');
          r.sendChunk();
        }
      }
      if (records.hasNext()) {
        ctx.record=records.next();
        ctx.count++;
      }
 else {
        ctx.record=null;
      }
    }
    sendDone(r,ctx);
  }
 catch (  ResponseContentBufferTooSmallException ex) {
    if (!r.resetToBookmark()) {
      ctx.error().$("String_Node_Str").$(ctx.count - 1).$("String_Node_Str").$();
      throw ex;
    }
    ctx.debug().$("String_Node_Str").$(ctx.count - 1).$();
    r.sendChunk();
  }
}