Lucene 7 is not consistent with Lucene 6 regarding adding TextField(field, TokenStream) to a document

I’m adding a field to a document using TextField with TokenStream, using the following code:

TokenFilter contentFilter = createContentFilter(body);
Field contentField = new TextField("fieldName", contentFilter);

It used to work great with Lucene 6. However, moving to Lucene 7 I get an error message while adding the document to the index:

java.lang.IllegalArgumentException: startOffset must be non-negative, and endOffset must be >= startOffset, and offsets must not go backwards startOffset=0,endOffset=39,lastStartOffset=36 for field 'content'
at org.apache.lucene.index.DefaultIndexingChain$PerField.invert(
at org.apache.lucene.index.DefaultIndexingChain.processField(

What ha been changed in Lucene 7 that breaks my code?
Thans, David