private static void checkOffsets(Document document, int startOffset, int endOffset) {
    if (startOffset < 0 || endOffset > document.getTextLength() || endOffset < startOffset) {
      throw new IllegalArgumentException("Invalid offsets: startOffset="+startOffset+"; endOffset="+endOffset+"; document length="+document.getTextLength());
    }
  }
private static void checkOffsets(Document document, int startOffset, int endOffset)