...it would go into an endless loop creating a string containing "AAAAAAAAAAA..." until the server crashed.
I rewrote it using my own custom string parser rather than use regular expressions or Java's
string.replaceAll() (which goes into a loop if you replace "A" with "AA").
I even tried to do this the OOP way by extending String and adding my method as a method to my String sub object, but String won't allow itself to be extended.
Conclusion: sometimes the "best practices" aren't truly the best practices -- and you need to do things your own way to get it to work correctly.