private String popTag(final boolean allowMarks) {
      if (this.tagLevel-- <= 0) {
        throw new IllegalStateException("Unbalanced tags, tried to pop below depth");
      }
      final String tag = this.activeTags[this.tagLevel];
      if (!allowMarks && tag == MARK) {
        throw new IllegalStateException("Tried to pop past mark, tag stack: " + Arrays.toString(this.activeTags) + " @ " + this.tagLevel);
      }
      return tag;
    }
mark tag boundaries within the stack, without needing to mess with typing too much.
text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/MiniMessageSerializer.java