public void finishAnnotating() {
    // Close off the final annotation, if any.
    endAnnotation();

    // Remove annotations that refer to unwritten data.
    if (annotations != null) {
      int asz = annotations.size();
      while (asz > 0) {
        Annotation last = annotations.get(asz - 1);
        if (last.getStart() > cursor) {
          annotations.remove(asz - 1);
          asz--;
        } else if (last.getEnd() > cursor) {
          last.setEnd(cursor);
          break;
        } else {
          break;
        }
      }
    }
  }
Finishes up annotation processing. This closes off any open annotations and removes annotations
that don't refer to written data.
android/android_framework/dex-maker/src/main/java/com/android/dx/util/ByteArrayAnnotatedOutput.java