This is a confirmed bug in Java.
It occurs in standard Java text components for really long lines, somewhere around 9500 characters when using the default font (Dialog) and default size (12). Changing font family and size affects at which line length this error occurs.
We have not discovered any workaround, other than using line breaks.
The bug has been found only on Linux and occurs at least on Linux Mint 19 Cinnamon and Ubuntu 18.04 and later versions. Both with Oracle JRE and AdoptOpenJDK JRE. It has not been possible to reproduce on Windows or MacOS.
More bug details can be found here:
https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8262010